Advertisement
Porr011

Lesson 9 activity 5

Feb 28th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. #include <cstdlib>
  5. using namespace std;
  6. // varibles for our libary
  7. int main()
  8. {
  9.     //varibles for code
  10.     ifstream inputFile;
  11.     string filename, name, clas, gpa, read;
  12.     int count=0;
  13.    
  14.     // getting our the fille name.
  15.     cout << "Enter the  file name (name.txt)" << endl;
  16.     cin >> filename; // putting the stars when each part starts
  17.     cout << "**********" << endl;
  18.     inputFile.open(filename);
  19.     // if statement if the file is open
  20.    
  21.         // using read to read the data
  22.         while (inputFile >> read)
  23.         {
  24.             // count diffrent info each time to the next set of info
  25.             count=count + 1;
  26.             // couting the Name
  27.             if (read=="Name:"){
  28.                 inputFile >> name;
  29.             }
  30.                else if (read=="Class:"){
  31.                    inputFile >> clas;
  32.                 }
  33.                       else if (read=="GPA:"){
  34.                          inputFile >> gpa;
  35.                     }
  36.     // for each 3 sets of info it realizes that it needs to print the info
  37.      if (count == 3) {
  38.         cout << " Name: " << name << endl;
  39.         cout << " Class: " << clas << endl;
  40.         cout << " Gpa " << gpa << endl;
  41.         cout << " ******** " << endl;
  42.         count = 0;
  43.         // reseting the loop
  44.      }
  45.        
  46.         }// ends function
  47.        
  48.        
  49.            
  50.             //putting the stars after the 3 part is finsihed
  51.            
  52.         inputFile.close();
  53.         // close file
  54.     return 0;
  55. }// end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement