Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. //this piece of code accepts the number of contributors, contributor names and the donations they made, from the user.
  2. //Then, it will output the contributor names who donated more than
  3. //10000$ under Grand Patrons and others under Head Patrons. It will also create a file named contributors.txt with the names and donations made.
  4.  
  5. #include<iostream>
  6. #include<fstream>
  7. #include<cstdlib>
  8. #include<cctype>
  9. const int Max = 200;
  10. struct contrib {
  11.         char name[Max];
  12.         double donation;
  13. };
  14.  
  15. int main()
  16. {
  17.         int* noofcon = new int;
  18.         int i,tmp;
  19.         i = tmp = 0;
  20.         std::cout<<"Please enter the number of contributors >>";
  21.         std::cin>>*noofcon;
  22.         std::cin.get();
  23.         std::ofstream outfile;
  24.         outfile.open("contributors.txt");
  25.         contrib* conts = new contrib [*noofcon];
  26.         while(i<*noofcon)
  27.         {
  28.                 std::cout<<"Enter the name of contributor #"<<(i+1)<<" >>";
  29.                 std::cin.getline(conts[i].name,Max);
  30.                 outfile<<conts[i].name<<"\n";
  31.                 std::cout<<"Enter the amount contributed by Mr./Mrs."<<conts[i].name<<" >>";
  32.                 std::cin>>conts[i].donation;
  33.                 outfile<<conts[i].donation<<"\n";
  34.                 std::cin.get();
  35.                 i++;
  36.         }
  37.         outfile.close();
  38.         std::cout<<"Grand Patrons :"<<std::endl;
  39.         for(int j = 0;(j<*noofcon) and (conts[j].donation > 10000);j++) //loop to print contributors who contributed more than 10000$
  40.         {
  41.                 tmp = 1;
  42.                 /*if(conts[j].donation > 10000) {*/
  43.                         std::cout<<conts[j].name<<"\n";
  44.                         std::cout<<conts[j].donation<<"\n";
  45.         /*      } */
  46.         }
  47.         if (tmp == 0) std::cout<<"none"; //if there are no such contributors, it will display none.
  48.         std::cout<<"Head Patrons :"<<std::endl;
  49.         for(int j = 0;(j<*noofcon) and (conts[j].donation < 10000);j++) //loop to print contributors who contributed less than 10000$
  50.         {
  51.                 tmp = 2;
  52.                 std::cout<<conts[j].name<<"\n";
  53.                 std::cout<<conts[j].donation<<"\n";
  54.         }
  55.         if (tmp != 2) std::cout<<"none"; //if there are no such contributors, it will display none.
  56.         delete noofcon;
  57.         delete [] conts;
  58.  
  59.         return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement