| | |
How to write Problem analysis
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 8
Reputation:
Solved Threads: 0
0
#11 Nov 8th, 2009
•
•
•
•
Here's a basic code; that's using two bool arrays to determinate if the seat is taken and if the seat is for smokers;
^^It's just a simple test code; based upon a matrix array.C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; #define Row 2 #define Column 10 bool SeatTaken [Row][Column]; // Is a specific seat taken? bool SmokerSeat[Row][Column]; // Is a specific seat for smokers? void ClearSeatsTaken() { for (int n=0; n<Column; n++) for (int a=0; a<Row; a++) SeatTaken [a][n]=0; } void SetSmokerSeats() { for (int n=0; n<Column; n++) {for (int a=0; a<Row; a++) {SmokerSeat [a][n]=0;}} for (int n=0; n<Column/2; n++) {for (int a=0; a<Row; a++) {SmokerSeat [a][n]=1;}} } void TESTUNIT() { for (int n=0; n<Column; n++) {for (int a=0; a<Row; a++) {cout << SeatTaken [a][n] << " ";} cout << endl; } } void MISSING() { cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl; } void DedicateSeat(bool Smoker) { bool GlobalBreak=false; for (int n=0; n<Column; n++) { if (GlobalBreak==true){break;} for (int a=0; a<Row; a++) { if (GlobalBreak==true){break;} if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false)) { SeatTaken [a][n]=true; cout << "Seat" << a << " at " << n << " is now taken!" << endl; GlobalBreak=true; } } } if (GlobalBreak==false) { bool Interrested=false; cout << "ERROR! No "; if (Smoker){cout << "smoker";}else{cout << "non smoker";} cout << " seats avaiable!" << endl; cout << "Interrested in another apparture? [Yes=1][No=0]" << endl; cin >> Interrested; if (Interrested){MISSING();} } } bool YouASmoker() { int SmokerSeatNeeded=0; cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl; cin >> SmokerSeatNeeded; if (SmokerSeatNeeded==-1){return 1;} DedicateSeat(SmokerSeatNeeded); return 0; } int main() { ClearSeatsTaken(); SetSmokerSeats(); while (1){ if(YouASmoker()==1){break;} TESTUNIT();} return 0; }
Hope it will help in any way
#include <string>
using namespace std;
void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo);
void plane(int flight);
void planeOne(int seatAreaOne);
void planeTwo(int seatAreaTwo);
void ClearSeatsTaken();
void SetSmokerSeats();
void MISSING();
bool YouASmoker();
void TESTUNIT();
#define Row 1
#define Column 10
bool SeatTaken [Row][Column]; // Is a specific seat taken?
bool SmokerSeat[Row][Column]; // Is a specific seat for smokers?
int main()
{
string name;
string passport;
int flight;
int seatAreaOne;
int seatAreaTwo;
int n;
cout<<"WELCOME TO C++ AIRLINES."<<endl;
cout<<"Please enter your name:"<<endl;
getline(cin, name);
cout<<"Please enter your passport number:"<<endl;
cin>>passport;
cout<<"Name:"<<name<<endl;
cout<<"Passport number:"<<passport<<endl;
initialize(flight, seatAreaOne, seatAreaTwo);
plane(flight);
ClearSeatsTaken();
SetSmokerSeats();
while (1){
if(YouASmoker()==1){break;}
TESTUNIT();}
cout<<"Boardingpass slip"<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Pasport number:"<<passport<<endl;
cout<<"Your seat number:"<<n + 1<<endl;
return 0;
}
void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo)
{
flight = 0;
seatAreaOne = 0;
seatAreaTwo = 0;
}
void plane(int flight)
{
int seatAreaOne;
int seatAreaTwo;
seatAreaOne = 0;
seatAreaTwo = 0;
cout<<"For your information, our company provides only two flights per day."<<endl;
cout<<"Enter (1) for flight A101 OR (2) for flight A102."<<endl;
cin>>flight;
if (flight==1)
{
cout<<"A101"<<endl;
planeOne(seatAreaOne);
}
else
{
cout<<"A102"<<endl;
planeTwo(seatAreaTwo);
}
}
void planeOne(int seatAreaOne)
{
cout<<"There are two types of seating area provided in this flight:"<<endl;
bool YouASmoker();
}
void planeTwo(int seatAreaTwo)
{
cout<<"There are two types of seating area provided in this flight"<<endl;
cout<<"Please choose a type of seating area."<<endl;
bool YouASmoker();
}
void ClearSeatsTaken()
{
for (int n=0; n<Column; n++)
for (int a=0; a<Row; a++)
SeatTaken [a][n]=0;
}
void SetSmokerSeats()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=0;}}
for (int n=0; n<Column/2; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=1;}}
}
void TESTUNIT()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{cout << SeatTaken [a][n] << " ";}
cout << endl;
}
}
void MISSING()
{
cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl;
}
void DedicateSeat(bool Smoker)
{
bool GlobalBreak=false;
for (int n=0; n<Column; n++)
{
if (GlobalBreak==true){break;}
for (int a=0; a<Row; a++)
{
if (GlobalBreak==true){break;}
if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false))
{
SeatTaken [a][n]=true;
cout << "Seat" << a << " at " << n << " is now taken!" << endl;
GlobalBreak=true;
}
}
}
if (GlobalBreak==false)
{
bool Interrested=false;
cout << "ERROR! No ";
if (Smoker){cout << "smoker";}else{cout << "non smoker";}
cout << " seats avaiable!" << endl;
cout << "Interrested in another apparture? [Yes=1][No=0]" << endl;
cin >> Interrested;
if (Interrested){MISSING();}
}
}
bool YouASmoker()
{
int SmokerSeatNeeded=0;
cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl;
cin >> SmokerSeatNeeded;
if (SmokerSeatNeeded==-1){return 1;}
DedicateSeat(SmokerSeatNeeded);
return 0;
}
Thanks for yr helping ... tis is my 2nd draft ..if i want to print a boardingpass, do i need to do another function call ?
my boarding pass include list out name, passport number , and the seat number ...
0
#14 Nov 9th, 2009
•
•
•
•
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo); void plane(int flight); void planeOne(int seatAreaOne); void planeTwo(int seatAreaTwo); void ClearSeatsTaken(); void SetSmokerSeats(); void MISSING(); bool YouASmoker(); void TESTUNIT(); #define Row 1 #define Column 10 bool SeatTaken [Row][Column]; // Is a specific seat taken? bool SmokerSeat[Row][Column]; // Is a specific seat for smokers? int main() { string name; string passport; int flight; int seatAreaOne; int seatAreaTwo; int n; cout<<"WELCOME TO C++ AIRLINES."<<endl; cout<<"Please enter your name:"<<endl; getline(cin, name); cout<<"Please enter your passport number:"<<endl; cin>>passport; cout<<"Name:"<<name<<endl; cout<<"Passport number:"<<passport<<endl; initialize(flight, seatAreaOne, seatAreaTwo); plane(flight); ClearSeatsTaken(); SetSmokerSeats(); while (1){ if(YouASmoker()==1){break;} TESTUNIT();} cout<<"Boardingpass slip"<<endl; cout<<"Name:"<<name<<endl; cout<<"Pasport number:"<<passport<<endl; cout<<"Your seat number:"<<n + 1<<endl; return 0; } void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo) { flight = 0; seatAreaOne = 0; seatAreaTwo = 0; } void plane(int flight) { int seatAreaOne; int seatAreaTwo; seatAreaOne = 0; seatAreaTwo = 0; cout<<"For your information, our company provides only two flights per day."<<endl; cout<<"Enter (1) for flight A101 OR (2) for flight A102."<<endl; cin>>flight; if (flight==1) { cout<<"A101"<<endl; planeOne(seatAreaOne); } else { cout<<"A102"<<endl; planeTwo(seatAreaTwo); } } void planeOne(int seatAreaOne) { cout<<"There are two types of seating area provided in this flight:"<<endl; bool YouASmoker(); } void planeTwo(int seatAreaTwo) { cout<<"There are two types of seating area provided in this flight"<<endl; cout<<"Please choose a type of seating area."<<endl; bool YouASmoker(); } void ClearSeatsTaken() { for (int n=0; n<Column; n++) for (int a=0; a<Row; a++) SeatTaken [a][n]=0; } void SetSmokerSeats() { for (int n=0; n<Column; n++) {for (int a=0; a<Row; a++) {SmokerSeat [a][n]=0;}} for (int n=0; n<Column/2; n++) {for (int a=0; a<Row; a++) {SmokerSeat [a][n]=1;}} } void TESTUNIT() { for (int n=0; n<Column; n++) {for (int a=0; a<Row; a++) {cout << SeatTaken [a][n] << " ";} cout << endl; } } void MISSING() { cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl; } void DedicateSeat(bool Smoker) { bool GlobalBreak=false; for (int n=0; n<Column; n++) { if (GlobalBreak==true){break;} for (int a=0; a<Row; a++) { if (GlobalBreak==true){break;} if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false)) { SeatTaken [a][n]=true; cout << "Seat" << a << " at " << n << " is now taken!" << endl; GlobalBreak=true; } } } if (GlobalBreak==false) { bool Interrested=false; cout << "ERROR! No "; if (Smoker){cout << "smoker";}else{cout << "non smoker";} cout << " seats avaiable!" << endl; cout << "Interrested in another apparture? [Yes=1][No=0]" << endl; cin >> Interrested; if (Interrested){MISSING();} } } bool YouASmoker() { int SmokerSeatNeeded=0; cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl; cin >> SmokerSeatNeeded; if (SmokerSeatNeeded==-1){return 1;} DedicateSeat(SmokerSeatNeeded); return 0; }
Thanks for yr helping ... tis is my 2nd draft ..if i want to print a boardingpass, do i need to do another function call ?
my boarding pass include list out name, passport number , and the seat number ...
// Skeen
![]() |
Similar Threads
- Weird file.write problem. (Python)
- I have problem about Knapsack in ASM (Assembly)
- vb.net NEWBIE!! Triangle problem!! (VB.NET)
- pascal write problem (ASP.NET)
- CDRW Problem (USB Devices and other Peripherals)
- XP crashes on any dialup connection (wanarp.sys / tcpip.sys problem) (Windows NT / 2000 / XP)
- do while; if else? am I using the right code for the problem? (C++)
Other Threads in the C++ Forum
- Previous Thread: compiling problem with wxwidgets 2.9.0 and anjuta 2.26.1.0
- Next Thread: MySQL, C++ connection
| 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 display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib 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 return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





