Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A program that allows the user to display all current projects, look up
- // a project based on name or date, add new projects, and continue to look up
- // and add projects until they choose to exit.
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- enum Question {YES, NO};
- struct dateTime{
- string request;
- string used;
- string start;
- string finish;
- };
- struct toDoList{
- string projName;
- dateTime timeGive;
- char completeYN;
- string description;
- };
- //Pre: allows the user to answer either yes or no
- //Post: returns either yes or no
- Question askQ();
- //Pre: GetProjects holds the Projects variable
- // Post: the fields are written for Projects
- toDoList GetProject(ifstream &inData);
- // Prompt user for input file to be used
- // Pre: inData declared
- // Post: the program searches for the program via the name input
- void GetFileInfo(ifstream& inData);
- // Function should print the projects contained in the allCars array
- // Pre: allProjects[] contains 0 or more projects
- // projCount contains the number of projects in allProjects[]
- // Post: Contents of allProjects[] printed to the screen
- void PrintProjects(const toDoList allProjects[], int projCount);
- //Pre: prompts the user if they want to view the projects
- //Post: displays the projects
- // prompts the user to display and displays
- void displayProjects(ifstream &inData, toDoList Project, Question YNans);
- //Pre: file outData has been opened
- //Post: the fields of Project are written on the outData
- // file and labeled
- void WriteProjects(ofstream &outData, toDoList Project);
- //Pre: prompts the user to search for programs
- //Post: searches for the programs by date or name
- // prompts the user to search by either name or date
- char searchProject(ifstream &inData, toDoList Project, Question YNans);
- //Pre: prompts the user to add new projects
- //Post: adds new projects to the output file
- //prompts the user to add files and add if yes
- char addNewProjects(ofstream &outData, toDoList Project, Question YNans);
- //Pre: prompts the user to continue searching
- //Post: allows the user to search for more programs
- // prompts the user if they would like to continue searching
- // and restarts the search if yes
- bool continueLook();
- const int MAX_PROJECTS = 50;
- int main(){
- ifstream inData;
- ofstream outData;
- Question YNans;
- bool answer = true; // bool for continuation of the program
- inData.open("Projects.txt");
- outData.open ("ProjectsComplete.txt");
- GetFileInfo(inData);
- toDoList allprojects[MAX_PROJECTS] = GetProject(inData);
- while(inData){
- toDoList allprojects[MAX_PROJECTS] = GetProject(inData);
- toDoList Project = GetProject(inData);
- displayProjects(inData, Project, YNans);
- WriteProjects(outData, Project);
- searchProject(inData, Project, YNans);
- addNewProjects(outData, Project, YNans);
- bool answer = continueLook();
- if(answer = true){
- cout << "We go again!\n";
- }
- else if(answer == false){
- cout << "Smell ya later.\n" << endl;
- break;
- }
- }
- return 0;
- }
- Question askQ(){
- char input;
- cin >> input;
- if (input == 'Y' || input == 'y'){
- return YES;
- }
- else if(input == 'N' || input == 'n'){
- return NO;
- }
- }
- toDoList GetProject(ifstream &inData){
- toDoList Project;
- inData >> Project.projName;
- inData >> Project.timeGive.start;
- inData >> Project.timeGive.finish;
- inData >> Project.timeGive.request;
- inData >> Project.timeGive.used;
- inData >> Project.completeYN;
- inData >> Project.description;
- getline(inData, Project.description);
- inData.ignore (2, '\n');
- return Project;
- }
- void PrintProjects(const toDoList allProjects[], int projCount){
- cout << "in print.\n";
- for(int i = 0; i < projCount; i++){
- displayProjects(allProjects[i]);
- }
- }
- void displayProjects(ifstream &inData, toDoList Project, Question YNans){
- cout << "Would you like to display your projects? Y for yes or N for no.\n";
- YNans = askQ();
- if (YNans == YES){
- cout << "Name: " << Project.projName << endl;
- cout << "Date started: " << Project.timeGive.start << endl;
- cout << "Date ended: " << Project.timeGive.finish << endl;
- cout << "Time required: " << Project.timeGive.request << endl;
- cout << "Time expended: " << Project.timeGive.used << endl;
- cout << "Complete? " << Project.completeYN << endl;
- cout << "Description: " << Project.description << endl;
- }
- else if(YNans == NO){
- cout << "I see you like to live on the edge.\n" << endl;
- }
- }
- void WriteProjects(ofstream &outData, toDoList Project){
- outData << "Name: " << Project.projName << endl;
- outData << "Date started: " << Project.timeGive.start << endl;
- outData << "Date ended: " << Project.timeGive.finish << endl;
- outData << "Time required: " << Project.timeGive.request << endl;
- outData << "Time expended: " << Project.timeGive.used << endl;
- outData << "Complete? " << Project.completeYN << endl;
- outData << "Description: " << Project.description << endl;
- }
- char searchProject(ifstream &inData, toDoList Project, Question YNans){
- string name;
- string day;
- cout << "Would you like to search?\n";
- YNans = askQ();
- if (YNans == YES){
- cout << "Would you like to search by name?\n";
- YNans = askQ();
- if (YNans == YES){
- cout << "Please enter a name to search by.\n";
- cin >> name;
- }
- else if(YNans == NO){
- cout << "Would you like to search by date?\n";
- YNans = askQ();
- if (YNans == YES){
- cout << "Please enter a date to search by.\n";
- cin >> day;
- }
- else if(YNans == NO){
- cout << "Then I can't help you with searching.\n";
- }
- }
- }
- else if(YNans == NO){
- cout << "That's okay, searching isn't my favorite thing anyway.\n" << endl;
- }
- }
- char addNewProjects(ofstream &outData, toDoList Project, Question YNans){
- cout << "Would you like to add any new projects? Y for yes or N for no.\n";
- YNans = askQ();
- if (YNans == YES){
- cout << "Please enter a name for your program:\n";
- cin >> Project.projName;
- cout << "Enter a start date:\n";
- cin >> Project.timeGive.start;
- cout << "Enter an end date:\n";
- cin >> Project.timeGive.finish;
- cout << "Enter the expected time required:\n";
- cin >> Project.timeGive.request;
- cout << "Enter the time taken:\n";
- cin >> Project.timeGive.used;
- cout << "Was it completed?\n";
- Project.completeYN = askQ();
- cout << "Please enter the description of the program:\n";
- cin >> Project.description;
- cin.ignore();
- getline(cin, Project.description);
- outData << Project.projName << ", "
- << Project.timeGive.start << ", "
- << Project.timeGive.finish << ", "
- << Project.timeGive.request << ", "
- << Project.timeGive.used << ", "
- << Project.completeYN << endl;
- outData << Project.description << endl;
- }
- else if(YNans == NO){
- cout << "Sometimes people don't want to add anything and that's okay.\n" << endl;
- }
- }
- bool continueLook(){
- cout << "Would you like to continue searching? Y for yes or N for no.\n";
- bool answer = askQ();
- return answer;
- }
- void GetFileInfo(ifstream& inData){
- while (!inData){
- cout << "File Error. File not found, try again." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement