This assignment is about operators, expressions, data types, and selection statements. Arrays, functions, and loops are not allowed. The only libraries allowed for this assignment are <iostream>
and <iomanip>
. This assignment is to be completed individually. You are not allowed to share your code with other students. The assignment is worth a total of 100 points. If you have any questions or need any help, please visit us during office hours and/or post questions on Piazza.
If you need to post any of your actual source code on Piazza for any reason, please be sure to tag the post as being visible to instructors only, so that you don't inadvertently share code with others and violate class rules.
Your submission will be tested and graded by an autograder, for this reason it cannot be stressed enough that your program must exactly follow the specifications for input and output upon submission.
If the question specifies that it will take a double
then a char
you must follow this input order or else fail the test. For this assignment, you should use the int
data type for regular whole numbers and as the default when a number format is not specified, you should use the double
data type for any question which specifies decimal or floating point numbers, and char
for single letter variables or input.
The output will always be some form of string printed out on a single line. It will always begin on a new line and end with some form of newline character; either std::endl
or '\n'
. Whenever printing a double
you should always have exactly 4 decimal places; if your decimal number is 3.1415926534
, you should print it as 3.1416
. If your number is 0.0
or 0
, it should print as 0.0000
. You can use <iomanip>
to accomplish this.
For details on expected submission instructions, please refer to the Submission and Grading section at the bottom of the document.
-
Addition. This program should prompt the user for two numbers, then output the following string:
<a> + <b> = <c>
wherea
is the first number given,b
is the second, andc
is the sum. (eg.5 + 7 = 12
). -
Subtraction. Prompt the user for two numbers, then output the following string:
<a> - <b> = <c>
similar to problem 1 except using subtraction instead of addition. -
Division. Prompt the user for two integer numbers, then output the following string:
<a> / <b> = <c>
. Integer division can lose precision as we discussed in lab, but we won't worry about that here. -
All. Making individual programs to perform basic operations is repetitive and not good coding practice, it would be better to create one program which can add, subtract, divide, and multiply two numbers depending on user input. For this program you will read two integers
a
andb
from the user and an operator characterc
. Eg.2 5 *
will multiplya
andb
and output the string2 * 5 = 10
,5 2 /
will dividea
byb
and output the string5 / 2 = 2
. Don't worry about validating input, the auto-grader will only give you legal numbers and one of the four basic operator characters+ - * /
. -
Odd or even. Sometimes it will be useful to know whether a given number is odd or even. This program should read a single integer number from the user and print whether or not the provided number is even or odd. The output should be a single line formatted as follows:
<number> is <odd|even>
wherenumber
is replaced by the user input, andodd
oreven
is printed depending on whether or not the number is odd or even. You are encouraged to use the ternary operator to complete this program. -
Positive or negative. This program should prompt the user for an integer number and print whether the provided number is positive or negative. The output should be a single line formatted as follows:
<number> is <positive|negative>
. If the number is zero, the output string should instead print<number> is neither positive nor negative
. -
Larger than 100 and multiple of 8. Prompt the user for an integer value. If the number is both a multiple of 8 and is larger than 100, the single line
<number> satisfies the criteria
should be printed. If the number does not satisfy both criteria, print out<number> does not satisfy the criteria
-
Last digit is 9. Prompt the user for an integer number. If the last digit of the entered number is 9, print
<number> is good
, otherwise, print<number> is no good
. Some examples of "good" numbers would be: 9, 19, 1279, 999, 699, 1029 etc. -
Privileges. This program should prompt the user for an integer representing age, then output one of the following:
Too young
for an age under 16;Can drive
for those in the interval [16, 18);Can join the military
[18, 21) and finallyCan have a beer
for ages greater than or equal to 21. -
Word for number. Prompt the user for a digit [0, 9] and print out the name of that digit as a string. Entering
9
should outputNine
, entering7
should outputSeven
etc. An number outside of the specified range should printNot a valid number
. Use aswitch
statement for this problem. -
Date converter. Prompt the user for three integers representing their birthday in the order
<month> <day> <year>
. Print the given date as a string on a single line in the following format:<month name> <day>, <year>
.10 3 1997
should outputOctober 3, 1997
,1
1
2000
should outputJanuary 1, 2000
etc. If a month does not exist, print outImaginary month
. -
Average. Prompt the user for three decimal values and print the average of the three in the format:
The average of <num1>, <num2>, and <num3> is <average>
. -
Smallest number. This program should prompt the user for three integer values, and determine which number is the smallest. The output string should be formatted as follows:
The smallest number entered was <number>
. -
Which quadrant. In mathematics, 2-dimensional cartesian systems can be segmented into four quadrants, depending on whether
x
andy
are positive and negative. For example, (1.0,1.0) falls inQuadrant 1
. This program should take anx
andy
coordinate from the user in that order, then output which quadrant that point falls into, in the format:Quadrant 1
,Quadrant 2
etc. If the point falls on thex-axis
or they-axis
, printNo quadrant
. Usedouble
for the coordinate points in this problem. -
Is it cold out? A student from Rhode Island is visiting Germany but doesn't understand Celsius very well. They want to be able to tell whether it is cold out or not without going outside, so they write a program to tell them how cold it is. This program should take a
decimal
number representing Celsius as input and determine its Fahrenheit equivalent. If the F temperature is less than or equal to 32 degrees, the program should printIt is cold out
, if the temp is (32, 65], the program should printWear a jacket
, if it is above 65, printIt is nice out
. -
Temperature converter. This program should prompt the user for two arguments, first a decimal number and second, a single letter, either
C
orF
. The decimal represents a temperature, the character represents which system that degree is in (50.0
F
would be 50.0 degrees Fahrenheit etc.). This program should take the given number and convert it to a temperature in the other system. The output string format should be<input num> degree(s) <input system> is equal to <new num> degree(s) <other system>
. Eg. input0
C
would give the string0.0000 degree(s) C is equal to 32.0000 degree(s) F
. You can assume that eitherF
orC
will be given for input, no need to account for invalid input. -
Grades. This program should prompt the user for a single character as an argument, this character should represent a letter grade. The program should print a single-line string for each different grade.
Grade Letter Output A Excellent
B Good
C Average
D Poor
F Failing
Additionally, the case of the letter should not matter. A
, a
, B
, b
, etc. should all be acceptable input for the program.
- Day of the week. This program takes in three integers, representing
day
month
year
in that order, and should output the day of the week associated with the given date. The formula used to calculate the date is:
- day is the day of the month (1, 2, 3, etc.).
- century is equal to (year / 100). For 2019, century would be 20.
- yearpart is the year within the century (year mod 100). For 2019, year would be 19.
- month is the month of the year, we typically associate the months as January = 1, February = 2, March = 3, etc. This is the case for this program for all cases except for January and February. Due to the way the formula works, specifically January and February must be entered into the above formula as months 13 and 14 of the previous year. This is to say that if you wanted to know which day of the week January 5, 1997 fell on, you would need month = 13, day = 5, year = 1996 when the values enter the formula. Your program should take them in as regular format
5 1 1997
and treat them differently once they have been read. - The value weekday resulting from the equation will be a number [0,6] where Saturday = 0, Sunday = 1, etc.
The output of your program should be a single string name of the appropriate weekday. If the formula outputs 0, your output will be Saturday
and so on.
- Triangles. This program should take as arguments, three interior angles of a triangle (for simplicity we will take only
integer
values for angles), it should classify the triangle as one of the three types of triangles (Acute
,Right
, andObtuse
) and print that label to the console as output. Additionally, if the triangle given is impossible (sum of interior angles does not equal 180) the program should not print any labels, and should instead printThis triangle is impossible
.
You will submit a single zip file named pa1.zip
through Gradescope. Your zip archive must contain your source files only. For each of the problems, create a file called main_<num>.cpp
where num is the question number itself with no leading zeros. Ensure all of your code resides within the main()
function within that file. All programs must compile and execute without warnings. Your programs will be automatically graded. For each of the questions you either pass the test cases (full points) or not (zero points).
You must be reminded that students caught cheating or plagiarizing will receive
no credit
. Additional actions, including a failing grade in the class or referring the case for disciplinary action, may also be taken.