ARRAY IN ARRAY problem

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 2346 Views - Last Post: 12 June 2013 - 01:41 AM Rate Topic: -----

#16 1helloworld1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 11-May 13

Re: ARRAY IN ARRAY problem

Posted 08 June 2013 - 11:37 AM

Quote

You can't enter only 4 rows but allow 6 columns.

thanks, I will fixed it.
Was This Post Helpful? 0
  • +
  • -

#17 1helloworld1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 11-May 13

Re: ARRAY IN ARRAY problem

Posted 08 June 2013 - 09:09 PM

Quote

using the int 1,2,0,0 where 1 is an adult, 2 is a child and 0 is empty.


But at the end of the result all the taken seat must be int 1 in the array table
Was This Post Helpful? 0
  • +
  • -

#18 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: ARRAY IN ARRAY problem

Posted 08 June 2013 - 09:27 PM

Why must it be 1 in the array table? Is it because the rest of your code assumes that it must be 1 and you don't want to re-write it? Take a step back and consider this: What if instead of expecting an occupied seat having a value of 1 instead reverse things: expect an empty seat to have a value of 0, and any other value indicates an occupied seat.

Even better, let the element in the array simply be the value paid for the seat: 20 for an adult, and 10 for a child. That way you simply need to sum up the rows and don't even need to do any mapping from type of consumer to what the expected income is. (Of course, the down side of using the price paid to hold a seat is figuring out how to deal with seats which are given free.)
Was This Post Helpful? 0
  • +
  • -

#19 1helloworld1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 11-May 13

Re: ARRAY IN ARRAY problem

Posted 08 June 2013 - 11:34 PM

because the assignment instruction say so must assign 1 as occupied seat. :surrender:

Quote

Even better, let the element in the array simply be the value paid for the seat: 20 for an adult, and 10 for a child.


then how about the seat ID, the seat ID need to store in array also.
Was This Post Helpful? 0
  • +
  • -

#20 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: ARRAY IN ARRAY problem

Posted 09 June 2013 - 12:00 AM

The requirement that only 1 be used to mark a seat would have been useful information that you could have given us earlier.

If you can only store a 1 in the array, then how do you expect to store a seat ID in the array? You could derive the seat id based on the row and column, but your teacher is contradicting himself if he want you to only store 1 in the array, but somehow be able to distinguish between adult or child, as well as hold the seat ID.

I suggest that you post the assignment's description exactly as given to you by your teacher (as opposed to how you interpreted it). We maybe able to guide you better.

This post has been edited by Skydiver: 09 June 2013 - 12:04 AM

Was This Post Helpful? 0
  • +
  • -

#21 1helloworld1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 11-May 13

Re: ARRAY IN ARRAY problem

Posted 09 June 2013 - 12:44 AM

The Seating Plan in the train is to be represented by a two dimensional array (ie. 4 X 6 for the above plan), where each element is either 0 (for seat available) or 1 (sold/unavailable). There are 1 aisle (lanes for walking) down the centre of the rows and columns – they are not represented in the array. Each seat number is being represented by the format [Row][Column], e.g. Seat No. B03.

The ticket information is to be stored in a structure variable. (You are encouraged to use a nested structure). The train details will be keyed in (once only) by the ticket clerk when the ticket is open for sale.

When a ticket is sold, the appropriate array element is updated and the ticket is displayed on the screen. A customer can buy more than 1 seat; the program will calculate the total amount of the fares to be paid.
Before and after every customer’s buying process, the program will display the updated Seat Occupancy. This shows the plan of the seats together with their availability. The total number of available seats on each row is also indicated at the end of the row.
The seat number is chosen by the customer. The total charge and ticket are automatically displayed.

The ticketing process can be closed in 2 possible ways - When there are no more customers (the clerk will respond with -1 to “How many seats required”), or when Total Seats Available is 0 (the program will show an appropriate message).

When the ticketing for the coach finally closes, the program displays a report called the Total Sales - by Seat Layout. This is similar to the Seat Occupancy except that the sales amount (in RM) is indicated at the end of each row and column. It starts with the show details and ends with the grand total of Sales for the show.
Was This Post Helpful? 0
  • +
  • -

#22 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: ARRAY IN ARRAY problem

Posted 09 June 2013 - 06:08 AM

Please post your current code, inside code tags without line numbers.

Jim
Was This Post Helpful? 0
  • +
  • -

#23 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: ARRAY IN ARRAY problem

Posted 09 June 2013 - 01:21 PM

View Post1helloworld1, on 09 June 2013 - 08:44 AM, said:

Each seat number is being represented by the format [Row][Column], e.g. Seat No. B03.


The Seat No. eg. B03 cannot be used directly with the array. So functions to convert seat numbers to and from row and column numbers would be useful.
Was This Post Helpful? 0
  • +
  • -

#24 1helloworld1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 11-May 13

Re: ARRAY IN ARRAY problem

Posted 12 June 2013 - 01:41 AM

#include <iostream>
#include <iomanip> 
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;

int Superior[4][6]={0};
int Economy[6][8]={0};
const int srow= 4 , scol= 6;
const int erow= 6 , ecol= 8;
const double sadult = 45.00 , schild = 22.50 ;
const double eadult = 25.00 , echild = 12.00 ;
void printSuperior(int Superior[4][6]);

	string Superior_seats[srow][scol] = {
   {"A01", "A02", "A03", "A04", "A05", "A06"},
   {"B01", "B02", "B03", "B04", "B05", "B06"},
   {"C01", "C02", "C03", "C04", "C05", "C06"},
   {"D01", "D02", "D03", "D04", "D05", "D06"}
};

	string Economy_seats[erow][ecol] = {
   {"A01", "A02", "A03", "A04", "A05", "A06","A07","A08"},
   {"B01", "B02", "B03", "B04", "B05", "B06","B07","B08"},
   {"C01", "C02", "C03", "C04", "C05", "C06","C07","C08"},
   {"D01", "D02", "D03", "D04", "D05", "D06","D07","D08"},
   {"E01", "E02", "E03", "E04", "E05", "E06","E07","E08"},
   {"F01", "F02", "F03", "F04", "F05", "F06","F07","F08"},
};

	string error="";

struct Sbooking
{
	string s_seat;
	string s_age;
	double price;
};

struct Ebooking
{
	string e_seat;
	string e_age;
	double price;
};

Sbooking s[srow][scol];
Ebooking e[erow][ecol];

void initialize_S (Sbooking s[srow][scol])
{
	for(int i=0;i<srow;i++)
	{
		for(int j=0;j<scol;j++)
		{
			s[i][j].s_seat="";
			s[i][j].s_age="";
			s[i][j].price=0;
		}
	}
}

void initialize_E (Ebooking e[erow][ecol])
{
	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			e[i][j].e_seat="";
			e[i][j].e_age="";
			e[i][j].price=0;
		}
	}
}

bool verify_selection (char ch)
{
	error="";

	if(ch !='S' && ch !='E')
	{
		error="Invalid choice re-enter again";
		return false;
	}

		return true;
}

int selection(char &ch)
{
	do
	{	
		if (error !="")
		{
			cout<<endl;
			cout<<error<<endl;
		}
		cout<<"Please select Superior('S') or Economy('E') : ";cin>>ch;
		ch=toupper(ch);
	}
	while(!verify_selection(ch));

	return ch;
}

void printSuperior(int Superior[4][6]) //print superior table
{
	unsigned char a1 = static_cast<char>(218);
	unsigned char a2 = static_cast<char>(179);
	unsigned char a3 = static_cast<char>(196);
	unsigned char a4 = static_cast<char>(191);
	unsigned char a5 = static_cast<char>(194);
	unsigned char a6 = static_cast<char>(197);
	unsigned char a7 = static_cast<char>(195);
	unsigned char a8 = static_cast<char>(180);
	unsigned char a9 = static_cast<char>(192);
	unsigned char a10 = static_cast<char>(193);
	unsigned char a11 = static_cast<char>(217);

	char ascii='A';

	cout<<endl;

		for(int num=1;num<7;num++)//display top number line
		{
			cout<<"   "<<"0"<<num; 
		}
			cout<<endl;
			cout<<"  "<<a1;
		for(int top=0;top<5;top++)//display top straight line cover
		{
			cout<<a3<<a3<<a3<<a3<<a5;}
			cout<<a3<<a3<<a3<<a3<<a4<<endl;
		
		for(int i=0;i<4;i++){
				cout<<ascii++<<" "<<a2;
		for(int j=0;j<6;j++){
				cout<<" "<<Superior[i][j]<<"  "<<a2;
			}
		if(i==3)
			goto stop;
		cout<<endl;	
		cout<<"  "<<a7;
		
		if(i==0){
		for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a6;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==1){
			for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a10;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				cout<<"  "<<a2<<"           aisles            "<<a2<<endl;
				cout<<"  "<<a7;
		
				for(int j=0;j<5;j++){
					cout<<a3<<a3<<a3<<a3<<a5;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==2){
		for(int j=0;j<5;j++){
			cout<<a3<<a3<<a3<<a3<<a6;
		}
		cout<<a3<<a3<<a3<<a3<<a8<<endl;}
		
	}	
		stop:
		{
			cout<<endl;
			cout<<"  "<<a9;
			for(int j=0;j<5;j++)
				cout<<a3<<a3<<a3<<a3<<a10;
				cout<<a3<<a3<<a3<<a3<<a11<<endl;
		}
}

void printEconomy(int Economy[6][8]) //print economy table
{
	unsigned char a1 = static_cast<char>(218);
	unsigned char a2 = static_cast<char>(179);
	unsigned char a3 = static_cast<char>(196);
	unsigned char a4 = static_cast<char>(191);
	unsigned char a5 = static_cast<char>(194);
	unsigned char a6 = static_cast<char>(197);
	unsigned char a7 = static_cast<char>(195);
	unsigned char a8 = static_cast<char>(180);
	unsigned char a9 = static_cast<char>(192);
	unsigned char a10 = static_cast<char>(193);
	unsigned char a11 = static_cast<char>(217);

	char ascii='A';

	cout<<endl;

		for(int num=1;num<9;num++)//display top number line
		{
			cout<<"   "<<"0"<<num; 
		}
			cout<<endl;
			cout<<"  "<<a1;
		for(int top=0;top<7;top++)//display top straight line cover
		{
			cout<<a3<<a3<<a3<<a3<<a5;}
			cout<<a3<<a3<<a3<<a3<<a4<<endl;
		
		for(int i=0;i<6;i++)
		{
				cout<<ascii++<<" "<<a2;
		for(int j=0;j<8;j++)
		{
				cout<<" "<<Economy[i][j]<<"  "<<a2;
		}
		if(i==5)
			goto stop;
		cout<<endl;	
		cout<<"  "<<a7;
		
		if(i==0){
		for(int i=0;i<7;i++){
				cout<<a3<<a3<<a3<<a3<<a6;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==1){
		for(int i=0;i<7;i++){
				cout<<a3<<a3<<a3<<a3<<a6;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}

		if(i==2){
			for(int i=0;i<7;i++){
				cout<<a3<<a3<<a3<<a3<<a10;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				cout<<"  "<<a2<<"                aisles                 "<<a2<<endl;
				cout<<"  "<<a7;
		
				for(int j=0;j<7;j++){
					cout<<a3<<a3<<a3<<a3<<a5;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==3){
		for(int j=0;j<7;j++){
			cout<<a3<<a3<<a3<<a3<<a6;
		}
		cout<<a3<<a3<<a3<<a3<<a8<<endl;}
		if(i==4){
		for(int j=0;j<7;j++){
			cout<<a3<<a3<<a3<<a3<<a6;
		}
		cout<<a3<<a3<<a3<<a3<<a8<<endl;}
	}	
		stop:
		{
			cout<<endl;
			cout<<"  "<<a9;
			for(int j=0;j<7;j++)
				cout<<a3<<a3<<a3<<a3<<a10;
				cout<<a3<<a3<<a3<<a3<<a11<<endl;
		}
}

bool verify_seat_require(int seat_require)
{
	bool valid = false;
	error="";
	if(seat_require <=(srow*scol) && seat_require >= -1)
	{
		return true;
	}
	
	else 
	{
		error="Invalid seat requirement.";
		return false;
	}

		return true;
}

int superior_seatrequire()
{
	int seat_require=0;

	do
	{
		if(error!="")

			cout<<error<<endl;
		
		cout<<"How many seat you required: ";cin>>seat_require;
	}
	while(!verify_seat_require(seat_require));

	return seat_require;

}

bool verify_seat_require1(int seat_require1)
{
	error="";

	if(seat_require1 <=(erow*ecol) && seat_require1 >= -1)
	{
		return true;
	}
	else
	{
		error="Invalid seat requirement.";
		return false;
	}

}

int economy_seatrequire()
{
	int seat_require1=0;

	do
	{
		error!="";
		cout<<error<<endl;

		cout<<"How many seat you required: ";cin>>seat_require1;
	}
	while(!verify_seat_require1(seat_require1));

	return seat_require1;

}

bool verify_Superiorage(const string &ages)
{
	error="";

	if(ages != "A" && ages != "C")
	{
		error="Invalid age Please re-enter again.";
		return false;
	}

		return true;
}

void get_Superiorage(Sbooking s[srow][scol],const string &seats)
{
	string ages="";

	do
	{
		if(error!="")
			cout<<error<<endl;

		cout<<"Enter  Adult('A')/Child('C') : ";cin>>ages;
		transform(ages.begin(),ages.end(),ages.begin(),toupper);
		cout<<endl;
	}
	while(!verify_Superiorage(ages));

	for(int i=0 ; i<srow ; i++)
	{
		for(int j=0 ; j<scol ; j++)
		{
			if(Superior_seats[i][j] == seats)
			{
				s[i][j].s_age=ages;
				
				if(s[i][j].s_age == "A")
				{
					s[i][j].price=sadult;
				}

				else if(s[i][j].s_age == "C")
				{
					s[i][j].price=schild;
				}
			}
		}
	}
}

bool verify_Superiorseat(Sbooking s[srow][scol],const string &seats)
{
	bool valid = false;
	error="";

	for(int i= 0 ; i<srow ; i++)
	{
		for(int j= 0 ; j<scol ; j++)
		{
			if(Superior_seats[i][j] == seats)
			{
				if(s[i][j].s_seat == "")
				{
					s[i][j].s_seat = Superior_seats[i][j];
					Superior[i][j] =1;

					valid = true;
				}
				else 
				{
					error="This seat has been taken";
					return false;
				}
			}
		}
	}

	if(!valid)
	{
		error="Invalid seat ID please re-enter again.";
		return false;
	}

	return true;
}

string get_Superiorseat(Sbooking s[srow][scol],int &seat_require)
{
	string seats;

	for(int i=0 ; i<seat_require ; i++)
	{
	do
	{
		if(error!="")
			cout<<error<<endl;
			error="";

		cout<<"Please select your seat ID: ";cin>>seats;
		cout<<endl;
	}
	while(!verify_Superiorseat(s,seats));
		get_Superiorage(s,seats);

	}

	return seats;
}

bool verify_Economyage(const string &ages1)
{
	error="";

	if(ages1 != "A" && ages1 != "C")
	{
		error="Invalid age Please re-enter again.";
		return false;
	}

		return true;
}

void get_Economyage(Ebooking e[erow][ecol],const string &seats1)
{
	string ages1="";

	do
	{
		if(error!="")
		cout<<error<<endl;

		cout<<"Enter  Adult('A')/Child('C') : "; cin>>ages1;
		transform(ages1.begin() , ages1.end() , ages1.begin() , toupper);
		cout<<endl;

	}
	while(!verify_Economyage(ages1));

	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			if(Economy_seats[i][j] == seats1)
			{
				e[i][j].e_age = ages1;
				
				if(e[i][j].e_age == "A")
				{
					e[i][j].price = eadult;
				}

				else if(e[i][j].e_age == "C")
				{
					e[i][j].price = echild;
				}
			}
		}
	}
}

bool verify_Economyseat(Ebooking e[erow][ecol] , const string &seats1)
{
	bool valid = false;
	error="";

	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			if(Economy_seats[i][j] == seats1)
			{
				if(e[i][j].e_seat =="")
				{
					e[i][j].e_seat = Economy_seats[i][j];
					Economy[i][j] = 1;

					valid = true;
				}
				
				else
				{
					error="This seat has been taken";
					return false;
				}
			}
		}
	}

	if(!valid)
	{
		error="Invalid seat ID please re-enter again.";
		return false;
	}

	return true;
}
	
string get_Economyseat(Ebooking e[erow][ecol],int &seat_require1)
{
	string seats1;

	for(int i=0 ; i<seat_require1 ; i++)
	{
	do
	{
		if(error!="")
			cout<<error<<endl;
			error="";

		cout<<"Please select your seat ID: ";cin>>seats1;

	}
	while(!verify_Economyseat(e,seats1));

		get_Economyage(e,seats1);
	}

	return seats1;
}

void E_totalprice(Ebooking e[erow][ecol],const string &seats1)
{
	double total=0;
	double paid=0,change=0;

	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			if(e[i][j].e_seat == seats1)
			{
				if(e[i][j].e_seat != "")
				{
					total+=e[i][j].price;
				}
			}
		}
	}

	cout<<"Total Price   : RM"<<fixed<<setprecision(2)<<total<<endl;
	cout<<"Your Cash Pay : RM";cin>>paid;
	cout<<"Cash Paid     : RM"<<fixed<<setprecision(2)<<paid<<endl;
	change = paid - total;
	cout<<"Change        : RM"<<fixed<<setprecision(2)<<change<<endl;
	cout<<endl;

	if(total>0)
	{
		total=0;
	}
}

int E_AvailableSeat(Ebooking e[erow][ecol])
{
	int totalseat=0;

	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			if(e[i][j].e_seat =="")
			{
				totalseat++;
			}			
		}
	}

	return totalseat;
}

double E_Occupancyrate(Ebooking e[erow][ecol])
{
	double total=0;

	for(int i=0 ; i<erow ; i++)
	{
		for(int j=0 ; j<ecol ; j++)
		{
			if(e[i][j].e_seat !="")
			{
				total++;
			}
		}
	}

	return (total/(erow*ecol)*100.0);
}

void Occupancy_Etable(Ebooking e[erow][ecol],int Economy[6][8])
{
	unsigned char a1 = static_cast<char>(218);
	unsigned char a2 = static_cast<char>(179);
	unsigned char a3 = static_cast<char>(196);
	unsigned char a4 = static_cast<char>(191);
	unsigned char a5 = static_cast<char>(194);
	unsigned char a6 = static_cast<char>(197);
	unsigned char a7 = static_cast<char>(195);
	unsigned char a8 = static_cast<char>(180);
	unsigned char a9 = static_cast<char>(192);
	unsigned char a10 = static_cast<char>(193);
	unsigned char a11 = static_cast<char>(217);
	int trow=0;
	char ascii='A';

		cout<<"  Seat Occupancy"<<a3<<"Economy Class\n"<<endl;

			for(int num=1;num<9;num++)//display top number line
			{
				cout<<"   "<<"0"<<num; 
			}

				cout<<"             "<<"Seats Available"<<endl;
				cout<<endl;
				cout<<"  "<<a1;

					for(int top=0;top<7;top++)//display top straight line cover
					{
						cout<<a3<<a3<<a3<<a3<<a5;}
						cout<<a3<<a3<<a3<<a3<<a4<<endl;

							for(int i=0;i<erow;i++)
							{
								cout<<ascii++<<" "<<a2;
								
									for(int j=0;j<ecol;j++)
									{
										cout<<" "<<Economy[i][j]<<"  "<<a2;

										if(e[i][j].e_seat!="")
										{
											trow++;
										}

									}

								cout<<"                "<<erow-trow;
								trow=0;

			if(i==5)
			goto stop;
			cout<<endl;	
			cout<<"  "<<a7;
		
			if(i==0){
			for(int i=0;i<7;i++)
			{
				cout<<a3<<a3<<a3<<a3<<a6;
			}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
			}

			if(i==1){
			for(int i=0;i<7;i++)
			{
				cout<<a3<<a3<<a3<<a3<<a6;
			}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
			}

			if(i==2){ 
				for(int i=0;i<7;i++)
				{
					cout<<a3<<a3<<a3<<a3<<a10;
				}

					cout<<a3<<a3<<a3<<a3<<a8<<endl;
					cout<<"  "<<a2<<"                aisles                 "<<a2<<endl;
					cout<<"  "<<a7;
		
				for(int j=0;j<7;j++)
				{
					cout<<a3<<a3<<a3<<a3<<a5;
				}
					cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
					if(i==3){
						for(int j=0;j<7;j++)
						{
							cout<<a3<<a3<<a3<<a3<<a6;
						}
							cout<<a3<<a3<<a3<<a3<<a8<<endl;
						}

					if(i==4){
						for(int j=0;j<7;j++)
						{
							cout<<a3<<a3<<a3<<a3<<a6;
						}
							cout<<a3<<a3<<a3<<a3<<a8<<endl;
						}
						}	
		stop:
		{
				cout<<endl;
				cout<<"  "<<a9;

					for(int j=0;j<7;j++)
						cout<<a3<<a3<<a3<<a3<<a10;
						cout<<a3<<a3<<a3<<a3<<a11<<endl;
						cout<<endl;
						cout<<" Occupancy rate: "<<setprecision(2)<<E_Occupancyrate(e)<<"%"<<"                "<<"Total Seats Available: "
								<<E_AvailableSeat(e)<<endl;
		}
}

int S_AvailableSeat(Sbooking s[srow][scol])
{
	int totalseat=0;

	for(int i=0 ; i<srow ; i++)
	{
		for(int j=0 ; j<scol ; j++)
		{
			if(s[i][j].s_seat =="")
			{
				totalseat++;
			}			
		}
	}

	return totalseat;

}

double S_Occupancyrate(Sbooking s[srow][scol])
{
	double total=0;

	for(int i=0 ; i<srow ; i++)
	{
		for(int j=0 ; j<scol ; j++)
		{
			if(s[i][j].s_seat !="")
			{
				total++;
			}
		}
	}

	return (total/(srow*scol)*100.0);
}

void Occupancy_Stable(Sbooking s[srow][scol],int Superior[4][6])
{

	unsigned char a1 = static_cast<char>(218);
	unsigned char a2 = static_cast<char>(179);
	unsigned char a3 = static_cast<char>(196);
	unsigned char a4 = static_cast<char>(191);
	unsigned char a5 = static_cast<char>(194);
	unsigned char a6 = static_cast<char>(197);
	unsigned char a7 = static_cast<char>(195);
	unsigned char a8 = static_cast<char>(180);
	unsigned char a9 = static_cast<char>(192);
	unsigned char a10 = static_cast<char>(193);
	unsigned char a11 = static_cast<char>(217);
	int trow=0;
	double seatrate=0;
	char ascii='A';

		cout<<"  Seat Occupancy"<<a3<<"Superior Class\n";
		for(int num=1;num<7;num++)//display top number line
		{
			cout<<"   "<<"0"<<num; 
		}
			cout<<"             "<<"Seats Available"<<endl;
			cout<<"  "<<a1;
		for(int top=0;top<5;top++)//display top straight line cover
		{
			cout<<a3<<a3<<a3<<a3<<a5;}
			cout<<a3<<a3<<a3<<a3<<a4;
			cout<<"          "<<"---------------"<<endl;

		for(int i=0;i<srow;i++){
				cout<<ascii++<<" "<<a2;

		for(int j=0;j<scol;j++){
				
				cout<<" "<<Superior[i][j]<<"  "<<a2;

				if(s[i][j].s_seat !="")
				{
					trow++;
				}
		}
				cout<<"                "<<scol-trow;
				trow=0;

		if(i==3)
			goto stop;
		cout<<endl;	
		cout<<"  "<<a7;
		
		if(i==0){
		for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a6;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==1){
			for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a10;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				cout<<"  "<<a2<<"           aisles            "<<a2<<endl;
				cout<<"  "<<a7;
		
				for(int j=0;j<5;j++){
					cout<<a3<<a3<<a3<<a3<<a5;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==2){
		for(int j=0;j<5;j++){
			cout<<a3<<a3<<a3<<a3<<a6;
		}
		cout<<a3<<a3<<a3<<a3<<a8<<endl;}
		
	}	
		stop:
		{
			cout<<endl;
			cout<<"  "<<a9;
			for(int j=0;j<5;j++)
				cout<<a3<<a3<<a3<<a3<<a10;
				cout<<a3<<a3<<a3<<a3<<a11<<endl;
				cout<<endl;
				cout<<" Occupancy rate: "<<setprecision(2)<<S_Occupancyrate(s)<<"%"<<"      "<<"Total Seats Available: "<<S_AvailableSeat(s)<<endl;

		}

}

void S_totalprice(Sbooking s[srow][scol],const string &seats)
{
	double total=0;
	double paid=0,change=0;

	for(int i=0 ; i<srow ; i++)
	{
		for(int j=0 ; j<scol ; j++)
		{
			if(s[i][j].s_seat == seats)
				{
				total+= s[i][j].price;
				}
		}
	}

	cout<<"Total Price   : RM"<<fixed<<setprecision(2)<<total<<endl;
	cout<<"Your Cash Pay : RM";cin>>paid;
	cout<<"Cash Paid     : RM"<<fixed<<setprecision(2)<<paid<<endl;
	change = paid - total;
	cout<<"Change        : RM"<<fixed<<setprecision(2)<<change<<endl;	
	cout<<endl;
}

void S_report(Sbooking s[srow][scol],const string &seats, const string &ages)
{
	unsigned char a1 = static_cast<char>(218);
	unsigned char a2 = static_cast<char>(179);
	unsigned char a3 = static_cast<char>(196);
	unsigned char a4 = static_cast<char>(191);
	unsigned char a5 = static_cast<char>(194);
	unsigned char a6 = static_cast<char>(197);
	unsigned char a7 = static_cast<char>(195);
	unsigned char a8 = static_cast<char>(180);
	unsigned char a9 = static_cast<char>(192);
	unsigned char a10 = static_cast<char>(193);
	unsigned char a11 = static_cast<char>(217);
	double row_total=0,final_total=0;
	char ascii='A';

		cout<<endl;
		cout<<"    Total Sales - by Seat Layout           Superior Class\n";

		for(int num=1;num<7;num++)//display top number line
		{
			cout<<"   "<<"0"<<num; 
		}
			cout<<"                    SALES(RM)"<<endl;
			cout<<"  "<<a1;
		for(int top=0;top<5;top++)//display top straight line cover
		{
			cout<<a3<<a3<<a3<<a3<<a5;}
			cout<<a3<<a3<<a3<<a3<<a4;
			cout<<"          "<<"---------------"<<endl;

		for(int i=0;i<4;i++){
				cout<<ascii++<<" "<<a2;

		for(int j=0;j<6;j++)
		{				
			cout<<" "<<Superior[i][j]<<"  "<<a2;

			if(s[i][j].s_seat!="")
			{
				row_total+= s[i][j].price;
				final_total+= s[i][j].price;
			}
		}
				cout<<"                "<<row_total;
				row_total=0;

		if(i==3)
			goto stop;
			cout<<endl;	
			cout<<"  "<<a7;
	
		if(i==0){
		for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a6;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==1){
			for(int i=0;i<5;i++){
				cout<<a3<<a3<<a3<<a3<<a10;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				cout<<"  "<<a2<<"           aisles            "<<a2<<endl;
				cout<<"  "<<a7;
		
				for(int j=0;j<5;j++){
					cout<<a3<<a3<<a3<<a3<<a5;}
				cout<<a3<<a3<<a3<<a3<<a8<<endl;
				}
		if(i==2){
		for(int j=0;j<5;j++){
			cout<<a3<<a3<<a3<<a3<<a6;
		}
		cout<<a3<<a3<<a3<<a3<<a8<<endl;}
			
		stop:
		{
			cout<<endl;
			cout<<"  "<<a9;
			for(int j=0;j<5;j++)
				cout<<a3<<a3<<a3<<a3<<a10;
				cout<<a3<<a3<<a3<<a3<<a11<<endl;
				cout<<endl;
				cout<<" Total Sales(RM): "<<"      "<<"Total Sales: RM"<<final_total<<endl;

		}

	}
}
int main()
{	
	char ch=0;
	int seat_require=0 , seat_require1=0 ;
	Sbooking s[srow][scol]; Ebooking e[erow][ecol];
	initialize_S (s); initialize_E (e);

	while(seat_require !=1)
	{
		ch = selection(ch);

		if(ch =='S')
		{
			seat_require = superior_seatrequire();
			printSuperior(Superior);
			string seats = get_Superiorseat(s,seat_require);
			S_totalprice(s,seats);
			Occupancy_Stable(s,Superior);
		}

		if(ch =='E')
		{
			printEconomy(Economy);
			seat_require1 = economy_seatrequire();
			string seats1 = get_Economyseat(e,seat_require1);
			E_totalprice(e,seats1);
			Occupancy_Etable(e,Economy);
		}
	}


	system("pause");
}



Now the problem is when superior_seatrequire()(Let's say seatrequire =2) function get the input then call user enter Seat ID and Age.
When enter 2 Seat ID = A01 and A02 , age = A and C. but the total amount to pay is 45 suppose is 67.50 .
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2