Advertisement
Porr011

Lesson 9 activity 5

Feb 6th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 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;
  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.     if (inputFile){
  21.        
  22.         while (inputFile >> name){
  23.            
  24.             count=count + 1;
  25.             // couting the Name,Class,and GPA
  26.             if (name=="Name:"){
  27.                 cout << name ;
  28.             }else{
  29.                 if (name=="Class:"){
  30.                     cout << name ;
  31.                 }else{
  32.                     if (name=="GPA:"){
  33.                         cout << name ;
  34.                     }else{
  35.                         cout << name << endl;
  36.                     }
  37.                 }
  38.             }
  39.             //putting the stars after the 3 part is finsihed
  40.             if (count>5){
  41.                 count=0;
  42.                 cout << "**********" << endl;
  43.             }
  44.         }
  45.         // if file is not open
  46.     }
  47.    
  48.     else
  49.     {
  50.         cout << "ERROR." << endl;
  51.     }
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement