code

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

Join Date: Dec 2007
Posts: 16
Reputation: bis student is an unknown quantity at this point 
Solved Threads: 0
bis student's Avatar
bis student bis student is offline Offline
Newbie Poster

code

 
0
  #1
Feb 14th, 2008
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void intialize(char array[][6]){
  5. for(int i=0;i<13;i++)
  6. for(int j=0;j<6;j++)
  7. array[i][j]='*';
  8. }
  9.  
  10. void menu (char array [][6]){
  11. cout <<endl;
  12.  
  13. cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
  14. for (int i =0; i<13 ;i++){
  15. cout<<"Row "<<i+1<<'\t';
  16. for(int j=0;j<6;j++){
  17. cout<<array[i][j]<<"\t";
  18. }
  19. cout<<endl;
  20. }
  21. cout<<endl;
  22. }
  23.  
  24. void main(){
  25.  
  26. char array[13][6];
  27. intialize(array);
  28. char smoking,type,exit,column;
  29. int row,col;
  30.  
  31. do{
  32. smoking = 'N';
  33. do{
  34. cout<<"Enter ticket type (F:first class or E:economy class) : ";
  35. cin >> type;
  36. }while(type !='F' &&type !='f'&&type !='e'&&type !='E');
  37.  
  38. if(type =='E' || type=='e'){
  39. cout <<"Enter \'S\' for smoking section or \'N\' nonsmoking section : ";
  40. cin>> smoking;
  41. }
  42.  
  43. menu(array);
  44.  
  45. //do{
  46. cout <<"Enter desired seat ( Row and Column ) : ";
  47. cin >>row >> column;
  48. while (row <=0 && row>13 || column < 'A' && column < 'F'){
  49. cout<<"Invalid value "<<endl;
  50. cout <<"Enter desired seat ( Row and Column ) : ";
  51. cin >>row >> column;
  52. }
  53.  
  54. while ((type =='F' || type=='f') && row >2){
  55. cout <<"Error! ,only first and second rows is first economy class"<<endl;
  56. cout <<"Enter desired seat ( Row and Column ) : ";
  57. cin >>row >> column;
  58. }
  59.  
  60. while ((smoking=='S' || smoking=='s') && row <8 ){
  61. cout <<"Error! ,this section is nonsmoking"<<endl;
  62. cout <<"Enter desired seat ( Row and Column ) : ";
  63. cin >>row >> column;
  64. }
  65.  
  66. do{
  67.  
  68. switch (column){
  69. case 'A':
  70. col = 0;
  71. break;
  72. case 'B':
  73. col = 1;
  74. break;
  75. case 'C':
  76. col = 2;
  77. break;
  78. case 'D':
  79. col = 3;
  80. break;
  81. case 'E':
  82. col = 4;
  83. break;
  84. case 'F':
  85. col = 5;
  86. break;
  87. }
  88. if (array[row-1][col]=='X'){
  89. cout<<"The seat is occupied "<<endl;
  90. cout <<"Enter desired seat ( Row and Column ) : ";
  91. cin >>row >> column;
  92. }
  93. else
  94. break;
  95. }while(true);
  96.  
  97. cout<<"Your seat is in Row "<<row<<" and in column "<<column<<endl;
  98. array[row-1][col]='X';
  99.  
  100. menu(array);
  101.  
  102. cout<<"Enter E to Exit or enter any key to continue : ";
  103. cin >>exit;
  104.  
  105. }while(exit !='E' && exit !='e');
  106.  
  107. }
how can I make the last code shorter and more clear .
there are always hope
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,730
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: code

 
0
  #2
Feb 14th, 2008
>how can I make the last code shorter and more clear .
I'd say it's plenty clear, and the only easy way to make it shorter is to drop the switch statement in favor of something like this:
  1. // Find the display index of the selected column
  2. col = column - 'A';
To nitpickers: yes, I know.
Last edited by Narue; Feb 14th, 2008 at 2:03 pm.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC