943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 656
  • C++ RSS
Feb 14th, 2008
0

code

Expand Post »
C++ Syntax (Toggle Plain Text)
  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 .
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bis student is offline Offline
16 posts
since Dec 2007
Feb 14th, 2008
0

Re: code

>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:
C++ Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Math tutor
Next Thread in C++ Forum Timeline: Dubbuging





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC