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 to be successful. Students who do not have the patience to follow the steps WILL have difficulty.
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 grade. 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
// a1.cpp
#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 box 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.
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 $13.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.06. 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the hardcopy source code for this assignment. Staple multiple pages together, if applicable.
You must also upload copies of the source file (named a2.cpp) & the executable file (named a2.exe) to the appropriate drop box in Angel
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 with the following, 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
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. The final price must be a value rounded to the nearest penny. Also, display the message "Invalid input." if the user inputs a quantity that is less than 0 or greater than 50 and immediately display the menu again. Also, if the user inputs a menu choice below 1 or greater than 4, display the message "Invalid input." and immediately display the menu again.
You must use at least 2 functions other than the main function. The functions must be appropriate and effective based on what we have learned about the purpose of functions.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a3.cpp) & the executable file (named a3.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.
Assignment #4:
The program must use a loop to generate 30 random integers between or including 1 and 100 and store those integers into an array.
With a separate loop the program must find and display the maximum value in the array.
Then the program must ask the user to input a value and then search the array for that value with a third loop. If the value is found, the program must display the array position in which the value was found (where the very first position in the array is position zero.) If the value is not found in the array, the program must display the message "Not found".
For full credit, your program must use three loops as described above even if you can simplify the algorithm into fewer loops. Also, you must use this statement srand(1); to initialize the random seed. Do not use srand(time(NULL)); even though it leads to more interesting and varied sets of random numbers.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a4.cpp) & the executable file (named a4.exe) to the appropriate drop box in Angel
(look under the Lessons tab) by the beginning of the class period on the due date.
Assignment #5:
Modify Assignment #3 with the following, additional specifications. The customer's orders will be read as integers from a file named a5input.txt. You can assume that a5data.txt is in the same folder as the exe file. The data in that file will consist of separate integers on separate lines. For example, the file
1
1
2
1
3
1
4
would cause one of each item to be ordered. The data
3
89
3
1.5
4
would cause 1.5 pounds of peanuts to be ordered since the 89 is an invalid quantity.
The output must be written to another file named a5output.txt. No output should be displayed on the monitor. Only the total price should be written there with no other words or symbols such as a $. You may have to specify full file paths when declaring the input and/or output file pointers. See the instructor if you need help with that.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a5.cpp) & the executable file (named a5.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.
Assignment #6:
Modify Assignment #3 with the following, additional specifications. The items' prices will be read as numeric values on separate lines from a file named prices.txt. The items' shipping prices will be read as numeric values on separate lines from a file named shipping_prices.txt. All shipping prices for this assignment will be flat, per item shipping costs. The items' descriptions will be read as one-word strings on separate lines from a file named items.txt. The menu will be created based on the data in items.txt which is guaranteed to have 100 or fewer items. You can assume that the external data files are in the same folder as the exe file. The customer will type input from the keyboard and the final total price must be displayed rounded to the nearest penny. The last menu option must be described as "Checkout". For example, if there are 10 items listed in items.txt then menu option #11 will be "Checkout". You can assume that all 3 data files will have the same number of lines.
You must use 2 or more additional functions which are stored in an include file named "functions.h" that is stored in the same folder as your a6.cpp file.
You may have to specify full file paths when declaring the input and/or output file pointers. See the instructor if you need help with that.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a6.cpp) & the executable file (named a6.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.
Assignment #7:
Modify Assignment #6 with the following, additional specifications. The items prices, shipping prices, and descriptions will be stored as columns in a nicely-formatted spreadsheet that includes column headings. You must manually export that data to a single tab-delimited named a7input.txt that is then read by your program to obtain pricing and description information. Create and use a professional-looking, neatly formatted Excel or other type of spreadsheet as the basis of your exported tab-delimited file. The format of the spreadsheet file must allow for an unspecified number of rows above the data to be used for a nicely-formatted spreadsheet (corporate logo, company name, column headings, etc.) You are guaranteed that the important data in the file will be in the format
Books 9.00 1.03
Movies 13.99 .7
Peanuts 1.80 .5
where the data elements are in separate spreadsheet cell entries. You are guaranteed that the last character in the row above your first item contains a ~ symbol. You will need to check for that symbol in order to determine where the real data begins. You are also guaranteed that there will be no extraneous data below the row with the last element.
You may have to specify full file paths when declaring the input and/or output file pointers. See the instructor if you need help with that.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a7.cpp) & the executable file (named a7.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.
Assignment #8:
Modify Assignment #7 with the following, additional specifications. The original data must be exported from an Excel or other type of spreadsheet as a comma-delimited file named a8input.csv that is read by your program to obtain pricing and description information.
You may have to specify full file paths when declaring the input and/or output file pointers. See the instructor if you need help with that.
No pseudocode or 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.
You must add the line system("PAUSE"); right before return 0; in order to receive any credit for this assignment.
Preconditions:
You must hand in the following on separate pages stapled in this specified order:
You must also upload copies of the source file (named a8.cpp) & the executable file (named a8.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.