Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a full report with C program examples that differentiate between the several functions from the standard input/output library (Conio.h & stdio.h) (full report contains

Write a full report with C program examples that differentiate between the several functions from the standard input/output library (Conio.h & stdio.h) (full report contains a description for each functions . Then compare between them based on their output)

#include

#include

#include

#include

using namespace std;

void foodmenu();

void drinkmenu();

void checkout();

void mainmenu();

int totalCart=0;

string item[999];

float price[999];

int qty[999];

void foodmenu()

{

int optionF, quantityF;

float priceF;

char N,contF;

do

{

printf(" #Food Menu# ");

printf("1. Nasi Ayam -RM 08.00/unit ");

printf("2. Nasi Beryani -RM 10.00/unit ");

printf("3. Nasi Arab -RM 12.50/unit ");

printf("Select Your Option :");

scanf("%d", &optionF);

if (optionF==1)

{

item[totalCart]="Nasi Ayam";

printf(" you selected Nasi Ayam ");

}

else if(optionF==2)

{

item[totalCart]="Nasi Beryani";

printf(" You selected Nasi Beryani ");

}

else if(optionF==3){

item[totalCart]="Nasi Arab";

printf(" You selected Nasi Arab ");

}

printf(" Quantity : ");

scanf("%d", &quantityF);

qty[totalCart]=quantityF;

switch(optionF)

{

case 1 :

priceF = 8*quantityF;

break;

case 2 :

priceF = 10*quantityF;

break;

case 3 :

priceF = 12.5*quantityF;

break ;

default : printf (" Your selection is invalid please input the valid number.");

}

price[totalCart]=priceF;

totalCart++;

printf(" Price Total is %0.2f ", priceF);

printf(" Do you want to take another food menu ? (Y/N)");

contF = getch();

}while(contF == 'Y' || contF =='y');

mainmenu();

return;

}

void drinkmenu()

{

int optionD, quantityD;

float priceD;

char contD;

do

{

printf(" #Drink Menu ");

printf("1. Fresh Orange -RM3.00 ");

printf("2. Mango Lassi -RM3.50 ");

printf("3, Strawberry -RM4.00 ");

printf("Your Option :");

scanf("%d", &optionD);

if (optionD==1)

{

item[totalCart]="Fresh Orange";

printf(" you selected Fresh Orange ");

}

else if(optionD==2)

{

item[totalCart]="Mango Lassi";

printf(" You selected Mango Lassi ");

}

else if(optionD==3){

item[totalCart]="Strawberry";

printf(" You selected Strawberry ");

}

printf(" Quantity : ");

scanf("%d", &quantityD);

qty[totalCart]=quantityD;

switch(optionD)

{

case 1 : priceD = 3*quantityD;

break;

case 2 : priceD = 3.5*quantityD;

break;

case 3 : priceD = 4*quantityD;

break ;

default : printf (" Your selection is invalid please input the valid number.");

}

price[totalCart]=priceD;

totalCart++;

printf("Price Total is %0.2f", priceD);

printf(" Do you want to take another food menu ? (Y/N)");

contD = getch();

}while (contD == 'Y' || contD=='y');

mainmenu();

}

void checkout()

{

float cash;

float totalPrice=0;

printf(" Check Out ");

printf("===================================== ");

for(int i=0; i

{

cout

cout

totalPrice+=price[i];

}

printf("===================================== ");

printf(" Total : RM %0.2f",totalPrice);

printf(" Enter the Cash Ammount : ");

scanf("%f", &cash);

if(cash

printf("You don't have sufficient balance, your order has been canceled");

}else{

printf("Your change : %0.2f ", (cash-totalPrice));

printf("THANK YOU!!");

}

}

void mainmenu()

{

int menuM;

char contM;

printf(" #Main Menu ");

printf("1. Food Menu ");

printf("2. Drink Menu ");

printf("3. Checkout ");

printf("Select your option :");

scanf("%d", &menuM);

switch (menuM)

{

case 1 : foodmenu();

break;

case 2 : drinkmenu();

break;

case 3 : checkout();

break;

default :

printf(" Thank You");

break;

}

}

int main ()

{

int option;

char cont;

do

{

mainmenu();

printf(" Do you want to buy again? (Y/N) ");

cont = getch();

}while(cont == 'Y' || cont == 'y');

return 0;

}

Do description for each functions and explain the program step by step

these are some picture for sample functions description.

image text in transcribed

image text in transcribed

image text in transcribed

Functions printf() and scanf() are the most commonly used to display out and take input respectively. . However, several functions from the standard input/output library can be used for manipulating character and string data. . These functions are used to permit the transfer of information between the computer and the standard input/output device. Other basic input/output functions in the preprocessor directives (standard library) for manipulating character and string data are: gets() puts() getchar putchar() getch() putch() getc) pute() For a string For a character . Use library getchar(), putchar() Example: getchar(): to read a single character from standard input- keyboard. Pressing Enter causes the block of characters you typed to be made available to your program. char huruf; huruf = get char(); putchar (huruf); putchar (huruf+1); . The output with the input 'E' IS EE . putchar() to write a single character to standard output-output monitor. 53 getch(), putch() Use library Example: getch(): to read a single character from standard input- keyboard. The block of characters you typed available directly to your program. No need to press enter. Does not echo the input. char huruf; huruf = getch(); pulchar (huruf); putchar (huruf +1); The output with the input 'Elis F putch) to write a single character to standard output - monitor. 54 getc(), putc() Use library Example: getc) to read a single character from standard input device (i.e. keyboard and file). With stdin device type work similar with getchar() char huruf; gelc(stdin); pute (huruf, stdout); . pute() to write a single character to standard output device (i.e. monitor and file). 55 gets(), puts() Use library . . gets() to read strings standard input device Pressing Enter causes the strings you typed to be made available to your program. The new line character will be stored as null ('\0') puts ) to write string to standard output device. To change null ("\0') to new line. Example: Input string "Ahmad Mubassyir" and store as: Ahmad Mu ba S sy i r 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

(4) Performing linear regression to obtain the parameter estimates.

Answered: 1 week ago