| | |
Arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 5
Reputation:
Solved Threads: 0
ok my teacher wants me to write a program using these instructions :
A small airline has just purshased a computer for its new automated reserations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu alternatives--Please type 1 for "First Class" and PLease type 2 for "Economy". If the persons types 1, YOur program should assign a seat in the first class section (seat 1-5). If the person types 2, Your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use one-dimensional array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, Your program should ask the person if it is acceptable to be placed in the economy section(and viceversa). If yes, then make the appropiate seat assignment. If no, the print the message "Next flight leaes in 3 hours".
this is what i have so far and i need to know what can i do assign each section a seat, but individually, i don't want it to print all together, i just want to ask do yo want first class or economy depending on the answer i assign the corresponding seat can someone help me pleaseee what is im doing wrong
//Airplane Reservation System
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
int main()
{
int firstClass = 0;//first class section
int economy = 0;//economy section
int sections= 0;//to choose the section of the seats
int total = 0;
int sectionsCounter = 0;
//use an array for the capacity of 10 seats
int seats[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
//Menu Alternatives
cout<<"Please type 1 for ""First Class"":"<<"\n"<<endl;
cout<<"Please type 2 for ""Economy"":"<<endl;
cin>>sections;
//use an if statement to assign a seat in first class
if ( sections == 1)
{
sections = 1;
cout<<"First Class"<<setw (13)<<"Seats"<<endl;
for ( int i = 0; i <= 4; i++)
cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl;
}//end of if
//use a if statement to assign a seat in economy section
else
if ( sections == 2)
{
sections = 1;
cout<<"Economy"<<setw (13)<<"Seats"<<endl;
for ( int i = 5; i < 10; i++)
cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl;
}//end of if
system("pause");
return 0;
}//end of main
A small airline has just purshased a computer for its new automated reserations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu alternatives--Please type 1 for "First Class" and PLease type 2 for "Economy". If the persons types 1, YOur program should assign a seat in the first class section (seat 1-5). If the person types 2, Your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use one-dimensional array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, Your program should ask the person if it is acceptable to be placed in the economy section(and viceversa). If yes, then make the appropiate seat assignment. If no, the print the message "Next flight leaes in 3 hours".
this is what i have so far and i need to know what can i do assign each section a seat, but individually, i don't want it to print all together, i just want to ask do yo want first class or economy depending on the answer i assign the corresponding seat can someone help me pleaseee what is im doing wrong
//Airplane Reservation System
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
int main()
{
int firstClass = 0;//first class section
int economy = 0;//economy section
int sections= 0;//to choose the section of the seats
int total = 0;
int sectionsCounter = 0;
//use an array for the capacity of 10 seats
int seats[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
//Menu Alternatives
cout<<"Please type 1 for ""First Class"":"<<"\n"<<endl;
cout<<"Please type 2 for ""Economy"":"<<endl;
cin>>sections;
//use an if statement to assign a seat in first class
if ( sections == 1)
{
sections = 1;
cout<<"First Class"<<setw (13)<<"Seats"<<endl;
for ( int i = 0; i <= 4; i++)
cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl;
}//end of if
//use a if statement to assign a seat in economy section
else
if ( sections == 2)
{
sections = 1;
cout<<"Economy"<<setw (13)<<"Seats"<<endl;
for ( int i = 5; i < 10; i++)
cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl;
}//end of if
system("pause");
return 0;
}//end of main
•
•
Join Date: Jul 2005
Posts: 1,707
Reputation:
Solved Threads: 275
You mean something like this:
C++ Syntax (Toggle Plain Text)
if ( sections == 1) //first class reqeusted { if(firstClass < 4)//implies there's only 4 first class seats available on this flight ++firstClass; //assign a seat in first class }
•
•
Join Date: Sep 2007
Posts: 5
Reputation:
Solved Threads: 0
no, what i mean is that the program should print First Class or Economy 0 until the user inputs the number of section, and when the user choose wich section they want, the program should assign a seat for each section, if it is first class it has to be in the seats from 1-5 and if it is economy it has to be in the seats from 6-10
•
•
Join Date: Oct 2007
Posts: 49
Reputation:
Solved Threads: 1
If you want it to print out 0's then set the array to 0's
with this you're setting each array with it's respective number.
also as a heads up if you're looking for this to loop until all the seats are full you need to set a lop before the menu starts to go back to the menu once the user is done making his selections.
with this you're only printing out the numbers between seats[0] to seats[4]. first thing first take out the sections = 1; its doing nothing. Then find a way to change seats[] to the value 1 once they selected either 1 or 2 for their seating. I would do something like
int i =0;
while (i < 4 && seats[i] ==1)
i++;
seats[i] = 1;
Hope this helps out.
C++ Syntax (Toggle Plain Text)
int seats[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
also as a heads up if you're looking for this to loop until all the seats are full you need to set a lop before the menu starts to go back to the menu once the user is done making his selections.
C++ Syntax (Toggle Plain Text)
//use an if statement to assign a seat in first class if ( sections == 1) { sections = 1; cout<<"First Class"<<setw (13)<<"Seats"<<endl; for ( int i = 0; i <= 4; i++) cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl; }//end of if
with this you're only printing out the numbers between seats[0] to seats[4]. first thing first take out the sections = 1; its doing nothing. Then find a way to change seats[] to the value 1 once they selected either 1 or 2 for their seating. I would do something like
int i =0;
while (i < 4 && seats[i] ==1)
i++;
seats[i] = 1;
Hope this helps out.
•
•
Join Date: Jul 2005
Posts: 1,707
Reputation:
Solved Threads: 275
Use firstClass and and economy to calculate indexes into the array of seats which represent the first available seat in each section. Here's something that might guide you.
C++ Syntax (Toggle Plain Text)
if(sections == 1) //customer wants first class { if(firstClass < 5)/*there's only 5 seats in first class, they are seats[0], seats[1], seats[2], seats[3], and seats[4]*/ cout << "you will be assigned seat " << seats[firstClass]; /*now there's one less seat class in first class so increment firstClass so you don't give the seat out twice*/ ++firstClass; } if(sections == 2) //they want economy. /*the first open seat in economy will be at index i == 5 + economy. You can write the code notifying the customer what seat they were assigned and keeping track of the next available seat in economy */
Last edited by Lerner; Nov 12th, 2007 at 2:58 pm.
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: random number generation
- Next Thread: C++ - possible c_str problem???
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






