{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 (orderQuanity >= 0 && orderQuanity <= 50) penPrice = .50; else if (orderQuanity >= 51 && orderQuanity <= 100) penPrice = .48; else if (orderQuanity >= 101 && orderQuanity <= 499) penPrice = .45; else
Image of page 1

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

View Full Document Right 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; if((penCount>0 && penCount <50)){ price = .50; (orderTotal = price * penCount); }else if((penCount>51 && penCount <100)){ price = .48; (orderTotal = price * penCount); }else if((penCount>100 && penCount <499)){ price = .45; (orderTotal = price * penCount); }else{ price = .42; (orderTotal = price * penCount); }
Image of page 2
printf("The total for your order is: $%.2f, Quantity: %i,Price: %.2f\n", orderTotal,
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern