Question

In: Computer Science

Develop a C++ program that looks for a given value in a text file full of...

Develop a C++ program that looks for a given value in a text file full of integer values

Prompt the user for a value to search for in the file

  • No input validation is required

Open the accompanying text file named numbers.txt

Search the contents of the text file

  • You may not "hard-code" the quantity of values found in the file...
  • Use a loop of some sort until the end of the text file is reached

Maintain how many many times the value is found in the file

Close the text file when processing is complete

Display the number of times the value is found in the file

Number.txt

61      62      71      40      32      6       27      8       74      3
95      10      74      69      66      37      94      10      17      55
38      5       43      69      19      89      65      74      71      33
85      74      26      5       6       40      36      100     4       57
56      73      78      24      36      48      84      3       89      80
93      49      46      8       39      89      50      44      47      78
37      12      41      4       40      57      21      13      43      73
64      4       67      8       37      10      9       51      38      67
68      30      66      1       42      43      53      7       93      32
33      94      22      74      84      77      48      27      37      51
28      100     86      91      8       30      13      1       23      17
81      39      86      70      6       74      4       70      58      31
7       45      26      69      73      38      40      82      82      99
49      23      31      47      43      82      55      55      52      18
5       71      16      15      25      75      66      6       20      34
95      14      62      89      49      99      38      91      20      9
40      24      10      23      18      42      12      61      50      19
86      44      8       83      15      42      37      30      1       42
61      5       52      29      22      18      60      13      24      54
82      2       43      66      82      91      23      67      48      71
80      95      47      55      94      59      82      67      1       40
25      17      71      27      8       30      66      97      43      100
30      78      26      18      5       34      90      63      44      85
47      55      97      55      56      42      100     38      56      99
17      70      98      86      90      41      24      61      20      67
56      51      93      10      15      74      42      58      59      38
38      27      71      95      82      42      93      53      18      23
98      92      80      42      31      94      67      99      70      89
40      20      91      35      48      17      22      30      35      27
23      3       92      45      14      24      20      72      95      18
60      54      30      54      3       37      55      50      95      67
13      70      63      75      66      91      47      45      66      74
81      5       14      63      33      99      74      90      37      39
65      70      79      60      98      57      41      59      64      70
21      39      3       84      50      84      100     20      88      84
65      45      24      56      35      45      92      41      44      47
62      24      17      24      21      16      2       87      56      25
95      51      50      31      94      92      86      97      91      74
47      35      44      93      73      73      84      23      74      1
94      81      21      67      29      52      65      85      31      97
61      77      53      55      84      48      8       1       99      50
40      36      42      66      84      27      43      100     28      58
62      14      42      25      51      3       71      97      68      57
7       92      12      47      72      18      91      58      33      14
90      51      42      14      97      77      86      87      74      12
25      75      18      29      12      18      17      36      42      85
24      1       18      82      64      33      95      94      70      16
44      72      18      64      66      53      59      70      18      40
35      83      8       88      85      32      6       20      56      37
41      19      4       85      77      45      93      1       5       63
7       37      4       37      67      38      62      56      39      26
77      11      33      75      81      75      23      77      43      78
36      56      16      66      81      98      37      38      1       19
59      82      20      8       90      64      49      55      16      16
93      64      54      24      10      90      14      68      67      59
99      25      69      41      90      40      30      7       41      95
46      44      46      90      40      13      47      69      28      21
37      73      35      85      48      25      100     45      56      93
81      53      86      10      23      52      67      83      63      4
74      73      34      56      34      50      8       72      69      77
80      41      6       49      100     77      17      47      18      62
14      88      30      88      94      93      58      54      49      95
76      9       66      89      36      72      16      13      20      33
54      5       57      20      57      72      27      2       46      66
13      3       4       44      41      36      85      13      26      97
63      50      8       49      87      19      23      47      60      68
52      17      13      42      57      67      13      43      70      31
60      83      17      6       58      60      97      6       65      75
58      98      59      36      69      15      79      62      99      31
14      11      95      67      58      65      96      19      43      73
76      15      72      54      94      73      43      84      72      70
52      28      10      32      35      50      91      77      24      40
38      38      31      91      100     55      34      71      32      90
20      29      46      29      45      20      30      61      1       5
19      48      70      97      41      33      5       21      39      19
94      49      43      83      1       60      38      76      40      49
14      96      34      18      43      90      85      42      48      52
45      79      7       94      18      24      23      68      90      58
64      81      1       74      32      100     27      81      94      83
42      55      28      13      66      43      15      84      95      1
74      53      33      86      41      38      17      6       18      76
2       45      75      15      38      97      67      95      72      69
85      49      2       22      10      65      10      98      53      60
27      77      2       48      30      52      85      27      65      29
44      2       43      64      5       55      31      89      35      29
96      42      73      91      55      12      59      96      44      9
51      92      11      87      93      29      12      33      67      11
65      2       5       90      66      16      94      5       52      56
57      29      56      65      97      19      57      57      75      40
69      11      90      78      32      52      83      14      22      94
87      28      43      99      20      66      63      30      34      47
95      43      35      8       79      30      33      43      61      23
77      23      27      30      88      30      67      1       13      57
57      21      24      37      64      83      1       96      63      16
38      7       80      28      59      20      87      72      8       77
88      84      70      41      95      20      66      31      24      37
67      70      91      6       8       92      58      68      69      99
19      93      44      84      83      34      64      2       94      50
96      58      55      66      69      83      9       72      45      88
100     24      11      53      75      8       18      21      25      55

Solutions

Expert Solution

CODE -

#include<bits/stdc++.h>

// #include <iostream>

// #include <iomanip>

// #include <fstream>

// If you don't want to use <bits/stdc++> or your compiler doesn't support it, you can remove it and uncomment the above three header files for your code to work.

using namespace std;

main()

{

    int num,count=0;

    ifstream infile ("numbers.txt");

    if (!infile)

    {

        cout << "File not Found" << endl;

        exit(0);

    }

    cout << "Enter the number you want to search: ";

    cin >> num;

    int number;

    while(!infile.eof())            // loop will run until end of file.

    {

        infile >> number;           // getting number from the file.

        if (number == num)

            count++;                 // incrementing the count if number from the file matches the number to be searched.

    }

    infile.close();

    cout << count;

}

SCREENSHOT -


Related Solutions

Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
I just finished this program where the program reads a text file of full names ,...
I just finished this program where the program reads a text file of full names , first and last name, and a zip code. It reads the items then stores the first name and last name and zipcodes as an objects and prints the items.   However, when i use my text file i get this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 " I notice this issue only happens when the names are...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
Add an item to a Text File / C++ the program will prompt for a filename...
Add an item to a Text File / C++ the program will prompt for a filename AND then prompt for a text file item. text file items always contain an unknown amount of spaces, (see getline). Allow the user to put both the filename and the extensions, like groceries.txt or retirementToDo.clist Don't add any directory information to the filenames, use them as typed. If the file does exist, the item will be APPENDED to the end of the file. If...
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function... ALL LINES...
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
WRITE A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX (Create index in text file) full...
WRITE A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX (Create index in text file) full code
write a program in Java that can take a given text file and then compress it...
write a program in Java that can take a given text file and then compress it with Huffman coding due 20 october 2020 Huffman coding can be used to “zip” a text file to save space. You are required to write a program in Java that can take a given text file and then compress it with Huffman coding. Your program should be able to decompress the zipped files as well [4 marks]. In addition, show percentage gain in data...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT