Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Source file : Brown_B_Prj5.cpp
- Programmer: Blaine Allen Brown
- Date: December 2, 2011
- Lab CRN 10940
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct infoType
- {
- string name;
- int id;
- double height;
- double weight;
- double postWeight;
- int bmi;
- int postBmi;
- };
- struct nodeType
- {
- infoType info;
- nodeType *link;
- };
- void add(nodeType *list, ifstream& inFile)
- {
- cout << "4" << endl; //debug
- string name;
- int id;
- double height;
- double weight;
- nodeType *position;
- cout << "5" << endl; //debug
- position = list;
- cout << "6" << endl; //debug
- if(list != NULL)
- {
- while(position->link != NULL)
- {
- cout << "7" << endl; //debug
- position = position->link;
- cout << "8" << endl; //debug
- }
- }
- cout << "9" << endl; //debug
- nodeType *temp;
- cout << "10" << endl; //debug
- temp = new nodeType;
- cout << "11" << endl; //debug
- inFile >> name >> id >> height >> weight;
- cout << "12" << endl; //debug
- temp->info.name = name;
- temp->info.id = id;
- temp->info.height = height;
- temp->info.weight = weight;
- cout << "13" << endl; //debug
- temp->link = NULL;
- cout << "14" << endl; //debug
- position->link = temp;
- cout << "15" << endl; //debug
- }
- void print(nodeType *list, char yesNo)
- {
- int counter = 0;
- cout << "Printing the list of members..." << endl;
- if(list == NULL)
- {
- cout << "Got nothing." << endl;
- }
- nodeType *position;
- position = list;
- while(position != NULL)
- {
- cout << "Name: " << position->info.name << endl;
- cout << "ID: " << position->info.id << endl;
- cout << "Height: " << position->info.height << endl;
- if(yesNo == 'y')
- {
- cout << "Starting weight: " << position->info.weight << endl;
- cout << "Starting BMI: " << position->info.bmi << endl;
- cout << "Current weight: " << position->info.postWeight << endl;
- cout << "Current BMI: " << position->info.postBmi << endl;
- }
- else
- {
- cout << "Weight: " << position->info.weight << endl;
- }
- cout << endl;
- counter++;
- }
- cout << counter << " members in the list." << endl << endl;
- }
- int main()
- {
- cout << "1" << endl; //debug
- nodeType *list;
- cout << "2" << endl; //debug
- list = NULL;
- cout << "3" << endl; //debug
- //File 1
- ifstream inFile;
- inFile.open("peeps.txt");
- if(!inFile)
- {
- cout << "No such file." << endl;
- system("PAUSE");
- return 1;
- }
- while(!inFile.eof())
- {
- add(list, inFile);
- }
- print(list, 'n');
- inFile.close();
- inFile.clear();
- //File 2
- inFile.open("changes.txt");
- if(!inFile)
- {
- cout << "No such file." << endl;
- system("PAUSE");
- return 1;
- }
- inFile.close();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement