Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct Time{
- int hour;
- int minutes;};
- struct Classes{
- std::string day;
- std::string location;
- std::string coursenumber;
- Time time;};
- void getfile(ifstream& inData, string& filename);
- void printmenu();
- char getoption();
- void print(ifstream& inData, string& filename);
- Classes newentry(ifstream& inData, ofstream& outData, string& filename);
- void NewSearch(ifstream& inData);
- int main(){
- ifstream inData;
- ofstream outData;
- string filename;
- char option;
- getfile(inData, filename);
- do{
- printmenu();
- option = getoption();
- if(option =='N')
- newentry(inData,outData,filename);
- else if(option =='P')
- print(inData, filename);
- else if(option == 'S')
- NewSearch(inData);
- else if(option == 'Q')
- cout << "Thank you for using Your Class Schedule have a great day";
- }while(option != 'Q');
- return 0;
- }
- void getfile(ifstream& inData, string& filename)
- {
- char choice;
- cout << "Do you have a new txt schedule file you wish to load from [Y] or [N]" <<endl<< "*For default Class.txt please select [N]*";
- cin >> choice;
- choice = toupper(choice);
- if(choice == 'Y'){
- do{
- cout << "Please enter a .txt filename you wish to load from.";
- cin >> filename;
- inData.open(filename.c_str());
- if (!inData)
- cout << "Please enter a valid file name" << endl;
- }while(!inData);
- }
- else
- filename = "class.txt";
- inData.close();
- }
- void printmenu()
- {
- cout << "Welcome To Your Class Schedule! " << endl;
- cout << "To Add New Entry: [N]" << endl;
- cout << "To search: [S]" << endl;
- cout << "To print schedule: [P]" << endl;
- cout << "To Exit: [Q] " << endl;
- }
- Classes newentry(ifstream& inData, ofstream& outData, string& filename)
- {
- Classes clas;
- Time tim;
- outData.open(filename.c_str(), ios::app);
- cout << "Please enter class Name: ";
- cin >> clas.day;
- outData << clas.day <<','<< " ";
- cout << "Please enter class Number: ";
- cin >> clas.coursenumber;
- outData << clas.coursenumber <<','<< " ";
- cout << "Please enter the day of the class: ";
- cin >> clas.day;
- outData << clas.day <<','<< " ";
- cout << "Please enter the location of the class: ";
- cin >> clas.location;
- outData << clas.location <<','<< " ";
- cout << "Please enter the hour of the class: ";
- cin >> tim.hour;
- outData << tim.hour << ':';
- cout << "Please enter the minutes:";
- cin >> tim.minutes;
- outData << tim.minutes << endl << endl;
- outData.close();
- return clas;
- }
- char getoption()
- {
- char option;
- cin >> option;
- option = toupper(option);
- while(option != ('Q')&&(option != ('N'))&&(option != ('S'))&&(option !=('P'))){
- cout << "please enter valid option:" << endl;
- cin >> option;
- option = toupper(option);
- }
- return option;
- }
- void print(ifstream& inData, string& filename)
- {
- string line;
- inData.open(filename.c_str());
- while(inData){
- getline(inData,line);
- cout << line << endl;
- }
- inData.close();
- }
- void NewSearch(ifstream& inData)
- {
- string line, compare;
- cout << "How would you like to search:" << endl;
- cout << "class Name:[N]" << endl;
- cout << "Class location: [L]" << endl;
- cout << "class number:[#]" << endl;
- cout << "class time: [T]" << endl;
- cout << "Day of Class:[D]" << endl;
- cin >> compare;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement