CMPSC 101 Programming Assignments

assignment 1 | assignment 2 | assignment 3 | assignment 4

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. It is also important that you follow the course Coding Standards when you write each program.

The Programming Process - Read Ch. 2, Section 3 of your textbook carefully. 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 programs that follow the given specifications perfectly and work to the degree that they display the proper results, you may miss points if you do not follow the Coding Standards. Read these guidelines thoroughly. If you have any questions, be sure to consult the instructor and your textbook. Take the time to check your program and code thoroughly before submitting it so that you do not lose points for violating these guidelines.


Tentative Assignment #1:

A fruit stand owner wants you to write a program that will allow him to calculate the total cost of a customer's purchase. The customer will buy a certain number of apples, a certain number of pounds of grapes, and a certain number of candy bars. The apples are 53 cents each. Grapes must be purchased by the pound and cost 1.47 per pound. Candy bars are exactly one dollar a piece but are taxed with the state sales tax rate. Prompt the owner to input and obtain the number of apples purchased, the number of pounds of grapes purchased and the number of candy bars purchased. Your program must display an output message along with the total amount due including tax. However, the very first line of your output (before the user makes any inputs) must be your name so that the instructor can easily identify your program when he executes it.

Be sure to ask the instructor about the specifications above if you have any questions since the first step of the Programming Process is to "define the problem and understand the given specifications". 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 answer is explained with a clearly worded, explanatory output message as well. Present the final cost as a number rounded to the hundredth's place (e.g. $78.65) and include a dollar symbol. Trailing zeros such as the zero in the possible price $5.60 must be displayed. Save the source code file as "assignment1.cpp". If the file is not named "assignment1.cpp" exactly, you will not receive any points for the runtime portion of this grade even if your program's logic and output is perfect! There should be no blank spaces and no # symbol in the filename.

One or more sample test plan items will be developed in class. Your program must be consistent with these sample test plan items.

Write a test plan and the pseudocode before you begin to write the code or type the code into C++. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. It is possible to lose many points for violations of these Standards even for a program that executes properly. Be sure to read the common errors that former CMPSC 101 students have made in the past on their programming assignments.

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 writing out the code. (Make sure that you use this test plan to test your program before submitting it.) The test plan must include several reasonable inputs as well as boundary and any other special values. You should include as many test cases as necessary so that the test plan is thorough. If possible, use tables in MS Word or MS Excel to neatly format your test plan however you must see the instructor or someone else to learn how to force Excel to show trailing zeros such as the zero in 5.60.

You must also hand in the source file saved on a floppy disk as assignment1.cpp. It is very important that you name the file as assignment1.cpp exactly. There must be no other computer files or folders on this floppy disk. Use a full-sized blank floppy disk label and label it with your name, the instructor's name, the name of the source file (assignment1.cpp) and the name of the course, CMPSC 101. You will lose points if the file is named incorrectly or if the disk is labelled incorrectly. The floppy disk will not be returned to you after this assignment has been graded.


Tentative Assignment #2:

Modify Assignment #1 to fulfill the following specifications. The customer can choose to buy either apples , grapes, or candy bars. Present the user with the exact menu:

1 Apples
2 Grapes
3 Candy Bars
4 No Purchases

The user will then be prompted to enter the quantity for the item he wishes to purchase. The prices for all items are the same as in Assignment #1 with the following exception. If the user desires to purchase grapes, also ask him for the three-letter abbreviation for the current month (e.g. Jan, Jun, Sep, etc.). If the month is Nov, Dec, Jan, or Feb, use the price of $2.29 per pound of grapes rather than $1.47. Candy bars are still taxed with the 6% PA state sales tax rate. The customer may choose menu option #4, exiting the program immediately without making any purchase. Your program must display an output message along with the total amount due. The very first line of your output (before the user makes any inputs) must be your name so that the instructor can easily identify your program when he executes it.

Be sure to ask the instructor about the specifications above if you have any questions since the first step of the Programming Process is to "define the problem and understand the given specifications". You must choose the proper variable data types for your variables so that the final answer is accurate. You must use a switch statement to organize the logic of the different menu options. Include explanatory input prompt messages where appropriate so that the user knows exactly what to type as inputs. Make sure that your answer is explained with a clearly worded, explanatory output message as well. Present the final cost as a number rounded to the hundredth's place (e.g. $78.65) and include a dollar symbol. Make sure that trailing zeros do display (eg. $2.80 rather than $2.8; hint - use setprecision). Save the source code file as "assignment2.cpp". If the file is not named "assignment2.cpp" exactly, you will not receive any points for the runtime portion of this grade even if your program's logic and output is perfect! There should be no blank spaces and no # symbol in the filename.

Write a test plan and the pseudocode before you begin to write the code or type the code into C++. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. It is possible to lose many points for violations of these Standards even for a program that executes properly. Be sure to read the common errors that former CMPSC 101 students have made in the past on their programming assignments.

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 writing out the code. (Make sure that you use this test plan to test your program before submitting it.) The test plan must include several reasonable inputs as well as boundary and any other special values. You should include as many test cases as necessary so that the test plan is thorough. If possible, use tables in MS Word or MS Excel to neatly format your test plan (Excel can perform the calculations themselves.)

You must also hand in the source file saved on a floppy disk as assignment2.cpp. It is very important that you name the file as assignment2.cpp exactly. There should be no blank spaces and no # symbol in the filename. There should be no other computer files or folders on this floppy disk. Use a full-sized blank floppy disk label and write label it with your name, the instructor's name, the name of the file (assignment2.cpp) and the name of the course, CMPSC 101. You will lose points if the file is named incorrectly or if the disk is labelled incorrectly. The floppy disk will not be returned to you after this assignment has been graded.


Tentative Assignment #3:

Modify Assignment #2 to fulfill the following specifications. The program must use a loop to present the customer with the following menu allowing him to make one order of each 3 products if he desires.

1 Apples
2 Grapes
3 Candy Bars
4 Checkout

For example, the customer could order 3 apples and 4 pounds of grapes. Or, the customer could order 5 apples, 1 pound of grapes, and 3 candy bars. The customer will now choose menu option #4 to exit at any time, even if he has made no purchase. However, the customer should not be allowed to order the same product twice (within the same program execution). If he does choose the same menu choice a second time, prompt him with a message indicating that he cannot make two orders for the same product and display the menu again. Also, do not allow the customer to make any order that would cause the total amount of purchases to go over $100. If he attempts to place an order for an item that would cause the running total to exceed $100, present a message that tells him that he can only spend $100 or less and present him with the menu again. He may place another valid order for the item that he attempted to purchase. If the user has purchased all three items, the program should automatically display the total rounded price as if the user selected the Checkout menu choice. For this assignment, assume that the price of grapes is simply $1.47 per pound no matter what the month. Your program must still display an output message along with the total amount due rounded to the hundredth's place and be sure to include a dollar symbol. Make sure that trailing zeros do display (eg. $2.80 rather than $2.8; hint - use setprecision). When your program executes, your name should appear on the very first line of output so that the instructor can easily identify your program. You must also use at least three functions (besides the main function) to demonstrate modular, structured programming. You must use a function named computeSalesTax with the function prototype

double computeSalesTax(double price);

. This function should receive the price of a taxable item as a double and it should return the amount of the tax on that item. The function should not return the total price with the tax included. The program must also use a void function named menu that uses the function prototype

void displayMenu();

The displayMenu function should only display the menu choices. It should not prompt the user to input a menu choice. Nor should it contain a cin statement that obtains the user's menu choice input. You must also use a function that rounds a value to the nearest hundredths place named roundToPenny.

Be sure to ask the instructor about the specifications above if you have any questions since the first step of the Programming Process is to "define the problem and understand the given specifications". 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 answer is explained with a clearly worded, explanatory output message as well. Present the final cost as a number rounded to the hundredth's place (e.g. $78.65) and include a dollar symbol. Save the source code file as "Assignment3.cpp". If the file is not named "Assignment3.cpp" exactly, you will not receive any points for the runtime portion of this grade even if your program's logic and output is perfect! There should be no blank spaces and no # symbol in the filename.

See this hyperlink for the format that your test plan should follow. By the way, the test cases in this test plan should work perfectly in your final project.

Write a test plan and the pseudocode before you begin to write the code or type the code into C++. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. It is possible to lose many points for violations of these Standards even for a program that executes with perfect output and logic. Be sure to read the common errors that former CMPSC 101 students have made in the past on their programming assignments.

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 writing out the code. (Make sure that you use this test plan to test your program before submitting it.) The test plan must include several reasonable inputs as well as boundary and any other special values. You should include as many test cases as necessary so that the test plan is thorough. If possible, use tables in MS Word or MS Excel to neatly format your test plan (Excel can perform the calculations themselves.)

You must also hand in the source file saved on a floppy disk as Assignment3.cpp. It is very important that you name the file as Assignment3.cpp exactly. There should be no blank spaces and no # symbol in the filename. There should be no other computer files or folders on this floppy disk. Use a full-sized blank floppy disk label and write label it with your name, the instructor's name, the name of the assignment (Assignment #3) and the name of the course, CMPSC 101. You will lose points if the file is named incorrectly or if the disk is labelled incorrectly. The floppy disk will not be returned to you after this assignment has been graded.


Tentative Assignment #4:

You can earn a maximum grade of B (89%) on this assignment if your program reads a list of 100 unordered, random integers from a text file named "Assignment4data.txt" and then stores those 100 values into a one-dimensional array. After closing the text file, your program must then search for the largest odd integer in the array and display that value along with its position within the original list of integers (where the very first integer is considered to be in position one.)

If you wish to earn a maximum grade of an A (100%), then your program must read a list of 100 unordered, random integers from a text file named "Assignment4data.txt" into an array. Your program must then sort the 100 values using any sort algorithm explained in our textbook or studied in this course. Finally, your program must display those 100 values in 50 rows with 2 values each, using a tab between each pair of values on the same line. All 100 values must be able to viewed on the console window after the program has executed. For example:

12 34
156 172
321 etc.

When your program executes, your name should appear on the very first line so that the instructor can easily identify your program.

If the file is not named "Assignment4.cpp" exactly, you will not receive any points for the runtime portion of this grade even if your program's logic and output is perfect! There should be no blank spaces and no # symbol in the filename.

Perform your pseudocode before you begin to write the code or type the code into C++. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. It is possible to lose many points for violations of these Standards even for a program that executes properly. Be sure to read the common errors that former CMPSC 101 students have made in the past on their programming assignments.

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.

    ( No test plan is necessary for this assignment!)

You must also hand in the source file saved on a floppy disk as Assignment4.cpp. It is very important that you name the file as Assignment4.cpp exactly. There should be no blank spaces and no # symbol in the filename. There should be no other computer files or folders on this floppy disk. Use a full-sized blank floppy disk label and write label it with your name, the instructor's name, the name of the assignment (Assignment #4) and the name of the course, CMPSC 101. You will lose points if the file is named incorrectly or if the disk is labelled incorrectly. The floppy disk will not be returned to you after this assignment has been graded.