C++ Exam Prep Programming Warm-Up Exercise: You will need to write a program to
ID: 3732448 • Letter: C
Question
C++ Exam Prep Programming Warm-Up Exercise:
You will need to write a program to manage a project/to-do list with the following requirements: 1. Store project data in a file including: Project name, description, start date, end date, expected time required, time expended, complete or not 2. The file should be structured with each project stored on two lines. The first line should have each data item except description (name, start, end, times) separated by a comma. The description should be on the second line. 3. Allow the user to display all current projects . Allow the user to look up a project based on name or date 5. Allow the user to add new projects 6. Allow the user to continue to look up and add projects until they choose to exit 7. Use at least two structures and one enum Submit: Fully documented and compilable source code along with data file usedExplanation / Answer
Answer :
C++ code:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct date
{
int month;
int day;
int year;
};
enum state {COMPLETED = 1, WORKING = 0};
struct project_Detailes
{
string projectName, description;
struct date startDate, endDate;
int expectedTime , timeExpended;
int pState;
};
void add()
{
ofstream outfile;
outfile.open("F:project.txt", ios::app);
struct project_Detailes p;
cout<<"Enter all the detailes"<<endl;
cout<<"Enter project name : ";
cin.ignore();
getline (std::cin,p.projectName);
cout<<" Enter Description : ";
getline (std::cin,p.description);
cout<<" Enter startDate -- ";
cout<<" Enter month : ";
cin>>(p.startDate).month;
cout<<" Enter day : ";
cin>>(p.startDate).day;
cout<<" Enter year : ";
cin>>(p.startDate).year;
cout<<" Enter end date -- ";
cout<<" Enter month : ";
cin>>(p.endDate).month;
cout<<" Enter day : ";
cin>>(p.endDate).day;
cout<<" Enter year : ";
cin>>(p.endDate).year;
cout<<" Enter expected time in minutes : ";
cin>>p.expectedTime;
cout<<" Enter time expended in minutes : ";
cin>>p.timeExpended;
cout<<" Enter 1-Completed 0-working";
cin>>p.pState;
outfile<<p.projectName<<","<<p.startDate.day<<"/"<<p.startDate.month<<"/"<<p.startDate.year<<","<<p.endDate.day<<"/"<<p.endDate.month<<"/"<<p.endDate.year;
outfile<<","<<p.expectedTime <<","<<p.timeExpended<<",";
switch(p.pState)
{
case COMPLETED:
outfile<<"Completed"<<endl;
break;
case WORKING:
outfile<<"Working"<<endl;
break;
}
outfile<<p.description<<endl;
outfile.close();
}
void display()
{
ifstream infile;
string str;
int i,j=1;
string contents[]={"Project Name","Start date","End date","Expected Date","Time Expended","Status"};
infile.open("F:project.txt");
while(!infile.eof()){
infile>>str;
if(str=="") return;
cout<<" ********* Project "<<j<<" Detailes ***********"<<endl;
int index=0;
for(i=0;i<str.length();i++)
{
if(i==0 || str[i]==','){
cout<<" "<<contents[index]<<" : ";
index++;
}
if(str[i]!=','){
cout<<str[i];
}
}
infile>>str;
j++;
cout<<" Description : "<<str;
cout<<" *******"<<endl;
}
infile.close();
}
void searchf()
{
ifstream infile;
int i;
infile.open("F:project.txt");
string str,out;
string contents[]={"Project Name","Start date","End date","Expected Date","Time Expended","Status"};
cout<<"Enter project Name to search for";
cin>>str;
while(!infile.eof()){
infile>>out;
if(out=="") return;
std::size_t found = out.find(str);
if (found!=std::string::npos){
cout<<"Search for project name - "<<str<<" is a success :"<<endl;
int index=0;
for(i=0;i<out.length();i++)
{
if(i==0 || str[i]==','){
cout<<" "<<contents[index]<<" : ";
index++;
}
if(out[i]!=','){
cout<<out[i];
}
}
infile>>out;
cout<<" Description : "<<out;
return;
}
infile>>out;
}
infile.close();
}
int main()
{
char ch;
while(true){
cout<<"Menu"<<endl;
cout<<"d - Display all current projects"<<endl;
cout<<"s - Look up a project based on name"<<endl;
cout<<"a - Add new project"<<endl;
cout<<"e - Exit"<<endl;
cout<<" Your choice ? "<<endl;
cin>>ch;
switch(ch)
{
case 'd':
display();
break;
case 's':
searchf();
break;
case 'a':
add();
cout<<"record added successfully"<<endl;
break;
case 'e':
exit(EXIT_SUCCESS);
break;
default:
cout<<"Please enter correct choice"<<endl;
break;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.