How to write Problem analysis

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 8
Reputation: xueyingkoo is an unknown quantity at this point 
Solved Threads: 0
xueyingkoo xueyingkoo is offline Offline
Newbie Poster
 
0
  #11
26 Days Ago
Originally Posted by Skeen View Post
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;
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define Row 2
  6. #define Column 10
  7. bool SeatTaken [Row][Column]; // Is a specific seat taken?
  8. bool SmokerSeat[Row][Column]; // Is a specific seat for smokers?
  9.  
  10. void ClearSeatsTaken()
  11. {
  12. for (int n=0; n<Column; n++)
  13. for (int a=0; a<Row; a++)
  14. SeatTaken [a][n]=0;
  15. }
  16.  
  17. void SetSmokerSeats()
  18. {
  19. for (int n=0; n<Column; n++)
  20. {for (int a=0; a<Row; a++)
  21. {SmokerSeat [a][n]=0;}}
  22. for (int n=0; n<Column/2; n++)
  23. {for (int a=0; a<Row; a++)
  24. {SmokerSeat [a][n]=1;}}
  25. }
  26.  
  27. void TESTUNIT()
  28. {
  29. for (int n=0; n<Column; n++)
  30. {for (int a=0; a<Row; a++)
  31. {cout << SeatTaken [a][n] << " ";}
  32. cout << endl;
  33. }
  34. }
  35.  
  36. void MISSING()
  37. {
  38. cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl;
  39. }
  40.  
  41. void DedicateSeat(bool Smoker)
  42. {
  43. bool GlobalBreak=false;
  44. for (int n=0; n<Column; n++)
  45. {
  46. if (GlobalBreak==true){break;}
  47. for (int a=0; a<Row; a++)
  48. {
  49. if (GlobalBreak==true){break;}
  50. if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false))
  51. {
  52. SeatTaken [a][n]=true;
  53. cout << "Seat" << a << " at " << n << " is now taken!" << endl;
  54. GlobalBreak=true;
  55. }
  56. }
  57. }
  58. if (GlobalBreak==false)
  59. {
  60. bool Interrested=false;
  61. cout << "ERROR! No ";
  62. if (Smoker){cout << "smoker";}else{cout << "non smoker";}
  63. cout << " seats avaiable!" << endl;
  64. cout << "Interrested in another apparture? [Yes=1][No=0]" << endl;
  65. cin >> Interrested;
  66. if (Interrested){MISSING();}
  67. }
  68. }
  69.  
  70. bool YouASmoker()
  71. {
  72. int SmokerSeatNeeded=0;
  73. cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl;
  74. cin >> SmokerSeatNeeded;
  75. if (SmokerSeatNeeded==-1){return 1;}
  76. DedicateSeat(SmokerSeatNeeded);
  77. return 0;
  78. }
  79.  
  80. int main()
  81. {
  82. ClearSeatsTaken();
  83. SetSmokerSeats();
  84. while (1){
  85. if(YouASmoker()==1){break;}
  86. TESTUNIT();}
  87. return 0;
  88. }
^^It's just a simple test code; based upon a matrix array.
Hope it will help in any way
#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 ...
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: MOSWEU is an unknown quantity at this point 
Solved Threads: 0
MOSWEU MOSWEU is offline Offline
Newbie Poster
 
0
  #12
25 Days Ago
i m in trouble ladies and gentlemen agent help needed
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 8
Reputation: xueyingkoo is an unknown quantity at this point 
Solved Threads: 0
xueyingkoo xueyingkoo is offline Offline
Newbie Poster
 
0
  #13
25 Days Ago
Originally Posted by MOSWEU View Post
i m in trouble ladies and gentlemen agent help needed

is that you have same prob with me ?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training
 
0
  #14
25 Days Ago
Originally Posted by xueyingkoo View Post
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo);
  6. void plane(int flight);
  7. void planeOne(int seatAreaOne);
  8. void planeTwo(int seatAreaTwo);
  9. void ClearSeatsTaken();
  10. void SetSmokerSeats();
  11. void MISSING();
  12. bool YouASmoker();
  13. void TESTUNIT();
  14.  
  15.  
  16. #define Row 1
  17. #define Column 10
  18. bool SeatTaken [Row][Column]; // Is a specific seat taken?
  19. bool SmokerSeat[Row][Column]; // Is a specific seat for smokers?
  20.  
  21.  
  22. int main()
  23. {
  24. string name;
  25. string passport;
  26. int flight;
  27. int seatAreaOne;
  28. int seatAreaTwo;
  29. int n;
  30.  
  31. cout<<"WELCOME TO C++ AIRLINES."<<endl;
  32. cout<<"Please enter your name:"<<endl;
  33. getline(cin, name);
  34. cout<<"Please enter your passport number:"<<endl;
  35. cin>>passport;
  36. cout<<"Name:"<<name<<endl;
  37. cout<<"Passport number:"<<passport<<endl;
  38.  
  39. initialize(flight, seatAreaOne, seatAreaTwo);
  40. plane(flight);
  41. ClearSeatsTaken();
  42. SetSmokerSeats();
  43. while (1){
  44. if(YouASmoker()==1){break;}
  45. TESTUNIT();}
  46.  
  47. cout<<"Boardingpass slip"<<endl;
  48. cout<<"Name:"<<name<<endl;
  49. cout<<"Pasport number:"<<passport<<endl;
  50. cout<<"Your seat number:"<<n + 1<<endl;
  51.  
  52.  
  53. return 0;
  54.  
  55. }
  56. void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo)
  57. {
  58. flight = 0;
  59. seatAreaOne = 0;
  60. seatAreaTwo = 0;
  61.  
  62. }
  63.  
  64. void plane(int flight)
  65. {
  66. int seatAreaOne;
  67. int seatAreaTwo;
  68. seatAreaOne = 0;
  69. seatAreaTwo = 0;
  70.  
  71. cout<<"For your information, our company provides only two flights per day."<<endl;
  72. cout<<"Enter (1) for flight A101 OR (2) for flight A102."<<endl;
  73. cin>>flight;
  74.  
  75. if (flight==1)
  76. {
  77. cout<<"A101"<<endl;
  78. planeOne(seatAreaOne);
  79. }
  80. else
  81. {
  82. cout<<"A102"<<endl;
  83. planeTwo(seatAreaTwo);
  84. }
  85.  
  86. }
  87. void planeOne(int seatAreaOne)
  88. {
  89.  
  90. cout<<"There are two types of seating area provided in this flight:"<<endl;
  91. bool YouASmoker();
  92. }
  93. void planeTwo(int seatAreaTwo)
  94. {
  95.  
  96. cout<<"There are two types of seating area provided in this flight"<<endl;
  97. cout<<"Please choose a type of seating area."<<endl;
  98. bool YouASmoker();
  99.  
  100. }
  101.  
  102. void ClearSeatsTaken()
  103. {
  104. for (int n=0; n<Column; n++)
  105. for (int a=0; a<Row; a++)
  106. SeatTaken [a][n]=0;
  107. }
  108.  
  109. void SetSmokerSeats()
  110. {
  111. for (int n=0; n<Column; n++)
  112. {for (int a=0; a<Row; a++)
  113. {SmokerSeat [a][n]=0;}}
  114. for (int n=0; n<Column/2; n++)
  115. {for (int a=0; a<Row; a++)
  116. {SmokerSeat [a][n]=1;}}
  117. }
  118.  
  119. void TESTUNIT()
  120. {
  121. for (int n=0; n<Column; n++)
  122. {for (int a=0; a<Row; a++)
  123. {cout << SeatTaken [a][n] << " ";}
  124. cout << endl;
  125. }
  126. }
  127.  
  128. void MISSING()
  129. {
  130. cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl;
  131. }
  132.  
  133. void DedicateSeat(bool Smoker)
  134. {
  135. bool GlobalBreak=false;
  136. for (int n=0; n<Column; n++)
  137. {
  138. if (GlobalBreak==true){break;}
  139. for (int a=0; a<Row; a++)
  140. {
  141. if (GlobalBreak==true){break;}
  142. if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false))
  143. {
  144.  
  145.  
  146. SeatTaken [a][n]=true;
  147. cout << "Seat" << a << " at " << n << " is now taken!" << endl;
  148.  
  149. GlobalBreak=true;
  150. }
  151. }
  152. }
  153. if (GlobalBreak==false)
  154. {
  155. bool Interrested=false;
  156. cout << "ERROR! No ";
  157. if (Smoker){cout << "smoker";}else{cout << "non smoker";}
  158. cout << " seats avaiable!" << endl;
  159. cout << "Interrested in another apparture? [Yes=1][No=0]" << endl;
  160. cin >> Interrested;
  161. if (Interrested){MISSING();}
  162. }
  163. }
  164.  
  165. bool YouASmoker()
  166. {
  167. int SmokerSeatNeeded=0;
  168. cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl;
  169. cin >> SmokerSeatNeeded;
  170. if (SmokerSeatNeeded==-1){return 1;}
  171. DedicateSeat(SmokerSeatNeeded);
  172. return 0;
  173. }

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 ...
First of all, use CODEtags! Next up, if you want to print out the seat number, then you'll need to pass this be passed to somewhere, then written out, the simple solution would be to make a global var, and saving the seat number to this var, and calling that.
// Skeen
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC