Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Complete the copier simulation of How To 7.1 Working with Pointers Your program should first show the main menu: U)ser A)dministrator Q)uit For a

C++

image text in transcribedimage text in transcribed

Complete the copier simulation of How To 7.1 Working with Pointers

Your program should first show the main menu:

U)ser A)dministrator Q)uit

For a user, prompt for the ID and the number of copies, increment the appropriate account, and return to the main menu.

For an administrator, show this menu:

B)alance M)aster P)roject

In the balance option, show the balances of the master account and the ten project accounts. In the master option, prompt for a user ID and link it to the master account. In the project option, prompt for user and project IDs.

Afterward, return to the main menu.

Working with Pointers You use pointers because you want flexibility in your program: the ability to change the relationships between data. This How To walks you through the decision-making process for using pointers. Problem Statement We will illustrate the steps with the task of simulating a portion of the control logic for a departmental photocopier. A person making a copy enters a user number. There are 100 different users, with numbers 0 to er is linked to a copy account, either the master account or one of ten project accounts. That linkage is maintained by the administrator, and it can change as users work on different projects. When copies are made, the appropriate account should be incremented. Step 1 Draw a picture. Bartosz Liszkowski/Stockphoto. As described in Section 7.6, it is a good idea to draw a picture that shows the pointers in your program. In our example, we need to track the copy accounts: a master account and ten project accounts. For each user, we need a pointer to the copy account: Users identify themselves on the copier control panel. Using pointers, the relationships between users and copy accounts can be flexible. master_account - users - project accounts = Step 2 Declare pointer variables. This step is usually easy. With numerical data, you will have pointers of type int* or double. If you manipulate character arrays, you use char* pointers. In Chapter 10, you will use pointers to objects. How many pointer variables do you have? If you only have one or two, just declare variables such as double* account_pointer; If you have a sequence of pointers, use a vector or array, such as vector lines; In our example, the purpose is to manipulate copy counters. Therefore, our data are integers and the pointers have type int*. We know that we will have exactly 100 pointers, one for each user. Therefore, we can choose an array int* users (100); Step 3 Initialize the pointers with variable addresses or free store memory. Will you allocate variables and then take their addresses with the & operator? That is fine if you have a fixed amount of data that you want to reach through the pointers. Otherwise, use the new operator to allocate memory dynamically. Be sure to deallocate the memory when you are done, using the delete or delete[] operator. In our example, there is no need for dynamic allocation, so we will just take addresses of variables. int master account; int project_accounts(10); for (int i = 0; i > id >> copies; *users[id] = *users[id] + copies; Exercise ... P7.2 asks you to complete this simulation

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_2

Step: 3

blur-text-image_3

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

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

Find all LFTs with fixed point(s). z = i

Answered: 1 week ago

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago