C Programming. Use Code :: Blocks to write a program for this exercise: ( Using
ID: 3695707 • Letter: C
Question
C Programming. Use Code :: Blocks to write a program for this exercise: (Using Pointers and Strings)
Cost Estimate:
(a) Define a pair of parallel arrays that will be used for estimating the cost of a repair job. The first array should contain the names of various parts; the second array, the price of each part.
For example, these arrays might contain data like this:
{ "muffler", "oil filter", "spark plugs", ... }
{ 39.95, 4.95, 6.00, ... }
(b) Write a program that will present a menu of parts for the user, then permit him or her to select any number of parts from the menu. After selecting a part, the program should prompt for the quantity of that part (one or more) that will be used for the repair, calculate the price for those parts, and add it to a total price. When the user selects "Done" from the menu, print the total price of all parts needed, with a sales tax of 6%.
Explanation / Answer
#include<stdio>
#include<conio>
using namespace std;
int menu(string parts[])
{
int c,i;
clrscr();
printf("Menu ");
for(i=0;i<5;i++)
{
printf("%d. %s ",(i+1),parts[i]);
}
printf("6.Done ");
printf("Enter choise");
scanf("%d",&c);
return c;
}
void main()
{
string parts={"muffler","oil filter","spark plugs","engine oil","gaer box"} ;
float p[]={39.95,4.95,6.00,10.0,20.0};
float tot=0;
int c;
while(1)
{
c=menu(parts);
switch(c)
{
case 1:
tot=tot+p[0];
break;
case 2:
tot=tot+p[1];
break;
case 3:
tot=tot+p[2];
break;
case 4:
tot=tot+p[3];
break;
case 5:
tot=tot+p[4];
break;
case 6:
printf("Total amount is %f",tot);
return;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.