#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
void inputdata();
void showdata();
void showdata2();
int SIZE=0;
struct chars
{
char route[100];
char shipname[100];
char captainname[100];
};
struct data
{
chars route[25];
chars shipname[25];
chars captainname[25];
float price1[25];
float price2[25];
int tickets1[25];
int tickets2[25];
int month[25];
}ship;
int main(void)
{
int input;
system("cls");
do
{
cout << "########################################################################\n";
cout << "# #\n";
cout << "# 1. Introduction of information about ships and cruises #\n";
cout << "# #\n";
cout << "# 2. Display of information about ships and cruises #\n";
cout << "# #\n";
cout << "# 3. Display of information about ship with the most tickets sold #\n";
cout << "# #\n";
cout << "# 4. Exit #\n";
cout << "# #\n";
cout << "########################################################################\n";
do
{
cout << "\n Make your choice: ";
cin >> input;
}
while(input<1 || input>4);
switch(input)
{
case 1:
inputdata();
break;
case 2:
showdata();
break;
case 3:
showdata2();
break;
}
}
while(input!=4);
}
void inputdata()
{
int i=0;
int counter=0;
ofstream datafile;
char again;
do
{
datafile.open("data.txt",ios::app);
datafile << "Ship: " << counter << endl;
cout << "Please input ship route: ";
cin.ignore();
cin.getline(ship.route[counter].route,100);
datafile << "Route: " << ship.route[counter].route << endl;
cout << "Please enter the name of the ship: ";
cin.getline(ship.shipname[counter].shipname,100);
datafile << "Name of ship: " << ship.shipname[counter].shipname << endl;
cout << "Please enter the name of the captain: ";
cin.getline(ship.captainname[counter].captainname,100);
datafile << "Name of captain: " << ship.captainname[counter].captainname << endl;
cout << "Ticket price first class: $";
cin >> ship.price1[counter];
datafile << "Price first class: $" << ship.price1[counter] << endl;
cout << "Ticket price second class: $";
cin >> ship.price2[counter];
datafile << "Price second class: $" << ship.price2[counter] << endl;
cout << "Tickets sold first class: ";
cin >> ship.tickets1[counter];
datafile << "Tickets sold first class: " << ship.tickets1[counter] << endl;
cout << "Tickets sold second class: ";
cin >> ship.tickets2[counter];
datafile << "Tickets sold second class: " << ship.tickets2[counter] << endl;
do
{
cout << "Enter month of journey (from 1 to 12): ";
cin >> ship.month[counter];
}while(1>ship.month[counter] || ship.month[counter]>12);
datafile << "Month: " << ship.month[counter] << endl;
datafile.close();
counter++;
cout << "Do you want to input data for another ship? (y/n): ";
cin >> again;
}while(counter<25 && (again!='n' && again!='N'));
SIZE=counter;
for(i;i<counter;i++)
{
cout << "\n\nRoute: " << ship.route[i].route << endl;
cout << "Name of ship: " << ship.shipname[i].shipname << endl;
cout << "Name of captain: " << ship.captainname[i].captainname << endl;
cout << "Price first class: $" << ship.price1[i] << endl;
cout << "Price second class: $" << ship.price2[i] << endl;
cout << "Tickets sold first class: " << ship.tickets1[i] << endl;
cout << "Tickets sold second class: " <<ship.tickets2[i] << endl;
cout << "Month of journey: " << ship.month[i] << endl;
}
system("pause");
system("cls");
}
void showdata()
{
if(SIZE==0)
{
cout << "First enter information about ships" << endl;
}
else
{
int i=0;
char name[100];
cout << "Information about ship: ";
cin.ignore();
cin.getline(name,100);
for(i;i<SIZE;i++)
{
if(strcmp(ship.shipname[i].shipname,name)==0)
{
cout << "\nRoute: " << ship.route[i].route << endl;
cout << "Name of ship: " << ship.shipname[i].shipname << endl;
cout << "Name of captain: " << ship.captainname[i].captainname << endl;
cout << "Price first class: $" << ship.price1[i] << endl;
cout << "Price second class: $" << ship.price2[i] << endl;
cout << "Tickets sold first class: " << ship.tickets1[i] << endl;
cout << "Tickets sold second class: " <<ship.tickets2[i] << endl;
cout << "Month of journey: " << ship.month[i] << endl << endl;
}
}
}
system("pause");
system("cls");
}
void showdata2()
{
if(SIZE==0)
{
cout << "First enter information about ships" << endl;
}
else
{
float* temp1;
temp1 = new float[SIZE];
float* temp2;
temp2 = new float[SIZE];
float* temp3;
temp3 = new float[SIZE];
for(int i=0;i<SIZE;i++)
{
temp1[i] = ship.price1[i]*ship.tickets1[i];
temp2[i] = ship.price2[i]*ship.tickets2[i];
temp3[i] = temp1[i]+temp2[i];
}
/* TO DO */
/* TO DO */
/* TO DO */
/* TO DO */
/* TO DO */
/* TO DO */
/* TO DO */
}
system("pause");
system("cls");
}