Study guide - 1. 2. 3. 4. The formatting of your source...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1. The formatting of your source code 2. The use of meaningful identifiers 3. The extent of internal documentation 4. The degree to which an exercises’ specifications are meet Exercise 1: Pen Pricing Create a C++ console application that calculates the price of specially engraved pens based upon the quantity ordered. The vendor charges the following prices based upon the order quantity: 0 - 50 pens 50 cents each 51 - 100 pens 48 cents each 101 - 499 pens 45 cents each 500 or more pens 42 cents each The output of the program should be similar to: 54 pens were ordered at a price of 48 cents each for a total of $25.92. The program must include variables, decision statements and logical operators. Based on the description of the problem – the price is based on the order quantity, we need to use a selection structure to set up a range for the order quantity. In the beginning of the main function, we need to declare and initialize a variable orderQuanity and prompt the user to enter the orderQuanity. In addition to the orderQuanity, we need to declare the penPrice as double. int orderQuanity = 0; double penPrice = 0.0; cout << "Enter the number of Pens to order:" ; cin >> orderQuanity; Our program then need to perform a selection and assign value to penPrice based on the different conditions. if penPrice = .50; else if (orderQuanity >= 51 && orderQuanity <= 100) penPrice = .48; else if penPrice = .45; else
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
if (orderQuanity >= 500) penPrice = .42; At the end of the program, we just need to display our program output like this: 54 pens were ordered at a price of 48 cents each for a total of $25.92. cout << orderQuanity << " pens were ordered at a price of " << penPrice << " cents each for a total of $" << penPrice * orderQuanity << endl; here is the program #include <iostream> #include <iomanip> using namespace std; int main() { //variable declaration double orderTotal = 0.00; double price = 0.42; // declare and enter quantity of pens int penCount; printf("Enter amount of pens you would like to order: "); cin >> penCount; price = .50; (orderTotal = price * penCount); price = .48; (orderTotal = price * penCount); price = .45; (orderTotal = price * penCount); }else{ price = .42; (orderTotal = price * penCount); }
Background image of page 2
printf("The total for your order is: $%.2f, Quantity: %i,Price: %.2f\n", orderTotal,
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/29/2010 for the course ENGINEERIN 305 taught by Professor Martincandell during the Spring '10 term at Rio Hondo College.

Page1 / 10

Study guide - 1. 2. 3. 4. The formatting of your source...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online