Как преобразовать код C++ в C
#include <stdio.h> #include <conio.h> #include <iostream> #include <cmath> #include<string.h> #include <stdlib.h> #include<time.h> #include <fstream> #include<list> using namespace std; #define NO_OF_ROWS 20 #define NO_OF_COLUMNS 6 main(void) { unsigned int r,c,Class,DesiredSeat,n=1,Age,PR=0,SP=0,OfficeWork=0; unsigned int SeatsNo[NO_OF_ROWS][NO_OF_COLUMNS],FlagAge=0; char Sex; unsigned int SeatingPlan[NO_OF_ROWS][NO_OF_COLUMNS] = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} }; cout<<"Seating Nos.\n"; n=1; for(r=0;r<NO_OF_ROWS;r++) { cout<<"Row-"<<(r+1); for(c=0;c<NO_OF_COLUMNS;c++) { cout<<"\t"<<n; n=n+1; } if(r<=5) cout<<"\tFirst Class"; if(r>=6) cout<<"\tEconomy Class"; cout<<"\n"; } while(1) { FlagAge=1; cout<<"\n\n"; cout<<"Seats Availability\n"; for(r=0;r<NO_OF_ROWS;r++) { cout<<"Row-"<<(r+1); for(c=0;c<NO_OF_COLUMNS;c++) { if(SeatingPlan[r][c] == 1) cout<<"\tX"; else cout<<"\t*"; } if(r<=5) cout<<"\tFirst Class"; if(r>=6) cout<<"\tEconomy Class"; cout<<"\n"; } cout<<"\n\n Enter 0-> To EXIT..."; cout<<"\n\n Enter 1-> First Class"; // cout<<"\n Enter 2-> Business Class"; cout<<"\n Enter 3-> Economy Class\n"; cout<<"\n\nEnter the Class: "; cin>>Class; if(Class == 0) exit(0); cout<<"\n Enter the Gender M/F: "; cin>>Sex; if(Sex == 'F' || Sex == 'f') { cout<<"\nEnter the Age = "; cin>>Age; if(Age<35) FlagAge=0; } else FlagAge=1; cout<<"\nIf the travel is for Official Work: Press 1 for YES and 0 for NO: "; cin>>OfficeWork; cout<<"\nIf the traveller has Permanant Resisdency Certificate? Press 1 for YES and 0 for NO: "; cin>>PR; cout<<"\nIf the traveller has Special Permission? Press 1 for YES and 0 for NO: "; cin>>SP; if(FlagAge && (OfficeWork || PR || SP)) { if(Class==1) cout<<"\n\nDesired Seat (1 - 30) = "; if(Class==3) cout<<"\n\nDesired Seat (31 - 120) = "; cin>>DesiredSeat; while(Class==1 && DesiredSeat>30) { cout<<"\nInvalid Desired Seat"; cout<<"\n\nDesired Seat (1 - 30) = "; cin>>DesiredSeat; } while(Class==3 && (DesiredSeat < 31 || DesiredSeat>120)) { cout<<"\nInvalid Desired Seat"; cout<<"\n\nDesired Seat (31 - 120) = "; cin>>DesiredSeat; } if(Class == 0) exit(0); r = DesiredSeat/NO_OF_COLUMNS; c = (DesiredSeat%NO_OF_COLUMNS)-1; if(SeatingPlan[r][c] == 0) SeatingPlan[r][c] = 1; else cout<<"\n\nSeat No. "<<DesiredSeat<<" is not Available"; } else { cout<<"\n\nTHE TRAVELLING IS NOT ALLOWED.\n\n"; } } }
Что я уже пробовал:
Я пробовал его в программировании на Си, но не смог решить
Richard MacCutchan
Помимо использования cin и cout, это уже код C.