Hi, I'm fairly new to C++.
My project states that I must write a program that will allow the user to view a list of TV shows read from an input file. each show should consist of four data members: show ID, Title, day of show, and time(pm). ID serves as primary key.
input file:
123 CSI Thursday 9
127 Survivor Thursday 8
124 Office Friday 10
122 AmazingRace Wednesday 7
125 Football Sunday 1
The program must read in the file and store it in an "Array of struct", and loop through the following MENU until the user quits.
'A' - ADD a show
'D' - DISPLAY list of shows
'M' - MODIFY a show's start time
'Q' - Quit
*Note - Modify will display a list of shows and ID's the user will pick one and then it will allow the user to edit the start time.
I understand structs, how to display the information, i/o, and looping but I am having trouble adding a show and modifying the shows
Here is my attempt:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
struct showType
{
string id[9];
string name[9];
string day[9];
string time[9];
};
showType show;
fstream infile;
int i = 0;
char select;
void Menu ( char select);
void getShows ( showType& show, int& i);
void addShows ( showType& show, int& i);
void modifyShows ( showType& show, int& i);
void displayShows ( showType& show, int& i);
int main()
{
infile.open("Shows.txt");
getShows(show,i);
Menu(select);
//displayShows(show,i);
displayShows(show,i);
system("pause");
return 0;
}
void Menu ( char select)
{
bool inc = true;
cout <<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout <<" Menu"<<endl;
cout <<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout <<" 'A' - ADD a show"<<endl;
cout <<" 'D' - DISPLAY a list of all shows"<<endl;
cout <<" 'M' - MODIFY a show's start time"<<endl;
cout <<" 'Q' - QUIT"<<endl;
cout <<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cin >> select;
while (inc == true)
{
switch(select)
{
case 'a': select = 'A';
case 'A': inc = false;
break;
case 'd': select = 'D';
case 'D': inc = false;
break;
case 'm': select = 'M';
case 'M': inc = false;
break;
case 'q': select = 'Q';
case 'Q': inc = false;
break;
default: inc = true;
cout <<" INVALID INPUT, please select another option."<<endl;
cin >> select;
break;
}
}
switch (select)
{
case 'A': addShows(show, i);
break;
case 'M': modifyShows(show, i);
break;
case 'D': displayShows(show, i);
break;
}
}
void getShows ( showType& show, int& i)
{
for (i; i < 9; i++)
infile >> show.id[i] >> show.name[i] >> show.day[i] >> show.time[i];
}
void addShows ( showType& show, int& i)
{
cout <<" Please enter the show record in the following format"<<endl;
cout <<" ex: 123 CSI Thursday 9"<<endl<<" ";
cin >> show.id[1] >> show.name[1] >> show.day[1] >> show.time[1];
}
void modifyShows (showType& show, int& i)
{
}
void displayShows ( showType& show, int& i)
{
i=0;
cout <<left<<setw(8)<<" Show ID"<<right<<setw(12)<<" Show Name "<<setw(10)<<" Weekday ";
cout <<left<<setw(13)<<" Show Time "<<endl<<endl;
for (i; i < 5; i++)
{
cout <<right<<setw(6)<<setw(3)<<" "<< show.id[i] <<right<<setw(14)<< show.name[i];
cout <<setw(10)<< show.day[i] <<setw(6)<< show.time[i]<<endl;
}
}