*HOW TO SEARCH FOR THE STUDENT ID IN C++ USING TEXT FILES?*
Text File Content:
ID G1 G2 G3
200 20 20 20
30 30 30 30
400 40 40 40
25 25 25 25
78 78 78 78
666 66 6 66
777 77 100 77
420 77 88 99
1711 10 10 10
404 40 50 60
505 100 100 100
void studentStats() {
ifstream inputFile;
inputFile.open("outFile.txt");
string studentData;
string studentID;
string ID, exam1, exam2, exam3;
string header;
system("cls");
cout << "Enter a Student ID: ";
cin >> studentID;
inputFile >> header;
getline(inputFile, header);
cout << header << endl;
inputFile >> ID;
inputFile >> exam1;
inputFile >> exam2;
inputFile >> exam3;
while (getline(inputFile, studentData)) {
}
if (studentID == ID) {
cout << ID << " "
<< exam1 << " " << exam2 << " " <<
exam3 << endl;
cout << "FOUND!" <<
endl;
}
else {
cout << "NOT FOUND!" <<
endl;
}
inputFile.close();
system("pause");
}//ends studentStats() function
Please find the updated code below::::
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
void studentStats() {
ifstream inputFile;
string studentData;
string studentID;
string ID, exam1, exam2, exam3;
string header;
system("cls");
getline(inputFile, header,'\n');
cout << "Enter a Student ID: ";
cin>>studentID;
string line;//for read line
inputFile.open ("outFile.txt"); //name of file here.
plz mention Complete path if file is not at root
if (inputFile.is_open()) //if file opened
{
while( getline(inputFile,
line,'\n') ) { //get row from text file
stringstream
ss(line); //stream to other variable
ss >>
ID;
ss >>
exam1;
ss >>
exam2;
ss >>
exam3;
if (studentID
== ID) {
cout << "Student FOUND!" <<
endl;
cout << ID << " " << exam1
<< " " << exam2 << " " << exam3 <<
endl;
return ;
}
}
inputFile.close(); //close
file
cout<<"File scan
done........"<<endl;
}
else //if file not found show the below message
{
cout << "Sorry, we could not
find the file." << endl;
}
cout << "Student NOT FOUND!" <<
endl;
inputFile.close();
system("pause");
}//ends studentStats() function
int main(){
studentStats();
return 0;
}
text file
ID G1 G2 G3
200 20 20 20
30 30 30 30
400 40 40 40
25 25 25 25
78 78 78 78
666 66 6 66
777 77 100 77
420 77 88 99
1711 10 10 10
404 40 50 60
505 100 100 100
output:


*HOW TO SEARCH FOR THE STUDENT ID IN C++ USING TEXT FILES?* Text File Content: ID...
*HOW DO I CHANGE THIS FROM A VOID FUNCTION TO A NON-VOID WITH PARAMETERS?* #include<iostream> #include<fstream> #include<string> using namespace std; void studentStats() { ifstream inputFile; inputFile.open("outFile.txt"); string studentData; string studentID; string ID, exam1, exam2, exam3; string header; cout << "Enter a Student ID: "; cin >> studentID; bool found =false; while (inputFile) { inputFile >> ID; inputFile >> exam1; inputFile >> exam2; inputFile >> exam3; if (ID.compare(studentID)==0) { cout << ID << " " << exam1 << " " <<...
[C++]
Using Files—Total and Average Rainfall
Write a program that reads in from a file a starting month name, an
ending month name, and then the monthly rainfall for each month
during that period. As it does this, it should
sum the rainfall amounts and then report the total rainfall and
average rainfall for the period. For example, the output might look
like this: During the months of March–June the total rainfall was
7.32 inches and the average monthly rainfall...
My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...
I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...
Write a C++ program which performs +, -, *, / and $ on hexadecimal operands. The maximum length of any operand or a solution is 40 digits. The input will be in the following format: Op1 op op2 = There is no space between operands and operator. Note 5/2 = quotient 2, remainder 1 2$3 = 8 The output should be of the form 2*3=6. Read date from a file. TEST DATA (input.txt): AAAA+BBF= BFD+2DE= 100*AA= 100$5= 100/F= 10000000000000-1= AAAAABBBBBCCCCCDDDDDEEEEEFFFFF-ABCDEF0123456789ABCDEF=...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...
I have a C++ code that lets me enter, display and delete a
student record. I need to implement a function that prints the
average grade score of the students I input.
Below is my code and a picture of how my code looks right
now.
#include<iostream>
#include<stdlib.h>
using namespace std;
//Node Declaration
struct node
{
string name;
string id;
int score;
node *next;
};
//List class
class list
{
private:
//head...
in C++ You are to define a structure containing the id number, three test scores, and their average, for each student in a class of 20. The file pr2data.txt is included and contains the data. The program is to include the following: A function that reads 20 records of data from the file, finds the average for each student and prints each student’s record. A function that lists the ids and averages for all the students whose average is above...
C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to include the following: • Write a Search function to search by student score • Write a Search function to search by student last name • Write a Sort function to sort the list by student score • Write a Sort function to sort the list by student last name • Write a menu function that lets user to choose any action he/she want to...