Question

Write a program that first asks the user how many budget items they have. Then using...

Write a program that first asks the user how many budget items they have. Then using dynamic arrays, create the appropriate arrays to hold the following data:

Allow the user to enter the budget items and amount budgeted for the number items created in the dynamic array. (For your testing, just use four or five.) Once all budget items are entered, the program should then output each budget item, the amount of money budgeted for that item, and the percentage of the total budget for each item. Your program should also calculate and print the total budget amount and print out the highest budget line item. A sample output is:

Budget Item

Amount

% of Total

Mortgage

1300

76.70

Electric

150

8.85

Internet

75

4.42

Cell Phone

120

7.08

Food

50

2.95

Total

1595

Highest Item

Mortgage

By using a struct to hold the data instead of two arrays

I need help with problem its C++. Thank you.

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

CODE:

#include <iostream>
#include <iomanip>

using namespace std;

//structure to store the item details
struct Items{
  
//stores item name
string item;
  
//stores item amount
double amount;
};

int main()
{
//to store the number of items
int n;
cout<<"Enter the number of budget items: ";
  
//input of number of Items
cin>>n;
  
//initializing n number of items
Items it[n];
  
cout<<"Enter Items name and amount: \n";
  
int sum=0,max=0;
  
//input of details of n items
for(int i=0;i<n;i++){
cin>>it[i].item;
cin>>it[i].amount;
  
//calculating sum of n items amount
sum+=it[i].amount;
  
//if max is smaller than ith items amount, update max
if(max<it[i].amount)
max = it[i].amount;
}
  
cout<<"\nITEM AMOUNT PERCENTAGE\n";
  
//it will print double upto 2 decimal precision
cout<<fixed<<setprecision(2);
  
//printing details of n items and their calculated PERCENTAGE
for(int i=0;i<n;i++){
cout<<it[i].item<<" "<<it[i].amount<<" "<<it[i].amount*100/sum<<"%"<<endl;
}
  
cout<<"Highest amount: "<<max<<endl;
cout<<"Total Amount: "<<sum;
  
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write a program that first asks the user how many budget items they have. Then using...
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
  • Q1 (2 pts) Shopping list Write a program that prompts a user for items on their...

    Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...

  • c++ Write a C++ program using the struct keyword to help a local restaurant automate its...

    c++ Write a C++ program using the struct keyword to help a local restaurant automate its breakfast billing system The program should do the following: a. Show the customer the different breakfast items offered by the restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item) Menu Plain...

  • Write a program Ct+ that processes a user's monthly budget. Note that this program can easily...

    Write a program Ct+ that processes a user's monthly budget. Note that this program can easily be enhanced to process any number of budget items he program should contain several Classes A parent class named SpentItemType. The parent class should contain several member variables and member functions Just need classes below Above, we will restrict the program to process a maximum of 10 budget items for each group For each Budget items, there should be a class created that contains...

  • IN C# Write a program to help a local restaurant automate its lunch billing system. The...

    IN C# Write a program to help a local restaurant automate its lunch billing system. The program should do the following: Show the customer the different lunch items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following lunch items (the price of each item is shown to the right of the item): Ham and Cheese Sandwich $5.00 Tuna Sandwich $6.00 Soup...

  • Write a program and flowchart. The program should ask the user how many customers they want...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

  • Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to...

    Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array    Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....

  • Shopping Cart You are to write a program that reads the name of the item, the quantity of each it...

    C++ language Shopping Cart You are to write a program that reads the name of the item, the quantity of each item, and the cost per item from a file. The program will then print out the item and how much is owed for each item. After everything is read in, it will print out the total cost of the cart. Your program should have the following functions main - This function asks the user to enter a filename and...

  • Write a program using M.I.P.S that asks user “how many positive number that is devisable by...

    Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...

  • Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

  • USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special”...

    USING PYTHON PROGRAMING LANGUAGE Write a program that first asks the user to enter a “special” letter. The program should then ask the user to enter a single line sentence containing all lowercase letters and no punctuation, except for a period at the end. The program will then output the number of times that this letter appears in the sentence. Example: Enter a special letter: t Enter a sentence: here is my little sentence. Your letter appears 3 times. (t...

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