7 like 0 dislike

Be careful! You can only submit answer 1 time. Dont worry, if you're not correct, we will check it manual!

Assume that the following information is stored in a text file called "data.txt".

     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
     13 student13 3.1
     14 student14 3.9
     15 student15 2.6
     16 student16 4.0
     17 student17 3.3
     18 student18 2.6

Fill in the blanks in the following C++ code so it will read the text file above, and find a student with a specific ID and print their name and GPA.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
   string idToLookFor;
   string id;
   string name;
   string gpa;
   cout << "Enter student ID: ";
   cin >> $1;
   $2 din;
   din.open( $3 );
   if ( $4 )
      cout << "Error.  Unable to open file.\n";
   else {
      while((din >> id) && (id != idToLookFor))
         din >> name >> gpa;
      if ($5 == idToLookFor)
      {
         din >> $6 ;
         cout << "Student name: " << name
              << " GPA: " << gpa << endl;
      }
      else
         cout << "The student was not found." << endl;
      din.$7();
   }
return 0; 
}

p/s: There are no space in all blanks

asked in Final Exam Preparation by (11.8k points)
reshown by | 87 views
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help

22 Answers

0 like 0 dislike
Hidden content!
**** * *
* ** *
** * ** * *** ******** ** *

[4]:!din

[5]:id
**** **** *
* *
answered by (10.8k points)
0 like 0 dislike
Hidden content!
* **** * **
** *
* ** * * * * *** ***

[4]:!din

[5]:id
* * **** **
***
answered by (-45 points)
0 like 0 dislike
Hidden content!
***
* **
* *** * ** * ** ** *

[4]:!din

[5]:id
* * * **** * gpa
** *
answered by (-144 points)
0 like 0 dislike
Hidden content!
* *
* * ****
*** ** * ** * * * *
** *

[5]:id

[6]:name ***** **** gpa
* * *
answered by (-74 points)
0 like 0 dislike
Hidden content!
* **
** * *
* *** * * *** *
* * *

[5]:id
* * *** * * gpa
*****
answered by (157 points)
reshown by
0 like 0 dislike
Hidden content!
*** *
* ** * *
*** ** * ** * * * * * *

[4]:!din

[5]:id
***** * * ** *** ***
* **
answered by (24 points)
0 0
[2]:fstream

input mistake.....
0 like 0 dislike
Hidden content!
* *
**** *
** * ** * * **

[4]:! * *

[5]:id
* * * * *** gpa
** **
answered by (-11 points)
0 like 0 dislike
Hidden content!
* * *****
* **** *
*** ** ** *


[5]:id == * *****

[6]:id
* *
answered by (-359 points)
0 like 0 dislike
Hidden content!
* * *
* *****
* *** * *** , **
** **

[5]:id
* * * * gpa
answered by (-103 points)
0 like 0 dislike
Hidden content!
* *** ***
*** *
**** * * * * * *
* * *

[5]:id
**** * * * *** gpa
** *
answered by (16 points)
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.62.178
©2016-2018

Related questions

7 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Jun 16, 2016 in Final Exam Preparation
Available when: Unlimited - Due to: Unlimited
| 81 views
6 like 0 dislike
20 answers
[Exercise] Essay (Open question) - asked Jun 16, 2016 in Final Exam Preparation
Available when: Unlimited - Due to: Unlimited
| 53 views
7 like 0 dislike
44 answers
[Exercise] Multichoice - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 17 views
6 like 0 dislike
32 answers
[Exercise] True/False - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 29 views
3 like 1 dislike
8 answers
[Exercise] Essay (Open question) - asked Jun 22, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 31 views
2,974 questions
57,433 answers
29,089 comments
938 users