Question

In: Computer Science

Can anyone translate this to flowgorith. #include<stdio.h> int main()    {    int seatingChart[10];       //array...

Can anyone translate this to flowgorith.

#include<stdio.h>

int main()
   {
   int seatingChart[10];       //array for seating chart
  
   int fc = 0, ec = 5,i;       //starting positions for first class and economy class
  
   printf("Welcome to the Airline Reservation System (ARS)\n\n");
  
   for(i=0;i<10;i++)       //initializing the array with zero
       {
       seatingChart[i] = 0;
       }
   char choice;
  
   do
       {
       int ch;
      
       printf("Please type 1 for first class\nPlease type 2 for economy: ");       //taking the input from the user
       fflush(stdin);
       scanf("%d",&ch);
      
       if(ch == 1 && fc <= 4)
           {                                       //checking the conditions to assign the seating
           seatingChart[fc] = 1;               //if 1 entered and first class is empy then seat is reserved
           printf("Seat number %d reserved (first class)\n",fc+1);          
           fc++;
           }
      
       else if(ch == 1 && fc > 4 && ec<=9)       //if fist class is not empty and economy class is empty
           {
           char check;
           printf("First class is filld.Do you want reserve for Economy Section (y/n)? ");       //asking the user to confirm
           fflush(stdin);
           scanf("%c",&check);

           if(check == 'y')       //if yes assigning the economy class
               {
               seatingChart[ec] = 1;
               printf("Seat number %d reserved (first class)\n",ec+1);
                   ec++;
               }
             
           else
               {
               printf("Next flight leaves in 3 hours.\n");
               }
          
           }
      
       else if(ch == 2 && ec <= 9)       //if 2 is entered and economy class is avaiable
           {
           seatingChart[ec] = 1;
           printf("Seat number %d reserved (first class)\n",ec+1);
           ec++;
           }
      
       else if(ch == 2 && ec > 9 && fc <= 4)           //if economy class is not availale and
           {                                               //first class is available
           char check;
           printf("Economy Section is filld.Do you want reserve for First Class (y/n)? ");
           fflush(stdin);
           scanf("%c",&check);
          
           if(check == 'y')
                   {
                   seatingChart[fc] = 1;
                   printf("Seat number %d reserved (first class)\n",fc+1);
                   fc++;
               }
               else
                   {
               printf("Next flight leaves in 3 hours.\n");
               }
           }
         
       else
           {
           printf("Next flight leaves in 3 hours.\n");       //if both are not available
           }

       printf("Seat Assignments: FC: ");   //printing the seats avalable
      
       for(i=0;i<5;i++)
           {
           if(seatingChart[i] == 1)
               {
               printf("X ");
               }
           else
               {
               printf("_ ");
               }
           }
       printf("EC: ");
      
       for(i=5;i<10;i++)
           {
           if(seatingChart[i] == 1)
               {
               printf("X ");
               }
           else
               {
               printf("_ ");
               }
           }
       printf("\n\t\t 1 2 3 4 5 6 7 8 9 10\n");

       printf("Another reservation (y/n)? ");       //asking if the user wants to make an other reservation
       fflush(stdin);
       scanf("%c",&choice);
      
       }
   while(choice == 'y');
  
   return 0;
   }

I have tried and can't get it to work.

Solutions

Expert Solution

#include<stdio.h>

int main()
   {
   int seatingChart[10];       //array for seating chart
  
   int fc = 0, ec = 5,i,p;       //starting positions for first class and economy class
  
   printf("Welcome to the Airline Reservation System (ARS)\n\n");
  
   for(i=0;i<10;i++)       //initializing the array with zero
       {
       seatingChart[i] = 0;
       }

int ch;

for( int j = 0; j< 10; j++)

{

printf("Please type 1 for first class\nPlease type 2 for economy: ");       //taking the input from the user

scanf("%i",&ch);

switch(ch)

{

case 1:

printf("\nFirst class\n");
printf("Seats available are 1,2,3,4,5.\n");
do
{
printf("Pick a seat:\n\n");
scanf("%i",&p);
seatingChart[j]=p;
for (i=0; i<j; i++)
{
if (seatingChart[j]==seatingChart[i])
{
printf("\n\nSeat taken.\n\n");
break;
}
}
}
while (i!=j);
if(seatingChart[j] <= 5)
{
printf("\n");
printf("--------------------------\n");
printf("Class: First class\n");
printf("Seat no : %i\n",seatingChart[j]);
printf("--------------------------\n\n");
}
else
printf("Next flight leaves in 3 hours.\n");
break;
       case 2:
           printf("\nEconomical class\n");
           printf("Seats available are 6,7,8,9,10.\n");
           do
           {
printf("Pick a seat:\n\n");
scanf("%i",&p);
seatingChart[j]=p;
           for (i=0; i<j; i++)
           {
if (seatingChart[j]==seatingChart[i])
{
printf("\n\nSeat taken.\n\n");
break;
}
           }
}
while (i!=j);
if(seatingChart[j] >= 6)
{
printf("\n");
printf("--------------------------\n");
printf("Class: Economical class\n");
printf("Seat no : %i\n",seatingChart[j]);
printf("--------------------------\n\n");
}
else
printf("Next flight leaves in 3 hours.\n");
break;
default:
break;
}//end switch case
}//end counting people*/
   return 0;
}


Related Solutions

Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number;...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number; Scanf (“%d”, & number); if (number % 2 ==0) { printf (“Even\n”); } else { printf(“Odd\n”); } Return 0; }
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2;...
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2; printf("he FInal =value=%d\n", value); value +=3; printf("he FInal =value=%d\n", value); value ++; printf("he FInal =value=%d\n", value); value= ++value2; printf("he FInal =value=%d\n", value); value= value2--; printf("he FInal =value=%d\n", value); } what is output explain each print statement? exlain why?
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum;...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum; scanf("%d", &numitms); sum=0; for (j=1;j<=numitms;j++) { scanf("%d", &data); sum+=data; } printf("sum: %d\n",sum); return0; } I got an answer with an error. Please debug the answer or have a new correct answer (don't copy and paste others' answer) main: SUBSP 2,i DECI numItms,i DECI j,j DECI data,d DECI sum,s LDWA numItms,i sum: .EQUATE 0 LDWA 1,i STWA j,j for: CPWA numItms, j BRGE endFor STRO...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc != 2) || (sscanf(argv[1],"%d",&count) != 1)) { fprintf(stderr,"Usage: %s <integer>\n", argv[0]); exit(1); } pid_t pid1, pid2; while (count > 0) { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); count = count - 2; } else if (pid1 == 0) { count = count - 1; } } exit(0); } Question #1 [2 pts] If the command-line argument passed to this...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to my Command-Line Calculator (CLC)\n");    printf("Developer: Your name will come here\n");    printf("Version: 1\n");    printf("Date: Development data Will come here\n");    printf("----------------------------------------------------------\n\n");    //choice stores users input    char choice;    //to store numbers    int val1,val2;    //to store operator    char operation;    //flag which leths the loop iterate    //the loop will break once the flag is set to 0...
#include "pch.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() {        FILE...
#include "pch.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() {        FILE *fp;        char c;        errno_t err;        err = 0;        err = fopen_s(&fp,"Desktop/test.txt", "r"); file is on my desktop but I err=2 but I don't think it is opening the file?        printf("%d\n", err);        if (err == 2)        {            printf("The file was opened\n");            while (1)       ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;     char fname[20];     //int sum = 0;     int i, j, k, tmp =0;     int num = 0;     int mass = 0;     int count = 0;     int fuel = 0;     int total = 0;     int M[1000];     char ch;     char buffer[32];     printf(" Input the filename to be opened : ");     scanf("%s",fname);     myFile = fopen(fname, "r");     if(myFile == NULL)     {         printf("Can't open file\n");     } while(1)     {         ch =...
Translate following function from C into RISC-V: Display Prime Numbers Between Two Intervals #include<stdio.h> int main(){...
Translate following function from C into RISC-V: Display Prime Numbers Between Two Intervals #include<stdio.h> int main(){ int low, high, i, flag; printf("Entertwonumbers(intervals):"); scanf("%d%d",&low,&high); printf("Primenumbersbetween%dand%dare:",low,high); //iteration until low is not equal to high while(low<high) { flag=0; //ignore numbers less than 2 if(low<=1) { ++low; continue; } //if low is a non-prime number, flag will be 1 for(i=2;i<=low/2;++i) { if(low%i==0) { flag=1; break; } } if(flag==0) printf("%d",low); //to check prime for the next number //increase low by 1 ++low; } return0; }
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int a,b,c,D,n; double x1,x2; double realPart, imagPart; do { // this set of code blocks prompts a message to the user and then read the integer entered and stores it as an integer printf("Enter a value for a:\n"); scanf("%d",&a); printf("Enter a value for b:\n"); scanf("%d",&b); printf("Enter a value for c:\n"); scanf("%d",&c); printf("You entered the Equation \n"); printf("%dx^2%+dx%+d=0\n",a,b,c); D = b*b - 4*a*c;    if (D<0)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT