Advertisement
skb50bd

CSE107Final_Q4

Sep 9th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. class SAFFFootball {
  7. private:
  8.     char host_nation[20];
  9.     char year[5];
  10.     char champion[20];
  11.     char runnerup[20];
  12.     char third_place[20];
  13.     char fourth_place[20];
  14. public:
  15.     SAFFFootball() {}
  16.     ~SAFFFootball() {}
  17.  
  18.     void read() {
  19.         cout << "Host Nation: ";
  20.         cin >> host_nation;
  21.         cout << "Year: ";
  22.         cin >> year;
  23.         cout << "Champion: ";
  24.         cin >> champion;
  25.         cout << "Runnerup: ";
  26.         cin >> runnerup;
  27.         cout << "Third: ";
  28.         cin >> third_place;
  29.         cout << "Fourth: ";
  30.         cin >> fourth_place;
  31.     }
  32.  
  33.     char * getHost() { return host_nation; }
  34.     char * getYear() { return year; }
  35.     char * getChampion() { return champion; }
  36.     char * getRunnerup() { return runnerup; }
  37.     char * getThird() { return third_place; }
  38.     char * getFourth() { return fourth_place; }
  39. };
  40.  
  41.  
  42. int main() {
  43.     char country[20];
  44.  
  45.     SAFFFootball Rec;
  46.  
  47.     ifstream infile;
  48.     infile.open("SAFF.dat", ios::binary);
  49.  
  50.     cout << "Enter team name: ";
  51.     cin >> country;
  52.  
  53.     cout << "Performance of Bangladesh" << endl;
  54.     while(infile.good()) {
  55.         reinterpret_cast <char *> (&Rec), sizeof(SAFFFootball);
  56.         cout << "Year " << Rec.getYear() << ": ";
  57.  
  58.         if(!strcmp(country, Rec.getChampion()))
  59.             cout << "Champion" << endl;
  60.         else if(!strcmp(country, Rec.getRunnerup()))
  61.             cout << "Runnerup" << endl;
  62.         else if(!strcmp(country, Rec.getThird()))
  63.             cout << "Third" << endl;
  64.         else if(!strcmp(country, Rec.getFourth()))
  65.             cout << "Fourth" << endl;
  66.         else
  67.             cout << "No information found" << endl;
  68.     }
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement