#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;
}
Just do program 6 using c++ which are printf and scanf. Please don’t use cout and...
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 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 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 ("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 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, 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 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 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 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; (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...