Design a program that will serve as a database for keeping track of roller coast
ID: 3627876 • Letter: D
Question
Design a program that will serve as a database for keeping track of roller coasters and their related statistics. This application will allow for the storing of the name of a given coaster, its peak height, its type (wood, steel), park name and location, and various user ratings, and store that information into a database (text file). The program will also need to be able to retrieve that information based on data that is to be input by the user of the program.
The program should be interactive, presenting the user with a menu of choices, such as the following:
1. Add Coaster
2. Add Coaster Ratings (Overall Thrill, Hills, Scariness)
3. Search for a Coaster by Type
4. Search for a Coaster by Name
5. Show a Listing of All Coasters
6. Search for a Coaster by Rating
7. Save Database to a file
8. Load Database from a file
9. Exit
Here is a brief explanation of what I am looking for to be contained with each menu item:
1. Add Coaster. The user will be able to enter a roller coaster’s information to store in the database. The information that will be entered will include the name of the coaster, peak height, its type (W or S), park name, and location (City & State). This option has to be completed at least once before options 2, 3 or 4 can be run, meaning, you must prevent a user from trying options 2, 3 or 4 until options 1 or 8 have been chosen.
2. Add Coaster Ratings. The user will be able to select a coaster that they wish to rate (up to you how they select it) and then enter ratings for overall thrill, hills, and scariness, each on a 0-10 basis. Each time a rating is entered, it is added to existing ratings and the number of ratings should be kept track of. In other words, if I entered ratings about the Beast in Cincy today and then tomorrow, your thrills may be 17 and ratings 2.
This option has to be completed at least once before option 6 can be run, meaning, you must prevent a user from trying option 6 until option 2 or 8 have been chosen.
3. Search for Coaster by Type. This option will prompt the user for a type (Wood or Steel) and return any matching coasters of that type. If there are no coasters for a particular type, a message stating this fact should be displayed. Information that should be displayed if a match exists for a given coaster would be in the format below. NOTE: Your program should not allow the user to do #3 unless #1 or #8 has been performed at least once.
SAMPLE DISPLAY:
Coaster: The Beast
Park: Paramount Kings Island
Location: Kings Mill, OH
Peak Height: 220 feet
Coaster: The Big Dipper
Park: Camden Park
Location: Huntington, WV
Peak Height: 65 feet
4. Search for a Coaster by Name. For this option, your program will output the details for coasters matching the name entered. This output will consist of a table similar to the one above.
NOTE: Your program should not allow the user to do #4 unless #1 or #8 has been performed at least once.
5. Show a listing of all Coasters. This option will produce a similar listing to the one in option 3 above, but will simply list every single coaster and its corresponding data, INCLUDING its type (wood or steel). NOTE: Your program should not allow the user to do #5 unless #1 or #8 has been performed at least once.
6. Search for a Coaster by Rating. For this option, your program will output the details for all coasters with a rating scale above numbers you will enter. For example, if you were looking for a coaster with its thrill rating above 7, its height above 6, and scariness above 7, it would output a table similar to the one below.
NOTE: Your program should not allow the user to do #6 unless #2 or #8 has been performed at least once.
Coaster: The Beast
Park: Paramount Kings Island
Location: Kings Mill, OH
Peak Height: 220 feet
Ratings: 6
Thrill: 8.2 Height: 8.1 Scariness: 7.1
But would not list the big dipper if its rating averages were Thrill: 2.1, Height: 6.1, Scariness: 8.1 (simply because it looks like it will fall)
7. Save Database to a file. All of the entered data should be written to a data file (or 2 if need be) (plain .txt file is ok) in a format so that it is easy to retrieve later (see below). You must prompt the user for the name of the file.
8. Load Database from a file. Data will be read back into your program from a previously saved data file (or 2). You must prompt the user for the name of the file.
9. Exit the program gracefully, including closing all files.
Explanation / Answer
please rate - thanks
check it out and get back to me
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct RollerCoaster{
string name;
string park;
string city;
string state;
double peak;
int type;
double thrill;
double height;
double scary;
int ratings;
}coaster[50];
int menu(bool,bool);
bool check(bool,string);
void addCoaster(RollerCoaster[],int&);
void addRating(RollerCoaster[],int);
void searchType(RollerCoaster[],int);
int searchName(RollerCoaster[],int,bool);
void listAll(RollerCoaster[],int);
void searchRate(RollerCoaster[],int);
void save(RollerCoaster[],int);
void load(RollerCoaster[],int&);
void display(RollerCoaster,bool);
double rate(string);
int main()
{int choice,count=0;
bool exists=false,rated=false;
choice=menu(exists,rated);
while(choice!=9)
{cin.ignore(80,' ');
switch(choice)
{case 1: addCoaster(coaster,count);
exists=true;
break;
case 2: addRating(coaster,count);
rated=true;
break;
case 3: searchType(coaster,count);
break;
case 4: searchName(coaster,count,false);
break;
case 5: listAll(coaster,count);
break;
case 6: searchRate(coaster,count);
break;
case 7: save(coaster,count);
break;
case 8: load(coaster,count);
exists=true;
rated=true;
break;
}
choice=menu(exists,rated);
}
}
void addCoaster(RollerCoaster coaster[],int& count)
{int t=0;
cout<<"Enter coaster name: ";
getline(cin,coaster[count].name);
cout<<"Enter coaster park: ";
getline(cin,coaster[count].park);
cout<<"Enter coaster city: ";
getline(cin,coaster[count].city);
cout<<"Enter coaster state: ";
getline(cin,coaster[count].state);
cout<<"Enter coaster peak: ";
cin>>coaster[count].peak;
while(t<1||t>2)
{cout<<"Enter coaster type ";
cout<<"1. wood ";
cout<<"2. steel ";
cin>>t;
if(t<1||t>2)
cout<<"invalid type ";
}
coaster[count].type=t;
coaster[count].ratings=0;
coaster[count].thrill=0;
coaster[count].height=0;
coaster[count].scary=0;
count++;
}
void addRating(RollerCoaster coaster[],int count)
{int i;
i=searchName(coaster,count,true);
if(i<0)
return;
coaster[i].height+=rate("height");
coaster[i].thrill+=rate("thrill");
coaster[i].scary+=rate("scary");
coaster[i].ratings++;
cout<<endl;
}
double rate(string mess)
{double r=-1;
while(r<0||r>10)
{cout<<"Enter rating for "<<mess<<" (0-10): ";
cin>>r;
if(r<0||r>10)
cout<<"invalid entry ";
}
return r;
}
void searchType(RollerCoaster coaster[],int count)
{int t=0,i,c=0;
while(t<1||t>2)
{cout<<"Enter coaster type to search ";
cout<<"1. wood ";
cout<<"2. steel ";
cin>>t;
if(t<1||t>2)
cout<<"invalid type ";
}
for(i=0;i<count;i++)
if(coaster[i].type==t)
{display(coaster[i],false);
c++;
}
if(c==0)
cout<<"There are no coasters of that type ";
}
void display(RollerCoaster r,bool all)
{cout<<"Coaster: "<<r.name<<endl;
cout<<"Park: "<<r.park<<endl;
cout<<"Location: "<<r.city<<", "<<r.state<<endl;
cout<<"Peak Height: "<<r.peak<<" feet ";
if(!all)
{cout<<endl;
return;
}
cout<<"Ratings: "<<r.ratings<<endl;
cout<<"Thrill: "<<r.thrill<<" Height: "<<r.height<<" Scariness: "<<r.scary<<endl<<endl;
}
int searchName(RollerCoaster coaster[],int count,bool search)
{int i,c=0;
string n;
cout<<"enter coaster name: ";
getline(cin,n);
for(i=0;i<count;i++)
if(n.compare(coaster[i].name)==0)
if(!search)
{display(coaster[i],false);
c++;
}
else
return i;
if(c==0)
cout<<"There are no coasters with that name ";
return -1;
}
void listAll(RollerCoaster coaster[],int count)
{int i;
for(i=0;i<count;i++)
display(coaster[i],false);
}
void searchRate(RollerCoaster coaster[],int count)
{int i,c=0;
double r1,r2,r3;
cout<<"Enter ratings to search for ";
r1=rate("height");
r2=rate("thrill");
r3=rate("scary");
for(i=0;i<count;i++)
if(coaster[i].height/coaster[i].ratings>r1&&
coaster[i].thrill/coaster[i].ratings>r2&&
coaster[i].scary/coaster[i].ratings>r3)
{display(coaster[i],true);
c++;
}
if(c==0)
cout<<"no coaster meet those ratings ";
}
void save(RollerCoaster coaster[],int count)
{ofstream out;
int i;
char filename[80];
cout<<"what is the name of the file you want to save to? ";
cin>>filename;
out.open(filename);
for(i=0;i<count;i++)
out<<coaster[i].name<<" "
<<coaster[i].park<<" "
<<coaster[i].city<<" "
<<coaster[i].state<<" "
<<coaster[i].peak<<" "
<<coaster[i].type<<" "
<<coaster[i].thrill<<" "
<<coaster[i].height<<" "
<<coaster[i].scary<<" "
<<coaster[i].ratings<<endl;
out.close();
}
void load(RollerCoaster coaster[],int& i)
{ifstream in;
i=0;
char filename[80];
cout<<"what is the name of the file you want to load from? ";
cin>>filename;
in.open(filename);
while(in.fail()) //is it ok?
{ cout<<"file did not open please check it ";
in.clear();
cout<<"what is the name of the file you want to load from? ";
cin>>filename;
in.open(filename);
}
getline(in,coaster[i].name);
while(in)
{
getline(in,coaster[i].park);
getline(in,coaster[i].city);
getline(in,coaster[i].state);
in>>coaster[i].peak;
in>>coaster[i].type;
in>> coaster[i].thrill;
in>>coaster[i].height;
in>>coaster[i].scary;
in>>coaster[i].ratings;
in.ignore(80,' ');
i++;
getline(in,coaster[i].name);
}
in.close();
}
bool check(bool e,string mess)
{if(!e)
{cout<<"there are no coasters in the database to "<<mess<<" ";
return false;
}
return true;
}
int menu(bool e,bool r)
{int n;
for(; ; )
{
cout<<"What would you like to do? ";
cout<<"1. Add Coaster ";
cout<<"2. Add Coaster Ratings (Overall Thrill, Hills, Scariness) ";
cout<<"3. Search for a Coaster by Type ";
cout<<"4. Search for a Coaster by Name ";
cout<<"5. Show a Listing of All Coasters ";
cout<<"6. Search for a Coaster by Rating ";
cout<<"7. Save Database to a file ";
cout<<"8. Load Database from a file ";
cout<<"9. Exit ";
cin>>n;
switch(n)
{case 1:
case 8:
case 9:
return n;
break;
case 7:
if(check(e,"save"))
return n;
break;
case 2:
if(check(e,"rate"))
return n;
break;
case 3:
case 4:
if(check(e,"search"))
return n;
break;
case 6:
if(check(r,"search"))
return n;
break;
case 5:
if(check(e,"list"))
return n;
break;
default:
cout<<"invalid entry ";
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.