Question
Just do program 6 using c++ which are printf and scanf. Please don’t use cout and cin.

Program 4: A slot machine has three windows. A random fruit is picked for each window from cherry apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is not a cherry, the user wins the bet amount. Otherwise, the player loses their bet Write a C program that will first allow the user to enter a bet amount. Next, the program should pick 3 random fruits for the 3 windows and print the 3 fruits picked. Lastly, the amount of money won or lost by the user should be displayed Program 5: Write a C program which includes the following functions with parameter passing Function 1:Allow the user to enter 3 float values Function 2: Print the 3 float values Function 3; Use the return statement to return the largest of the 3 float values. Print the largest value in the main. Function 4: Sort the 3 float values from low to high print the 3 float values in sorted order. Upon returning to the main, use your print function to Program 6: Rewrite Program 3 using appropriate functions and parameter passing. Also, please include a structure chart for your program which you can either create by hand or on the computer. Rewrite Program 6 using a looping statement. You may use either a while loop, do loop, or for
media%2F72e%2F72e45758-68b7-4b3d-8993-df
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
class GroceryItems
{
// Access specifier
private:
// Data Members
string itemName;
float unitPrice;
int quantity;
float discount;
  
public:
GroceryItems()
{
itemName='Cereal';
unitPrice=4;
quantity=5;
discount=5;
}
GroceryItems(string iName,float uPrice,int qty, float disc)
{
itemName=iName;
unitPrice=uPrice;
quantity=qty;
discount=disc;
}

string getItemName()
{
return itemName;
}
float getUnitPrice()
{
return unitPrice;
}
int getQuantity()
{
return quantity;
}
float getDiscount()
{
return discount;
}
  

// Member Functions()
void printname()
{
float cost = getUnitPrice() * getQuantity();
float discountAmt = (cost*getDiscount())/100;
float costWithdisc = cost - discountAmt;
cout << "Item Name = " << getItemName() <<endl;
cout << "Cost = " << cost <<endl;
cout << "Discount Amount = " << discountAmt<<endl;
cout << "Cost With Discount = " << costWithdisc<<endl;

  
}
  
  
};
int main()
{
int num;
GroceryItems g[5];
printf("***************************");
printf("GroceryItems Details");
printf("***************************");
printf("Enter number of Items");
scanf( "%d", &num );
GroceryItems gItemsList[num];
for(int i=0;i<num;i++)
{
char IName[101];
float IPrice;
int Qty;
float Disc;
printf( "Enter Item Name " );
scanf("%100s", IName);
printf( "Enter Item Price " );
scanf("%f", &IPrice );
printf( "Enter Item Quantity " );
scanf("%d", &Qty );
printf( "Enter Item Quantity " );
scanf("%f", &Disc );
GroceryItems item1(IName,IPrice,Qty,Disc);
gItemsList[i]=item1;
  
}
for(int i=0;i<num;i++)
{
gItemsList[i].printname();
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Just do program 6 using c++ which are printf and scanf. Please don’t use cout and...
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
  • This program should be run on Visual Studio. Please use printf and scanf as input and output. Tha...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • USING C++ PROGRAM Instructions - Part C Write a program that has three functions: All characters...

    USING C++ PROGRAM Instructions - Part C Write a program that has three functions: All characters printed should be in White ► Call the first function from main().Print "I'm in main" (as shown in example) > Print "I'm in function 1" in the first function. Call the second function. ► Print "I'm in function 2” in the second function and then ask the user to enter a float value. Enter 25 Call a third function and pass the value to...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions,...

    C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...

  • This program should be run on Visual Studio. Please use printf and scanf as input and...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.11 Lab Exercise Ch.6a: Functions: String analyzer Create and debug this program in Visual Studio. Upload your Source.cpp file for testing (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: ics Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

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