Assume that the following information is stored in a text file called "data.txt". Fill in the blanks in the following C++ code and debug so that it will read the text file above and find a student with a specific ID and print their name and GPA. Add comments stating all errors removed
- Assume that the following information is stored in a text file called "data.txt". Fill in the blanks in the following C++ code and debug so that it will read the text file above and find a student with a specific ID and print their name and GPA. Add comments stating all errors removed.
1 student1 3.5
2 student2 0.6
3 student3 4.0
4 student4 2.2
5 student5 2.3
6 student6 3.8
7 student7 3.5
8 student8 3.1
9 student9 1.5
10 student10 3.0
11 student11 2.0
12 student12 1.6
#include <iostream>
include <fstream>
#include <string>
using namespace std;
int main()
{
string idToLookFor;
string id;
string name;
string gpa;
cout << "Enter student ID: ";
cin >> ____________;
___________ din;
din.open( "__________" )
if ( ___________() )
cout << "Error. Unable to open file.\n";
else
{
while((din >> _______) && (id != idToLookFor))
cin >> name >> GPA;
if (________ == idToLookFor)
{
cin _________________ ;
cout << "Student name: " << name
<< " GPA: " << gpa endl;
}
else
cout << "The student was not found." << endl;
din._____________();
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images