0% found this document useful (0 votes)
21 views2 pages

2 - Chapter 2 - Introduction To C++

introduction about c++

Uploaded by

kayntran283
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

2 - Chapter 2 - Introduction To C++

introduction about c++

Uploaded by

kayntran283
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 2

1. Convert the following pseudocode to C++ code. Be sure to define the appropriate
variables
a. Store 20 in the speed variable.
Store 10 in the time variable.
Multiply speed by time and store the result in the distance variable.
Display the contents of the distance variable.

b. Store 172.5 in the force variable.


Store 27.5 in the area variable.
Divide area by force and store the result in the pressure variable.
Display the contents of the pressure variable.

2. Find the Error


There are a number of syntax errors in the following program. Locate as many as you can.

*/ What's wrong with this program? /*


#include iostream
using namespace std;
int main();
}
int a, b, c \\ Three integers
a = 3
b = 4
c = a + b
Cout < "The value of c is %d" < C;
return 0;
{

3. Annual Pay
Suppose an employee gets paid every two weeks and earns $2,200 each pay period. In a year the
employee gets paid 26 times. Write a program that defines the following variables:

payAmount This variable will hold the amount of pay the employee earns each pay period.
Initialize the variable with 2200.0.

payPeriods This variable will hold the number of pay periods in a year. Initialize the variable
with 26.

annualPay This variable will hold the employee’s total annual pay, which will be calculated.
The program should calculate the employee’s total annual pay by multiplying the employee’s pay amount
by the number of pay periods in a year and store the result in the annualPay variable. Display the total
annual pay on the screen.

4. Stock Commission
Kathryn bought 750 shares of stock at a price of $35.00 per share. She must pay her stockbroker a 2
percent commission for the transaction. Write a program that calculates and displays the following:

• The amount paid for the stock alone (without the commission)
• The amount of the commission
• The total amount paid (for the stock plus the commission)

5. Energy Drink Consumption


A soft drink company recently surveyed 16,500 of its customers and found that approximately 15 percent
of those surveyed purchase one or more energy drinks per week. Of those customers who purchase
energy drinks, approximately 58 percent of them prefer citrus-flavored energy drinks. Write a program
that displays the following:

• The approximate number of customers in the survey who purchase one or more energy drinks
per week
• The approximate number of customers in the survey who prefer citrus-flavored energy drinks

You might also like