Here is the Chapter 6 9 assignment. Fist a screen shot of the program running then the text file:
4
Sam Stone
2000
Freida Class
100500
Tammy Tubbs
5000
Red Raptor
55000
Here is the code
#include <iostream>
#include<fstream>
#include <string>
using namespace std;
struct Contributors
{
string name;
double amount;
};
const double GRAND= 10000;
void GetContributors()
{
int number=0;
fstream patrons("C:\\Users\\sconger\\Desktop\\donors.txt", ios::in | ios::app);
patrons >> number;
cout << "The number of contriburtors is " << number << endl;
patrons.ignore();
Contributors * donorList = new Contributors[number];
while (!patrons.eof())
{
for(int i=0;i<number;i++)
{
getline(patrons,donorList[i].name);
patrons>>donorList[i].amount;
patrons.ignore();
}
patrons.ignore();
}
patrons.close();
cout << "Grand Patrons" << endl;
cout << "****************************"<<endl;
for(int i=0;i<number;i++)
{
if(donorList[i].amount >= GRAND)
{
cout << donorList[i].name << "\t\t" << donorList[i].amount << endl;
}
}
cout << "Patrons" << endl;
cout << "****************************"<<endl;
for(int i=0;i<number;i++)
{
if(donorList[i].amount < GRAND)
{
cout << donorList[i].name << "\t\t" << donorList[i].amount << endl;
}
}
delete[] donorList;
}
int main()
{
GetContributors();
char c;
cin >> c;
}
No comments:
Post a Comment