Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "Training.h"
- using namespace std;
- int main()
- {
- Training *ptr; // training class object
- char object_training_id[6]; // these object is act like tempopray variable only
- char object_description[50]; // the result will then set into Training class object
- char object_date[50];
- char object_time[20];
- float object_charges;
- int object_registered;
- char object_Ic[15];
- char object_firstname[20];
- char object_lastname[20];
- ifstream inputfile; // variable for inputfile
- inputfile.open("data.txt", ios::in); //open file
- if(!inputfile)
- {
- cout << "Unavailable file" << endl;
- return 0;
- }
- int number_Training;
- inputfile >> number_Training;
- cout << number_Training << endl;
- ptr = new Training[number_Training]; // dynamic
- if(inputfile)
- {
- for(int i = 0; i < number_Training;i++)
- {
- inputfile >> object_training_id;
- ptr[i].setTrainingId(object_training_id);
- cout << object_training_id << endl;
- inputfile.ignore();
- inputfile.getline(object_description,50);
- ptr[i].setTrainingDescp(object_description);
- cout << object_description << endl;
- inputfile.getline(object_date,50);
- ptr[i].setTrainingDate(object_date);
- cout << object_date << endl;
- inputfile.getline(object_time,20);
- ptr[i].setTrainingTime(object_time);
- cout << object_time << endl;
- inputfile >> object_charges;
- ptr[i].setTrainingCharges(object_charges);
- cout << object_charges << endl;
- inputfile >> object_registered;
- ptr[i].setTrainingReg(object_registered);
- cout << object_registered << endl;
- for(int j=0; j < object_registered; j++)
- {
- inputfile.ignore();
- inputfile.getline(object_Ic,15);
- cout << object_Ic << endl;
- inputfile >> object_firstname;
- cout << object_firstname << endl;
- inputfile >> object_lastname;
- cout << object_lastname << endl;
- ptr[i].setParticipant(j,object_Ic,object_firstname,object_lastname);
- }//end for inner for loop
- }
- }//if for infile
- inputfile.close();
- char choice;
- do{
- cout << "Welcome yoo" << endl;
- cout << "1. Register a new participant" << endl;
- cout << "2. Remove a participant from a training session" << endl;
- cout << "3. Modify a Training details" << endl;
- cout << "4. Display a Training details" << endl;
- cout << "5. Quit" << endl;
- cout << "Please Enter a Number : " ;
- cin >> choice;
- cout << endl; // for end line
- if(choice == '1')
- {
- cout << "Entered 1" << endl;
- cout << "There are now " << number_Training << " course" << endl;
- cout << "Number" << "\t" << "Course Description" << endl;
- for(int i =0; i < number_Training; i++)
- {
- cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
- }
- int number;
- cout << "Please enter the number : ";
- cin >> number;
- if(validate_Session(number,number_Training))
- {
- if(ptr[number-1].getTrainingReg() >= 30)
- {
- cout << "No new registration should be allowed!" << endl;
- cout << "It's Full."<< endl;
- }//end for if
- else
- {
- registration(object_Ic,object_firstname, object_lastname);
- if(validate_Ic(object_Ic))
- {
- ptr[number-1].setParticipant(ptr[number-1].getTrainingReg(), object_Ic, object_firstname,object_lastname);
- ptr[number-1].setTrainingReg(ptr[number-1].getTrainingReg() + 1);
- cout << "Successfully Register" << endl;
- cout << endl;
- }
- else
- {
- cout << "Unable to register. Please try again " << endl;
- cout << endl;
- }
- }// end for else
- }//end for if validate
- else
- {
- cout << "The number invalid "<<endl;
- }
- }//end for choice 1
- else if(choice == '2')
- {
- cout << "Entered 2" << endl;
- cout << "There are now " << number_Training << " course" << endl;
- cout << "Number" << "\t" << "Course Description" << endl;
- for(int i =0; i < number_Training; i++)
- {
- cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
- }
- int number;
- cout << "Please enter the number : ";
- cin >> number;
- if(validate_Session(number, number_Training))
- {
- cout << "No. " << "\t" << "Participant ID" << endl;
- for(int i =0; i < ptr[number-1].getTrainingReg(); i++)
- {
- cout << (i+1) << "\t" << ptr[number-1].getParticipantIc(i) << endl;
- }
- cout << "Enter Participant ID : ";
- cin.ignore();
- cin.getline(object_Ic,15);
- ptr[number-1].remove_Participant(object_Ic);
- }
- }//end for choice 2
- else if(choice=='3')
- {
- cout << "Entered 3" << endl;
- cout << "There are now " << number_Training << " course" << endl;
- cout << "Number" << "\t" << "Course Description" << endl;
- for(int i =0; i < number_Training; i++)
- {
- cout << (i+1) << "\t"<< ptr[i].getTrainingId() << endl;
- }
- int number;
- cout << "Please enter the number : ";
- cin >> number;
- cout << endl;
- bool validated = true;
- if(validate_Session(number,number_Training))
- {
- cout << "+# " << ptr[number-1].getTrainingId() << endl;
- cout << "+# " << ptr[number-1].getTrainingDescp() << endl;
- cout << "+# " << ptr[number-1].getTrainingDate() << endl;
- cout << "+# " << ptr[number-1].getTrainingTime() << endl;
- cout << "+# " << ptr[number-1].getTrainingCharges() << endl;
- cout << endl;
- cout << "Enter new Info below" << endl;
- cin.ignore();
- cout << "Training ID : " ;
- cin.getline(object_training_id, 6);
- cout << "Training Description : ";
- cin.getline(object_description, 50);
- cout << "Training Date : ";
- cin.getline(object_date, 50);
- cout << "Training Time : ";
- cin.getline(object_time, 20);
- cout << "Training Charges : ";
- cin >> object_charges;
- if(validate_Id(object_training_id))
- {
- ptr[number-1].setTrainingId(object_training_id);
- ptr[number-1].setTrainingDescp(object_description);
- ptr[number-1].setTrainingDate(object_date);
- ptr[number-1].setTrainingTime(object_time);
- ptr[number-1].setTrainingCharges(object_charges);
- cout << "Successfully Modify!!!" << endl;
- }
- else
- {
- cout << "Unable to modify data. Please try again" << endl;
- }
- }
- else
- {
- cout << "Invalid Session" << endl;
- }
- }//end for choice 3
- else if(choice == '4')
- {
- for(int i = 0; i < number_Training; i++)
- {
- ptr[i].display();
- }
- }//end for choice 4
- cout << endl;
- }while(choice != '5');
- return 0;
- }//end for main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement