Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this piece of code accepts the number of contributors, contributor names and the donations they made, from the user.
- //Then, it will output the contributor names who donated more than
- //10000$ under Grand Patrons and others under Head Patrons. It will also create a file named contributors.txt with the names and donations made.
- #include<iostream>
- #include<fstream>
- #include<cstdlib>
- #include<cctype>
- const int Max = 200;
- struct contrib {
- char name[Max];
- double donation;
- };
- int main()
- {
- int* noofcon = new int;
- int i,tmp;
- i = tmp = 0;
- std::cout<<"Please enter the number of contributors >>";
- std::cin>>*noofcon;
- std::cin.get();
- std::ofstream outfile;
- outfile.open("contributors.txt");
- contrib* conts = new contrib [*noofcon];
- while(i<*noofcon)
- {
- std::cout<<"Enter the name of contributor #"<<(i+1)<<" >>";
- std::cin.getline(conts[i].name,Max);
- outfile<<conts[i].name<<"\n";
- std::cout<<"Enter the amount contributed by Mr./Mrs."<<conts[i].name<<" >>";
- std::cin>>conts[i].donation;
- outfile<<conts[i].donation<<"\n";
- std::cin.get();
- i++;
- }
- outfile.close();
- std::cout<<"Grand Patrons :"<<std::endl;
- for(int j = 0;(j<*noofcon) and (conts[j].donation > 10000);j++) //loop to print contributors who contributed more than 10000$
- {
- tmp = 1;
- /*if(conts[j].donation > 10000) {*/
- std::cout<<conts[j].name<<"\n";
- std::cout<<conts[j].donation<<"\n";
- /* } */
- }
- if (tmp == 0) std::cout<<"none"; //if there are no such contributors, it will display none.
- std::cout<<"Head Patrons :"<<std::endl;
- for(int j = 0;(j<*noofcon) and (conts[j].donation < 10000);j++) //loop to print contributors who contributed less than 10000$
- {
- tmp = 2;
- std::cout<<conts[j].name<<"\n";
- std::cout<<conts[j].donation<<"\n";
- }
- if (tmp != 2) std::cout<<"none"; //if there are no such contributors, it will display none.
- delete noofcon;
- delete [] conts;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement