Question

C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

C++ HELP

I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files

1. bill.h = contains the class program with methods and variables

2. bill.cpp = contains the functions from class file

3. main.cpp = contains the main program.

Please split this program into three files and make the program run. I have posted the code here.

#include<iostream>

using namespace std;

int again;
int total=0;
int bfrate[7][2]={ {0,30},
{1,35},
{2,40},
{3,20},
{4,15},
{5,20},
{6,30}
};

int purchased[][3]={{0,0},
{0,0},
{0,0},
{0,0},
{0,0},
{0,0},
{0,0}
};

void bfast(char bfmenu[][100]);
void main_menu();
void display();
void display_bf_bill(char bfmenu[][100]);
void display_bfmenu();
void repeatbf(char bfmenu[][100]);


int main()
{
char bfmenu[][100]={"toast","Idli-wada","Dosa","Upma","milk","tea","coffee"};
char choice;
do
{
enter:
display();
printf("Enter your choice here : "); // //The printf() function displays the standard output.//
scanf("%c", &choice); //The scanf() function reads the data from standard input(user input) and stores the values into the respective variables.//
switch(choice)
{
case 'A':
case 'a':cout<<"\nBreakfast\n"<< endl;
bfast(bfmenu);
break;

default:printf("\nWrong choice entered Please enter the valid choice!!\n");
goto enter;
}
}while(choice!='d');
}
void display()
{
printf(" Welcome to Breakfast Restaurant. \n ");
printf(" +============================+ \n\n");
printf(" && Please select the meal that you would like to purchase. && \n\n");
printf("\t\t [A] Breakfast\n");
}
void display_bfmenu()
{
printf(" Welcome to Breakfast Restaurant. \n ");
printf(" +============================+ \n\n");
printf(" $ Breakfast Menu $ \n\n");
printf(" && Please select the food that you would like to purchase. && \n\n");
printf("\t\t [0] Toast - Rs 30.00\n");
printf("\t\t [1] Idli-Vada - Rs 35.00\n");
printf("\t\t [2] Dosa - Rs 40.00\n");
printf("\t\t [3] UPMA Rs 20.00\n");
printf("\t\t [4] Milk- Rs 15.00\n");
printf("\t\t [5] Tea - Rs 20.00\n");
printf("\t\t [6] Coffee - Rs 30.00\n");
}
void bfast(char bfmenu[][100]) //Breakfast Menu Screen
{
int choice = 0; //local variables
int quantity = 0;
int again = 0;
int code,i;
display_bfmenu();
printf("\nEnter the code: \n");
scanf("%d", &code);
if(code>=0&&code<=6)
{
printf("\nEnter the quantity: \n");
scanf("%d",&quantity);
purchased[code][1]= quantity*bfrate[code][1]; /*purchased[code][1]+ (quantity*bfrate[code][1]);*/
total+=purchased[code][ 1];
}
else
{
printf("\nInvalid code entered, Please enter the code again!!!! \n");
bfast(bfmenu);
}
repeatbf(bfmenu);
}
void repeatbf(char bfmenu[][100])
{
printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : "); // Allows user to choose whether to check-out or buy anything else.
scanf("%d",&again);
if (again == 1)
bfast(bfmenu);
else if (again == 2 )
{
display_bf_bill(bfmenu);
exit(0);
}
else
{
printf("\n\n\t\tSorry Invalid Decision Entered\n");
repeatbf(bfmenu);
}
}
void display_bf_bill(char bfmenu[][100])
{
int i;
printf(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ \n\n");
printf(" Breakfast RESTAURANT \n");
printf(" BILLING INFORMATION \n");
printf("\t\t ITEMS\t\tPrice(in Rs.)\n");
for(i=0;i<7;i++)
{
if(purchased[i][1]!=0)
{
printf("\t\t%s\t\t",bfmenu[i]);
printf("%d\n",purchased[i][1]); /*purchased[i][1]);*/
}
}
printf("\t\tTotal=Rs.%d\n",total);
printf("\n\n +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ \n\n");

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

----------------------------------------------------------------------------------------------------------------------------

bill.h

#ifndef BILL_H

#define BILL_H


void bfast(char bfmenu[][100]);

void main_menu();

void display();

void display_bf_bill(char bfmenu[][100]);

void display_bfmenu();

void repeatbf(char bfmenu[][100]);


#endif


----------------------------------------------------------------------------------------------------------------------------
bill.cpp

#include<iostream>

#include<stdio.h>

#include<cstdlib>

using namespace std;

#include "bill.h"

int again;

int total=0;

int bfrate[7][2]={ {0,30},

{1,35},

{2,40},

{3,20},

{4,15},

{5,20},

{6,30}

};

int purchased[][3]={{0,0},

{0,0},

{0,0},

{0,0},

{0,0},

{0,0},

{0,0}

};

void display()

{

printf(" Welcome to Breakfast Restaurant. \n ");

printf(" +============================+ \n\n");

printf(" && Please select the meal that you would like to purchase. && \n\n");

printf("\t\t [A] Breakfast\n");

}

void display_bfmenu()

{

printf(" Welcome to Breakfast Restaurant. \n ");

printf(" +============================+ \n\n");

printf(" $ Breakfast Menu $ \n\n");

printf(" && Please select the food that you would like to purchase. && \n\n");

printf("\t\t [0] Toast - Rs 30.00\n");

printf("\t\t [1] Idli-Vada - Rs 35.00\n");

printf("\t\t [2] Dosa - Rs 40.00\n");

printf("\t\t [3] UPMA Rs 20.00\n");

printf("\t\t [4] Milk- Rs 15.00\n");

printf("\t\t [5] Tea - Rs 20.00\n");

printf("\t\t [6] Coffee - Rs 30.00\n");

}

void bfast(char bfmenu[][100]) //Breakfast Menu Screen

{

int choice = 0; //local variables

int quantity = 0;

int again = 0;

int code,i;

display_bfmenu();

printf("\nEnter the code: \n");

scanf("%d", &code);

if(code>=0&&code<=6)

{

printf("\nEnter the quantity: \n");

scanf("%d",&quantity);

purchased[code][1]= quantity*bfrate[code][1]; /*purchased[code][1]+ (quantity*bfrate[code][1]);*/

total+=purchased[code][ 1];

}

else

{

printf("\nInvalid code entered, Please enter the code again!!!! \n");

bfast(bfmenu);

}

repeatbf(bfmenu);

}

void repeatbf(char bfmenu[][100])

{

printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : "); // Allows user to choose whether to check-out or buy anything else.

scanf("%d",&again);

if (again == 1)

bfast(bfmenu);

else if (again == 2 )

{

display_bf_bill(bfmenu);

exit(0);

}

else

{

printf("\n\n\t\tSorry Invalid Decision Entered\n");

repeatbf(bfmenu);

}

}

void display_bf_bill(char bfmenu[][100])

{

int i;

printf(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ \n\n");

printf(" Breakfast RESTAURANT \n");

printf(" BILLING INFORMATION \n");

printf("\t\t ITEMS\t\tPrice(in Rs.)\n");

for(i=0;i<7;i++)

{

if(purchased[i][1]!=0)

{

printf("\t\t%s\t\t",bfmenu[i]);

printf("%d\n",purchased[i][1]); /*purchased[i][1]);*/

}

}

printf("\t\tTotal=Rs.%d\n",total);

printf("\n\n +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ \n\n");

}

----------------------------------------------------------------------------------------------------------------------------------

main.cpp

#include <iostream>

#include <stdio.h>

using namespace std;

#include "bill.h"


int main()

{

char bfmenu[][100]={"toast","Idli-wada","Dosa","Upma","milk","tea","coffee"};

char choice;

do

{

enter:

display();

printf("Enter your choice here : "); // //The printf() function displays the standard output.//

scanf("%c", &choice); //The scanf() function reads the data from standard input(user input) and stores the values into the respective variables.//

switch(choice)

{

case 'A':

case 'a':cout<<"\nBreakfast\n"<< endl;

bfast(bfmenu);

break;

default:printf("\nWrong choice entered Please enter the valid choice!!\n");

goto enter;

}

}while(choice!='d');

}

------------------------------------------------------------------------------------------------------------------------------------------
SEE OUTPUT

Files main.cpp E saved && Please select the food that you would like to #include io stream» main.cpp 2 #include <stdio.h> 3 u

Thanks, PLEASE UPVOTE, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • Need help with a C++ problem I have

    For my assignment I have to write a program that creates a restaurant billing system. I think that I got it correct but it says that it is incorrect, so I was wondering if someone would be able to look over my code. It says that I need tax of $0.20, and the amount due to be $4.10, which is what I have in my output.https://imgur.com/a/jgglmvWMy issue is that I have the correct outcome when I run my program but...

  • I need to make it so this program outputs to an output.txt, the program works fine,...

    I need to make it so this program outputs to an output.txt, the program works fine, just need it to fprintf to output.txt #include <stdio.h> #include <string.h> #include <malloc.h> #define MAX 30 struct treeNode { char names[MAX];    struct treeNode *right; struct treeNode *left; }*node; void searchName(char names[], struct treeNode ** parent, struct treeNode ** location) { struct treeNode * ptr, * tempPtr; if(node == NULL)    { *location = NULL; *parent = NULL; return; } if(strcmp(names, node->names) == 0)...

  • Writing a program in C please help!! My file worked fine before but when I put...

    Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...

  • C Programming I have this cost estimation program, but I want to add to it more...

    C Programming I have this cost estimation program, but I want to add to it more functions to be more accurate and more useful. I want to add to the program an array and a loop that can help me with the materials that can be use to the building, as ceramic, wood and concrete and extra functions. ########## #include <stdio.h> int main(void) { float wid,len,yrs; int metersq = 2000; int floors,rooms,win,doors,restrooms,umet; char floortype[20]; char ti[20]; int woodfloor = 25;...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT