CMPSC 101 Programming Assignments

Since the main course objective of CMPSC 101 is to use certain computer programming techniques to solve problems, you will have to complete a number of programs throughout the semester. It is essential that you follow the Programming Process. Write a test plan and pseudocode before you begin to write or type out the actual C++ code. It is also important that you follow the course Coding Standards when you write each program so that it is easy to read your program and so that others can understand your code.

The Programming Process - You must conscientiously follow these steps in order to be successful in writing programs efficiently. Students who do not have the patience to follow the steps WILL have difficulty completing the assignments.

1. Define the problem and understand the given specifications. Create a test plan.
2. Develop an algorithm by writing pseudocode.
3. Code the program by writing it out on paper first.
4. Test and debug the program.
5. Document and maintain the program.

Coding Standards - Hopefully, you will become a better problem-solver throughout this course. However, even if you write a program that displays the proper results, you may miss many points if you do not follow the Coding Standards even to the point of receiving a lower letter grde. Read these guidelines thoroughly. If you have any questions, be sure to consult the instructor and your textbook. Be sure to read the common errors that former CMPSC 101 students have made in the past on their programming assignments.

For each assignment below, be sure to immediately ask the instructor about the specifications if you have any questions. You must choose the proper variable data types for your variables so that the final answer is accurate. Include explanatory input prompt messages where appropriate so that the user knows exactly what to type as inputs. Make sure that your outputs are clearly explained with a word or phrase. Make sure that a dollar symbol is displayed in front of amounts of money.

This rubric will be used to grade your programs.


Assignment #1:

Follow the compiler instructions to create your first C++ source file named a1.cpp. Type the code below exactly as it appears.

// Type your name here
// CMPSC 101
// a1.cpp
// Type today's date here
// Purpose - This program displays a hello world message.

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
      cout << "hello world" << endl;
      system("PAUSE");

      return 0;
}// end of main

Compile and debug the program if necessary. Execute the program. Print the source file by clicking the Visual C++ File/Print... menu command and submit it by the due date.

You must also upload copies of the source file (.cpp) and executable file (.exe) to the appropriate drop boxes in Angel (look under the Lessons tab) by the beginning of the class period on the due date. You will lose points if any file is named incorrectly.


Assignment #2:

On online retailer has hired you to write a program to calculate the total cost of a customer's purchases. The customer may order books, movies, and peanuts. Books are $9 each. Movies are $14.99 each. Peanuts are sold at $1.80 per pound and can be purchased by the tenth of a pound. The shipping cost for each book is $1.03. The shipping cost for movies is 5% of the movie subtotal portion of the order. The shipping charge for peanuts is 50 cents per pound of peanuts ordered.

The program must prompt the user to input the number of books, movies, and peanuts (in lbs.) that he would like to purchase and obtain those amounts in that specified order. The program must then output the total cost of the three orders rounded to the nearest whole dollar.

Your program must be consistent with any sample test plan cases that may have been developed in class and the program must follow our Coding Standards.

Preconditions:

You must hand in the following on separate pages stapled in this specified order:

  1. The hardcopy source code for this assignment. Staple multiple pages together, if applicable.
  2. The typed pseudocode that you used to write out your C++ code.
  3. The typed test plan that you developed before developing an algorithm or writing the C++ code. You must use the test plan format that is specified on the test plan guide.

You must also upload copies of the source file (named a2.cpp), executable file (named a2.exe), the pseudocode (named a2.doc or a2.txt), and the test plan (named a2.xls) to the appropriate drop boxes in Angel (look under the Lessons tab) by the beginning of the class period on the due date. You will lose points if any file is named incorrectly.


Assignment #3:

Modify Assignment #2 to fulfill these additional specifications. The program must use a loop to present the customer with the following exact menu allowing him to make one or more orders for each of the three products if he desires.

1 Books
2 Movies
3 Peanuts
4 Checkout


In this assignment program, the customer is allowed to make two or more separate orders for the same product. For example, the customer may order 3 books and 2 movies but no peanuts. Or, the customer could order 5 books, 1 pound of peanuts, and 3 movies in that order. Or, the customer could order 6 books, 3 movies, and then 2 more books. The customer may choose menu option #4 to exit the program at any time, even if he has made no purchase. But do not allow the customer to make any order that would cause the total amount of purchases plus shipping to go over $200. If he attempts to place an order for an item that would cause the running total to exceed $200, present a message that tells him that he can only spend $200 or less and present him with the menu again. Do not count the last item ordered that caused the running total to go over $200. Your program must display the total amount of money due rounded to the hundredth's place (i.e. the nearest penny). Meeting the specifications outlined above will earn you a maximum grade of 89%.

In order for you to earn a possible 100%, the program must give the customer free shipping if the total amount of purchases (not counting shipping) exceeds $100.

Add the comment "// A version" below your name at the very top of your program if you are going for the 100%. Otherwise, add the comment "// B version". Also, add either the phrase "John Doe A version" or "John Doe B version" as the "Title" in the Angel exe drop box.

Your program must be consistent with any sample test plan cases that may have been developed in class. See this hyperlink for some other sample test cases.

Preconditions:

You must hand in the following on separate pages stapled in this specified order:

  1. The hardcopy source code for this assignment. Staple multiple pages together, if applicable.
  2. The typed pseudocode that you used to write out your C++ code.
  3. The typed test plan that you developed before developing an algorithm or writing the C++ code. You must use the test plan format that is specified on the test plan guide.

You must also upload copies of the source file (named a3.cpp), executable file (named a3.exe), the pseudocode (named a3.doc or a3.txt), and the test plan (named a3.xls) to the appropriate drop boxes in Angel (look under the Lessons tab) by the beginning of the class period on the due date. You will lose points if any file is named incorrectly.


Assignment #4:

Write a program that reads orders of books, movies, and pounds of peanuts from a sequential access file named a4data.txt. The file must be opened from the exact location C:/Temp/a4data.txt. The file will be formatted with a positive integer typed on each line of the file. For example, this sample file would cause the total price of $178.37 to be displayed. The first integer will represent a menu choice, the second will represent the number of items of that menu choice, the third will represent another menu choice, the fourth will represent the number of items of that menu choice, and so on. Use the same menu choices as you did in Assignment #3. The integer 4 will be found at the end of the file to indicate "checkout". Do not display the menu on the screen in this assignment.

After the program has read the sequence of menu choices and number of items purchased, it must display the total amount of the purchased items rounded to the nearest penny. Use the same prices as Assignment #2 including the shipping charges. Finally after the total amount of the purchase, prompt the user to input an order number that he would like to inspect. After he types an order number, display a message in the format "3 books", "3 movies", or "3 pounds of peanuts" and end the program. If he types an order number that is greater than the number of orders that were made, display the message "That order number does not exist" and end the program.

No test plan must be submitted with this assignment, however your program must be consistent with any sample test plan cases that may have been developed or discussed in class.

Preconditions:

You must hand in the following on separate pages stapled in this specified order:

  1. The hardcopy source code for this assignment. Staple multiple pages together, if applicable.

You must also upload copies of the source file (named a4.cpp) & the executable file (named a4.exe) to the appropriate drop boxes in Angel (look under the Lessons tab) by the beginning of the class period on the due date. No pseudocode or test plan is required for this assignment but it is still recommended that you create them in the process of completing the program.