1. Practice questions:
1. Write a program in C++ to store registration of 100 students and their 7
courses. Calculate class average of each of course and display.
2. (Credit Limit Calculator) Develop a C program that will determine if a
department store customer has exceeded the credit limit on a charge account.
For each customer, the following facts are available:
a. Account number
b. Balance at the beginning of the month
c. Total of all items charged by this customer this month
d. Total of all credits applied to this customer's account this month
e. Allowed credit limit
The program should input each fact, calculate the new balance (= beginning
balance + charges – credits), and determine whether the new balance
exceeds the customer's credit limit. For those customers whose credit limit
is exceeded, the program should display the customer's account number,
credit limit, new balance and the message “Credit limit exceeded.” Here is
a sample input/output dialog
3. One large chemical company pays its salespeople on a commission basis.
The salespeople receive $200 per week plus 9% of their gross sales for that
week. For example, a salesperson who sells $5000 worth of chemicals in a
week receives $200 plus 9% of $5000, or a total of $650. Develop a program
that will input each salesperson’s gross sales for last week and will calculate
and display that salesperson’s earnings. Process one salesperson's figures at
a time. Here is a sample input/output dialog:
4. The simple interest on a loan is calculated by the formula:
Interest = principal * rate * days / 365;
2. The preceding formula assumes that rate is the annual interest rate, and therefore
includes the division by 365 (days). Develop a program that will input principal,
rate and days for several loans, and will calculate and display the simple interest
for each loan, using the preceding formula.
Here is a sample input/output dialog:
5. Write a program that finds the smallest of several integers (without using
array). Assume that the first value read specifies the number of values
remaining.
6. One interesting application of computers is drawing graphs and bar charts
(sometimes called “histograms”). Write a program that reads five numbers
(each between 1 and 30). For each number read, your program should print
a line containing that number of adjacent asterisks. For example, if your
program reads the number seven, it should print *******.
7. An online retailer sells five different products whose retail prices are shown
in the following table:
Write a program that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity sold for one day
Your program should use a switch statement to help determine the retail price
for each product.
Your program should calculate and display the total retail value of all products
sold last week.
8. (CalculatingWeeklyPay) A company pays its employees as managers (who
receive a fixed weekly salary), hourly workers (who receive a fixed hourly
wage for up to the first 40 hours they work and “time-and-a-half”—i.e., 1.5
times their hourly wage—for overtime hours worked), commission workers
(who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers
(who receive a fixed amount of money for each of the items they produce—
each pieceworker in this company works on only one type of item). Write a
program to compute the weekly pay for each employee. You do not know
the number of employees in advance. Each type of employee has its own
pay code: Managers have paycode 1, hourly workers have code 2,
commission workers have code 3 and pieceworkers have code 4. Use a
switch to compute each employee’s pay based on that employee’s paycode.
Within the switch, prompt the user (i.e., the payroll clerk) to enter the
3. appropriate facts your program needs to calculate each employee’s pay
based on that employee’s paycode.
9. Write a program that prints the following diamond shape
10. (Parking Charges)A parking garagecharges a $2.00minimum fee to parkforup to three hours
and an additional$0.50 perhourfor each hour or part thereofoverthree hours. The maximum
charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24
hours at a time. Write a programthat will calculate and print the parking charges for each of
three customers who parked their cars in this garage yesterday. You should enter the hours
parked foreach customer.Yourprogramshould print theresults in a tabularformat,and should
calculate and print the total of yesterday's receipts. The program should use the function
calculateCharges to determine the charge for each customer. Your outputs should appear in the
following format:
11. (Hypotenuse Calculations) Define a function called hypotenuse that
calculates the length of the hypotenuse of a right triangle when the other
two sides are given. The function should take two arguments of type
double and return the hypotenuse as a double.
12. (Square of Asterisks) Write a function that displays a solid square of
asterisks whose side is specified in integer parameter side. For example, if
side is 4, the function displays:
13. (Displaying a Square of Any Character) Modify the function created in
Exercise 5.19 to form the square out of whatever character is contained in
4. character parameter fillCharacter. Thus if side is 5 and fillCharacter is “#”,
then this function should print:
14. (Separating Digits) Write program segments that accomplish each of the
following:
a. Calculate the integer part of the quotient when integer a is divided by
integer b.
b. Calculate the integer remainder when integer a is divided by integer b.
c. Use the program pieces developed in a) and b) to write a function that
inputs an integer between 1 and 32767 and prints it as a series of digits,
with two spaces between each digit.
For example, the integer 4562 should be printed as:
15. Given the following structure and variable definitions,
struct customer {
char lastName[ 15 ];
char firstName[ 15 ];
unsigned int customerNumber;
struct {
char phoneNumber[ 11 ];
char address[ 50 ];
char city[ 15 ];
char state[ 3 ];
char zipCode[ 6 ];
} personal;
} customerRecord, *customerPtr;
customerPtr = &customerRecord
Write an expression that can be used to access the structure members in each of
the following parts:
a. Member lastName of structure customerRecord.
b. Member lastName of the structure pointed to by customerPtr.
c. Member firstName of structure customerRecord.
d. Member firstName of the structure pointed to by customerPtr.
e. Member customerNumber of structure customerRecord.
f. Member customerNumber of the structure pointed to by customerPtr.
g. Member phoneNumber of member personal of structure
customerRecord.
h. Member phoneNumber of member personal of the structure pointed to
by customerPtr.
i. Member address of member personal of structure customerRecord.
5. j. Member address of member personal of the structure pointed to by
customerPtr.
k. Member city of member personal of structure customerRecord.
l. Member city of member personal of the structure pointed to by
customerPtr.
m. Member state of member personal of structure customerRecord.
n. Member state of member personal of the structure pointed to by
customerPtr.
o. Member zipCode of member personal of structure customerRecord.
p. Member zipCode of member personal of the structure pointed to by
customerPtr.
16. Write statements that accomplish each of the following. Assume that the
structure
struct person {
char lastName[ 15 ];
char firstName[ 15 ];
char age[ 4 ];
};
has been defined and that the file is already open for writing.
a. Initialize the file "nameage.dat" so that there are 100 records with
lastName = "unassigned", firstname = "" and age = "0".
b. Input 10 last names, first names and ages, and write them to the file.
c. Update a record; if there’s no information in the record, tell the user
"No info".
d. Delete a record that has information by reinitializing that particular
record.