Description
CMSC 140 Programming Project 1
Chapters Covered:
- Chapters 1, 2, and 3
Concepts tested in this project
- To work with cout and cin objects
- To work with variables, constants and literals
- To work with string object
- Use of different data types
- To follow programming style
- Use of basic arithmetic operators
- Use of output manipulators (setw, fixed, setprecision)
Project Description
The Department plans to purchase a humanoid robot. The Chairman would like you to write a program to show a greeting script the robot can use later. Your first task is to use the following script to prototype the robot for presentation:
**************** Robot Prototype Scripting ********************
Hello, welcome to Montgomery College! My name is Nao. May I have your name? john Smith Nice to have you with us today, john Smith! Let me impress you with a small game. Give me the age of an important person or a pet to you. Please give me only a number: 2
You have entered 2. If this is for a person, the age can be expressed as: 2 years or 24 months or about 720 days or about 17280 hours or about 1036800 minutes or about 62208000 seconds. If this is for a dog, it is 14 years old in human age. If this is for a gold fish, it is 10 years old in human age.
Let’s play another game, john Smith. Give me a whole number. 4 Very well. Give me another whole number. 5 Using the operator ‘+’ in C++, the result of 4 + 5 is 9. Using the operator ‘/’, the result of 4 / 5 is 0 however, the result of 4.0 / 5.0 is about 0.8.
Thank you for testing my program!! PROGRAMMER: Your Name CMSC140 Common Project 1 Due Date: |
Write a program that uses the script above as a guide without roles, i.e. robot computer and visitor human, to prototype robot greeting in C++. See the Sample Screen Output below.
Project Specifications
Input
- Visitor’s name
- An age
- Two numbers
Output: The program should display the following data:
- Complete script described above
- Your name as the programmer
- Assignment/Project number
- Due date
Processing Requirements
- The program should declare and initialize (i.e. create and assign values for) variables/constants to hold (at least) the following data:
- Robot Name. This variable will hold the Robot Name. Initialize the variable with “Nao” or a name of your choice.
- Visitor Name, this variable will hold the user’s name.
- This variable will hold a person’s or a pet’s age.
- A constant variable for Programmer’s Name. Initialize the variable with your full name.
- A constant variable for Assignment Number. Initialize the variable with the value 1.
- A constant variable for Due Date. Initialize the variable with the due date of this assignment.
- Constant variables for Days of Month, Human Year, Gold Fish Year. Initialize the variables, for example const int ONE_DOG_YEAR = 7; const int DAYS_PER_MONTH = 30;
- Use the above variables when creating the output of the program, for example:
cout << “My name is “ << robotName;
Where robotName is a variable defined in your program.
- Use the following for the computations in the program :
- 1 month = 30 days
- Dog’s age = 7 times human’s age,
- Gold fish age = 5 times human’s age
Sample Screen Output
NOTE: Be sure to check also
- CMSC140 Common Project Submission Requirements
- CMSC140 Grading Rubric_CheckList-Project 1
Test Plan
Test your program with at least two more test cases. Use the given data as an example. Record your data for input and output in the following table. Make sure your tests cover all the possible scenarios.
Test Case # | Input | Actual Input | Expected Output
|
Actual Output
|
Did the test pass?
|
1 | 2
4 5
|
24
720 17280 1036800 62208000 14 10 9 0 .8
|
|||
2 | |||||
3 | |||||
4 |
CMSC140 Common Project Submission Requirements
Important NOTE:
-If your program does not compile, project will get a grade of “0”. Contact your instructor prior to the project submission due date if you have compilation issues.
-If your project has compilation errors and you are not able to resolve them, try to see your instructor during his/her office hour or go to tutoring session for help prior to project’s due date.
– Check your instructor’s office hours as well as the location and the schedule of the tutoring sessions with your instructor.
Details for Deliverables:
- Word document(docx) or .pdf including:
- Title page including student name, project title and number
- Completed Test Plan table ( given in the project’s description document)
- Screenshot of the program run (using test data from the Test Plan)
- Pseudocode/Flowchart ( if applicable to the project )
- “Lessons Learned” section describing any issues you experienced during work on the project and how you solved them or your overall experience.
- C++ file (source code): FirstInitialLastName_Pr<number>.cpp
Include the following in your code:
Program Header: All programming projects’ source code need to have one block comment at the top of the program containing the course name and CRN, the project number, your name, project description, and the due date. Provide any additional comments as necessary to clarify the program.
Following is a template of the required program header:
/*
* Class: CMSC140 CRN
* Instructor:
* Project<number>
* Description: (Give a brief description for Project)
* Due Date:
* I pledge that I have completed the programming assignment independently.
I have not copied the code from a student or any source.
I have not given my code to any student.
Print your Name here: __________
* Pseudocode or Algorithm for the program:
(be sure to indent items with control structure)
(need to match flow chart submitted in documentation)
1.
2.
3.
4.
5.
(more as needed)
*/
Comments: Add comment to variables, formulas, or any part of the program with the purpose of making the source code easier to understand.
Indentation: It must be consistent throughout the program and must reflect the control structure.
Proper naming conventions: Variable and method names need to be descriptive to show the role of the variable or method. Avoid single letter names. Constant names should be all upper case, variable names should use “camel case” (i.e. start with lower case, with subsequent words starting with upper case: hoursWorked for example) or underscores to separate words (i.e. items_ordered).
- Checklist (grading sheet posted on Blackboard): Specific project checklist and grading rubric worksheet should be completed with your name in the highlighted cell and your initials in the checkboxes.
What to submit on Blackboard?
You need to submit the following two files to Blackboard:
- Word document(docx) or .pdf: FirstInitialLastName_Pr<number>.docx or .pdf
- C++ file (source code): FirstInitialLastName_Pr<number>.cpp
✔ | CMSC140 Grading Rubric – Project 1 | Possible total grade: | 100 | Points Earned: | |||
Name | |||||||
PLANNING | |||||||
Flow chart submitted | 5 | ||||||
Pseudo code provided | 5 | ||||||
Test plan/data provided | 5 | ||||||
TESTING | |||||||
Passes sample data tests | 15 | ||||||
Passes student data tests | 5 | ||||||
Passes private instructor data tests | 65 | ||||||
Possible Sub-total | 100 | ||||||
REQUIREMENTS (Subtracts from PLANNING and TESTING totals) | |||||||
Documentation: | |||||||
Title page is missing or incomplete | -2 | ||||||
Screenprints Screenshots of program run not provided | -3 | ||||||
Learning Experience not included | -4 | ||||||
In 3+ paragraphs, highlight your lessons learned and learning | |||||||
experience from working on this project. What have you learned? | |||||||
What did you struggle with? What would you do differently on your next project? | |||||||
Program header/documentation within source code is missing, incomplete or incorrect | -10 | ||||||
Author’s Name is missing (-2) | |||||||
Function not commented properly (-2) | |||||||
Pseudo code not match program file submitted or incomplete (-6) | |||||||
Deliverables: | |||||||
Deliverables packaged incorrect or incomplete | -3 | ||||||
Programming Style: | |||||||
Incorrect use of indentation, naming convention, lack of white space separating variables, operators, and functions, indentation, etc. (see coding/style standards) | -5 | ||||||
User interface | |||||||
Not clear to user how data is to be entered | -4 | ||||||
Output is not easy to understand | -4 | ||||||
Input validataion not performed or incomplete (not required for first assignment) | -5 | ||||||
Design/Processing: | |||||||
Not use required control structure(s), operator(s) or statement(s) | -20 | ||||||
Use control structure other than sequence without explanation (-10) | |||||||
Not use basic arithmetic operators (-10) | |||||||
Not meet input requirement(s) | -10 | ||||||
Not take all required input | |||||||
Not meet output requirement(s) | -20 | ||||||
Not display or produce all required output (-10) | |||||||
Not use output manipulator: setprecision, fixed, etc. (-10) | |||||||
Not use required data type(s) or data structure(s) | -10 | ||||||
Not use variables, constants and literals (-4) | |||||||
Not use different data types/objects (-3) | |||||||
Not declare and initialize all required data items (-3) | |||||||
Possible decrements: | -100 | ||||||
Possible total grade: | 100 | Points Earned: |
CMSC 140 Programming Project 2
Chapter Covered:
- Chapter 4
Concepts tested in this project
- [ALL concepts from previous projects]
- Selection control structure
- The if statement
- The switch statement (optional)
- Relational operators and logical operators
- Use of relational and logical operators to check numeric ranges
- User friendly
- Use of user friendly user prompt and simple input validation
- Use of meaningful output labels and format
- Use of output manipulators
- Working with string type
- Use of getline()
Project Description
There are two main systems for measuring distance, weight and temperature, the Imperial System of Measurement and the Metric System of Measurement. Most countries use the Metric System, which uses the measuring units such as meters and grams and adds prefixes like kilo, milli and centi to count orders of magnitude. In the United States, we use the older Imperial system, where things are measured in feet, inches and pounds.
Write a program that shows the following menu options and lets the user to convert from Metric to Imperial system:
Converter Toolkit
——————–
- Temperature Converter
- Distance Converter
- Weight Converter
- Quit
- If the user enters 1, the program should ask for the temperature in Celsius and convert it to Fahrenheit
- If the user enters 2, the program should ask for the distance in Kilometer and convert it to Mile
- If the user enters 3, the program should ask for the weight in Kilogram and convert it to Pound
- If the user enters 4, the program should end.
Project Specifications
Input for this project:
- the user must enter an number to select a menu option
- the user must enter temperature in Celsius
- the user must enter distance in Kilometer
- the user must enter weight in Kilogram
- the user must enter a country name
Input Validation:
- Do not accept a number outside the range of 1 through 4 for the menu option. Be sure to display appropriate error message if the input is invalid.
- Do not accept negative numbers for distance and weight. Be sure to display appropriate error message if the input is invalid.
Output: The program should display the following:
- a menu for Converter Toolkit
- temperature in Fahrenheit, distance in miles or weight in pounds
- a country name
- Programmer’s full name
- project number
- a due date
Processing Requirements
- The program should use at least one selection control structure (if – else statement)
- Be sure to convert as specified. For example, convert temperature from Celsius to Fahrenheit, not the other way around.
- Use the following for converting input:
- 1 kilometer = 0.6 mile,
- 1 kilogram = 2.2 pounds,
- The formula for converting Celsius degree to Fahrenheit is:
F = (9/5)*C + 32 where F is the temperature in Fahrenheit and C is the temperature in Celsius
- Convert temperature to a whole number such as 78, distance to two positions after decimal point (for example 84.56) and weight to one position after decimal point (For example 121.6).
Sample Screen Output #1:
Sample Screen Output #2:
Special Project Submission Requirements
Deliverables:
- Intermediate deliverable:
Program design- Flowchart and/or pseudo code for the Program due one week after project is given. An intermediate assignment will be created for submission. Flowchart/pseudo code can be submitted electronically in the following format: word document, pdf or handwritten flowchart/pseudo code picture saved as .jpg or png.
NOTE: Be sure to check also
- CMSC140 Common Project Submission Requirements (.docx)
- CMSC140 Grading Rubric_CheckList-Project 2 (.xlsx)
Test Plan
Test your program with at least two more test cases. Use the given data as an example. Record your data for input and output in the following table. Make sure your tests cover all the possible scenarios.
Test Case # | Input | Actual Input | Expected Output
|
Actual Output
|
Did the test pass?
|
1 | Choice 1
Temp 20
|
68
|
|||
2 | Choice 2
Distance -8 |
Error message | |||
3 | |||||
4 |
CMSC 140 Programming Project 3
Chapter(s) Covered:
- Chapter 5
Concepts tested in this project
- [All concepts covered by previous projects]
- Repetition control structure
- The do.. while/while statements
- The for statement
- Input validation
- Use a repetition control structure for EACH user input
Project Description
The BlueMont chain hotels have 4 different types of room:
Single room: $60/night
Double room: $75/night
King room: $100/night
Suite room: $150/night
The size of the hotel chains in different locations may be different in terms of the number of floors and the type and the number of rooms on each floor.
You are required to write a program that calculates the occupancy rate and the total hotel income for one night and displays this information as well as some other information described below.
The program starts by asking the location where this hotel chain is located and the number of floors in the hotel. The number of floors may not exceed 5. The User then enters the total number of rooms for each floor. The program then asks specifically the number of occupied rooms for each room type on this floor. The total number of rooms on each floor may not exceed 30 and the program should check that the total number of occupied rooms on each floor does not exceed the total of rooms on that floor.
After the information is entered for each floor, the program calculates the following:
– Hotel income (based on the room type and its rate),
– The total number of occupied rooms,
– Total number of the uncopied rooms,
– The rate of occupancy,
– Floor number with the minimum number of rooms. (Assume no two floors have the same number of rooms).
– A message to improve the occupancy rate for the occupancy rate of less than 60%.
– Programmer’s full name
– Project number
– Project due date
Project Specifications
-Use constant variables to hold room rates, max and min # of floors and rooms.
-The program should continuously ask for the correct floor number if it is not within the range of 1 and 5.
-The program should continuously ask for the correct number of rooms for each floor if it is not within the range of 1 and 30.
-The program should repeat the process of asking the number of rooms on the floor and number of occupied rooms if the total number of occupied rooms exceeds the total number of rooms on the floor.
Refer to Sample outputs for more clarification.
Sample output#1
Sample output#2
Sample Output #3
Special Project Submission Requirements
Deliverables:
- Intermediate deliverable:
Program design- Flowchart/ pseudo code for the Program due one week after project is given. An intermediate assignment will be created for submission. Flowchart/pseudo code can be submitted electronically in the following format: word document, pdf or handwritten flowchart/pseudo code picture saved as .jpg or png.
NOTE: Be sure to check also
- CMSC140 Common Project Submission Requirements (.docx)
- CMSC140 Grading Rubric_CheckList-Project 3 (.xlsx)
Test Plan Template
Test your program with at least 3 more test cases. Use the given data as an example. Record your data for input and output in the following table. Make sure your tests cover all the possible scenarios.
Test Case # | Input | Actual Input | Expected Output
|
Actual Output
|
Did the test pass?
|
1 | loc: Washington
#of floors: 0
|
Number of floors should be between 1 and 5. Please try again!! | |||
2 | |||||
3 | |||||
4 |
CMSC 140 Programming Project 4
Concepts tested in this project
- Learn to organize code within a function
- Learn to pass data to and return data from a function
- Use of loops
- Use of output file processing
Project Description
Write a program that calculates the average number of days a company’s employees are absent during the year and outputs a report on a file named “employeeAbsences.txt“.
Project Specifications
Input for this project:
- the user must enter the number of employees in the company.
- the user must enter as integers for each employee:
- the employee number (ID)
- the number of days that employee missed during the past year.
Input Validation:
- Do not accept a number less than 1 for the number of employees.
- Do not accept a negative number for the days any employee missed.
- Be sure to print appropriate error messages for these items if the input is invalid.
Output: The program should display the following data:
- display a user full name
- display a due date
- display the user full name
- Each employee number (ID) and the number of days missed should be written to the report file named “txt“.
- The average number of days a company’s employees are absenting during the year should be written to the report file named “employeeAbsences.txt”.
Processing Requirements
- Create a global variable of type ofstream for the output file. Use this variable to open the file txt in your program to write data to it. A global variable is defined above the main function and its scope is within the entire program.
- Create the following three functions that will be called by the main function:
- A function called NumOfEmployees. This function asks the user for the number of employees in the company. This value should be returned as an int. The function accepts no arguments (No parameter/input).
- A second function called TotDaysAbsent that accepts an arguments of type int for the number of employees in the company and returns the total of missed days as an int. This function should do the following:
- Asks the user to enter the following information for each employee:
- The employee number (ID) (Assume the employee number is 4 digits or fewer, but don’t validate it).
- The number of days that employee missed during the past year.
- Writes each employee number (ID) and the number of days missed to the output file (txt). ( Refer to Sample File Output )
- A third function called AverageAbsent that calculates the average number of days absent.
- The function takes two arguments:
- the number of employees in the company
- The total number of days absent for all employees during the year.
- This function should return, as a double, the average number of days absent.
- This function does not perform screen or file output and does not ask the user for input.
NOTE:
- The location of the file txt created by your program will be in the same folder as your .cpp source file. Make sure to check your file system directory to see if the file is getting created as the result of running your program and its format matches with the format shown in the Sample File output format.
- Also avoid declaring an absolute path for txt, for example e:\\ employeeAbsences.txt or c:\\cmsc140\\employeeAbsences.txt in your program.
Sample Screen Output:
Sample File Output format:
NOTE: Be sure to check also
- CMSC140 Common Project Submission Requirements (.docx)
- CMSC140 Grading Rubric_CheckList-Project4 (.xlsx)
Test Plan Template
Test your program with at least 3 more test cases. Use the given data as an example. Record your data for input and output in the following table. Make sure your tests cover all the possible scenarios.
Test Case # | Input | Actual Input | Expected Output
|
Actual Output
|
Did the test pass?
|
1 | No. of employees :
4 Employee ID’s/Days of absence : 1111 4 1112 5 1113 4 1114 3 |
Total: 16
Average: 4.0 |
|||
2 | No. of employees :
5 Employee ID’s/Days of absence : 1234 2 2234 4 3234 6 4234 9 234 4 |
Total: 25
Average: 5.0 |
|||
3 | |||||
4 |
CMSC 140 Programming Project 5: Magic Square
Chapter(s) Covered:
- Chapter 1-8
Concepts tested by the program:
- Working with one dimensional parallel arrays
- Use of functions
- Use of loops and conditional statements
Project Description
The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below.
The Lo Shu Magic Square has the following properties:
- The grid contains the numbers 1 – 9 exactly
- The sum of each row, each column and each diagonal all add up to the same number.
This is shown below:
Write a program that simulates a magic square using 3 one dimensional parallel arrays of integer type.
Each one the arrays corresponds to a row of the magic square.
The program asks the user to enter the values of the magic square row by row and informs the user if the grid is a magic square or not.
See the sample outputs for more clarification.
Project Specifications
Input for this project:
- Values of the grid (row by row)
Output for this project:
- Whether or not the grid is magic square
- Programmer’s full name
- Project number
- Project due date
Processing Requirements
Use the following template to start your project:
#include<iostream>
using namespace std;
// Global constants
const int ROWS = 3; // The number of rows in the array
const int COLS = 3; // The number of columns in the array
const int MIN = 1; // The value of the smallest number
const int MAX = 9; // The value of the largest number
// Function prototypes
bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max);
bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRowSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
bool checkColSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
bool checkDiagSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
void fillArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
void showArray(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
int main()
{
/* Define a Lo Shu Magic Square using 3 parallel arrays corresponding to each row of the grid */
int magicArrayRow1[COLS], magicArrayRow2[COLS], magicArrayRow3[COLS];
// Your code goes here
return 0;
}
// Function definitions go here
Create and use following functions:
- void fillArray(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size) – Accepts 3 int arrays and a size as arguments, and fills the arrays out with values entered by the user. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square
- void showArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size) – accepts 3 int arrays and a size as arguments and displays their content.
Example:
1 3 5 (arrayRow1)
6 7 9 (arrayRow2)
8 2 4 (arrayRow3)
- bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size) – accepts 3 int arrays and a size as arguments and returns true if all the requirements of a magic square are met. Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
- bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max) – accepts 3 int arrays, a size and a min and max value as arguments and returns true if the values in the arrays are within the specified range min and max. Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
- bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size) – accepts 3 int arrays and a size as arguments, and returns true if the values in the arrays are unique (only one occurrence of numbers between 1-9). Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
- bool checkRowSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size) – accepts 3 int arrays and a size as arguments and returns true if the sum of the values in each of the rows are equal. Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
- bool checkColSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size) – accepts 3 int arrays and a size as arguments and returns true if the sum of the values in each of the columns are equal. Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
- bool checkDiagSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size) – accepts 3 int arrays and a size as arguments and returns true if the sum of the values in each of the array’s diagonals are equal. Otherwise, it returns false. First argument corresponds to the first row of the magic square, second argument to the second row and the third argument to the third row of the magic square.
[NOTE: You can create and use more functions as needed.]
Sample Output
NOTE: Be sure to check also
- CMSC140 Common Project Submission Requirements (.docx)
- CMSC140 Grading Rubric_CheckList-Project 5 (.xlsx)
Test Plan Template
Test your program with at least 3 more test cases. Use the given data as an example. Record your data for input and output in the following table. Make sure your tests cover all the possible scenarios.
Test Case # | Input | Actual Input | Expected Output
Is Magic?
|
Actual Output
Is Magic?
|
Did the test pass?
|
1 | 1 3 2
5 4 9 6 7 8 |
No | |||
2 | 10 2 3
4 15 6 7 8 -8 |
No | |||
3 | 4 9 2
3 5 7 8 1 6 |
Yes | |||
4 |