Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to read user information from input. Then use the information to answer some questions. Input: You will first output the instruction

Write a C++ program to read user information from input. Then use the information to answer some questions.

Input:

You will first output the instruction of input as following:

Please enter information to database in the format of    , separated each user by a newline:

Then the program will start reading user information from input and count the number of input. You can store your count in an int variable userCount.

Program:

  1. Your program will first make a struct named userAccount. The struct would need to contain four attributes storing the user information that you will be reading from input. Please make sure the name of your variables are readable and represent the information that's stored.
  2. You will then read the user information and store them in an array of struct userAccount. The array can't hold more than 20 accounts.
  3. Using all the stored user information to answer the following questions:

(1) What is the highest account balance among all users?

You would want to initialize a float variable highestBalance with 0.0. Then compare all your user account balances with this variable, and only update the value of the variable if your current user account balance is larger than the value of highestBalance. Once you finish looping through all your users, you should have the correct highest account balance stored in the variable named highestBalance.

(2) What's the average account balance of all users?

You would want to initialize a float variable balanceSum to store the sum of all the account balances. For every user, you want to add the user's account balance on the balanceSum. At the end of the loop you would have the sum of all user account balances stored in the balanceSum. You then use balanceSum divided by the number of users(userCount) and store the answer in a variable named averageBalance.

(3) How many users come from Swiss?

You would want to check each user's nationality and use string comparison between users' nationality and "Swiss" to see whether the user is from Swiss. You will count number of users from Swiss then store the answer in the variable usersFromSwiss.

(4) Do we have any user younger than 21?

You want to check whether there's any user of age less than 21, if so output "Yes". If there's no user younger than 21, output "No".

  1. Write the questions and answers to output in order with the following format. Have questions and answers on separate lines, and have an empty line between each question. If the answer is a dollar amount, make sure you include the $ before the number at the output.

Example input and output:

The input will be similar to the following:

Hanzo Japanese 38 34.99 Mei Chinese 31 75.0 Brigitte Swedish 23 24.5 Mercy Swiss 37 242.35 Sigma Dutch 62 1324.0 Baptiste Haitian 36 325.0

Your output should look like the following:

Q: What is the highest account balance among all users? A: $1324.0 Q: What's the average account balance of all users? A: $337.64 Q: How many users come from Swiss? A: 1 Q: Do we have any user younger than 21? A: No

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

a. Do team members trust each other?

Answered: 1 week ago

Question

a. How will the leader be selected?

Answered: 1 week ago