0% found this document useful (0 votes)
17 views9 pages

CMSC140 Classwork 6 - Updated103123

Uploaded by

davebeshir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

CMSC140 Classwork 6 - Updated103123

Uploaded by

davebeshir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

CMSC140 Programming Classwork 6

Classwork Requirements:

This classwork consists of two different parts. For each part you need to submit a separate cpp
and word/pdf document.

Part 1:
Develop a program that allows the user to choose addition or subtraction operations on two
whole numbers entered from the keyboard.
Input Process Output
1. Choice of operation Validate the choice, Result of operation
2. First number If choose to perform
3. Second number operation, add two numbers;
otherwise, subtract two
numbers

Note:
 Break the problem into smaller piece(s).
 Your functions’ signature should match the given flowcharts in the file attachment.

Main

Input Process Output

getChoice validateChoice getNumbers addition subtraction displayResult


getChoice
validateChoice getNumbers addition subtraction
(choice) (&num1, &num2) (num1, num2) (num1, num2)

Ask user for


choice of
operationn Validates the
choice of 1 or 2
Result = Result = num1-
num1+num2 num2
Save Ask for two
choice numbers

returns
whether the return return
return
choice is (result) (result)
(choice)
valid or not

addition
(num1,
 You must declare function prototypes above main function and define the functions
below main function.

Example Output:

Submit:

 C++ file (source code): FirstInitialLastName_CW6_Part1.cpp


 A document named FirstInitialLastName_CW6_Part1.docx/doc/pdf which includes
screenshots of your output.
o A screenshot of invalid choice
o A screenshot of choice of addition
o A screenshot of choice of subtraction
Part 2:Develop a program working as a soda vending machine. The program should show
the product menu with price and take user input for product number, quantity and pay amount.
The output should show the total sale price including tax and the change.
The tax amount, total purchase and change amount must be displayed in decimal.
Input Process Output
1. Product Number 1. Show menu 1. Total Purchase
2. Product Quantity 2. Calculate purchase 2. Tax (6% of Total Purchase)
3. Payment Amount 3. Take payment 3. Change
4. Calculate tax
5. Calculate Total purchase
6. Calculate Change
showMenu

showMenu function:

1. Displays the menu choices.


2. Prompts the user for the choice
Show menu: 3. Reads the choice
1. Coke $1.25 4. Saves the price of the choice
2. Pepsi $1.00 5. Returns the price of the choice
3. Water $2.00
4. Coffee $1.50
5. Exit Menu

takePurchase
(price) takePurchase function:
Prompt for choice
1. Prompts the user for quantity
2. Reads the quantity
3. Returns the purchase price (price *
quantity)
Sample Outputs:
Prompt for quantity
Save price

displayInfo
Return Price of choice Save quantity (purchase, payment)

Return (price *quantity)


Calculate tax
takePayment (6% of purchase)

Prompt for Calculate total purchase


payment amount (purchase+ Calculated tax)

General
Save payment Requirements:
amount
 Name your source file FirstInitialLastName_CW_[classwork #].cpp
Calculate change (payment -total
Include the following in your code in C++ source .cpp: purchase)
o Program Header: All programming projects’ source code need to have one block
Return (payment)
comment at the top of the program containing the course name, CRN, the project
number, your name, project description, and the due date.
o Provide any additional comments as necessary to clarify the program.
Display calculated values
Following is a template of the required program header:
/*
* Class: displayInfo function: CMSC140 CRN
* Instructor:
* 1. It calculates tax by multiplying Project<number>
* purchase by 6% Description: (Give a brief
description 2. It calculates total purchase cost; for Project)
* Due Date: purchase+ Calculated tax
* I pledge 3. It calculates change amount due that I have completed the
programming to the customer; payment -total assignment independently.
I have not purchase copied the code from a
student or 4. It displays tax, total purchase any source.
I have not cost and change due. given my code to any
student.
Print your Name here: __________
*/
takePayment function:

1. Prompts the user for


payment
2. Reads the payment
3. Stores the payment
4. Returns the payment
o Indentation: It must be consistent throughout the program and must reflect the
control structure.
o 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).
o Comments: If your variable/constant names are not descriptive to show the
role of the variable or method, add comment to variables, formulas, or any
part of the program with the purpose of making the source code easier to
understand.
Grading Criteria Points

The classwork part 1 with correct name and requirement has been 30
submitted.

Word document part 1 with correct name and requirement has been 20
submitted.

The classwork part 2 with correct name and requirement has been 30
submitted.

Word document part 2 with correct name and requirement has been 20
submitted.

100

Classwork Specific Points Deducted:
Part 1:
Section (i) has not used while loop -10
Section (ii) has not used do-while loop -10
Other sections have not used nested for loop -10
Part 2:
Full name is not read and stored using one read statement. -5
Full name is not read and stored. -5
Phone number is not read and stored. -5
Street address is not read and stored. -5
City is not read and stored. -5
State is not read and stored. -5
Zip code is not read and stored. -5
File is not saved correctly -5
Data is not displayed correctly from file to the console. -5
Wrong file name has been used -5
General Points Deducted:

Program does not compile (0 Points) -100


Wrong cpp file name/format -10

Program does not pass sample data tests -10


Program does not pass instructor data tests. -10
Program does not run with desired output -50

Incorrect use of indentation, naming convention, etc. -10

cpp file missing header comments -10

Wrong word document file name/format -10

Missing Screenshots of your program run -10

Not use variables, constants, and literals -3


Not declare and initialize all required data items -3
Grading Criteria Points

The classwork part 1 cpp has been submitted 30


Document part 1 has been submitted. 20
The classwork part 2 cpp has been submitted 30
Document part 2 has been submitted. 20
100

Classwork Specific Points Deducted:
Part 1:
getChoice function is not declared, implemented or called correctly -10
validateChoice function is not declared, implemented or called correctly -10
getNumbers function is not declared, implemented or called correctly -10
addition function is not declared, implemented or called correctly -10
subtraction function is not declared, implemented or called correctly -10
displayResult function is not declared, implemented or called correctly -10
The result is not displayed correctly -10
Part 2:
showMenu function is not declared, implemented or called correctly -10
takePurchase function is not declared, implemented or called correctly -10
takePayment function is not declared, implemented or called correctly -10
displayInfo function is not declared, implemented or called correctly -10
Tax or purchase or change is not calculated correctly -5
General Points Deducted:

Program does not compile (0 Points) -100


Wrong cpp file name/format -10
Wrong screenshot document file name/format -5
Missing Screenshots of your program run -10
Program does not pass sample data tests -10
Program does not pass instructor data tests -10
Incorrect use of indentation, naming convention, etc. -3
Missing header comments in cpp file -3
Not use variables, constants, and literals, where appropriate -3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy