+1(978)310-4246 credencewriters@gmail.com
  

Description

Gannon University
Department of Computer and Information Science
CIS 219: Linux Programming
Homework 03 (Due Date: April 08th, 2021, 23:59)
Instructions:
§
§
This is an individual assignment and no two students should have the same or similar code. Don’t
share your code with anyone else. In case you need a clarification, please feel free to ask me.
Save all your program source code (.cpp files) in one folder called
CIS219_HW3_FirstName_LastName.zip the folder and only uploaded the zipped folder.
1. (Variables and Expressions) Write a C++ program that calculates a car’s gas mileage. The
program should ask the user to enter the number of gallons of gas the car can hold, and the
number of miles it can be driven on a full tank. It should then display the number of miles
that may be driven per gallon of gas.
2. (Conditions and Loops) Write a C++ program that plays the game of “guess the number” as
follows: Your program chooses the number to be guessed by selecting an integer at random
in the range of 1 to 100. The program then displays the following:
I have a number between 1 and 1000.
Can you guess my number?
The plater then types a first guess. The program responds with one of the following:
Excellent! You guessed the number!
Would you like to play again (y or n)?
Too low. Try again.
Too high. Try again.
If the player’s guess is incorrect, your program should loop until the player finally gets the
number right. Your program should keep telling the player Too High or Too low to help
the player “zero in” on the correct answer.
The program should also count the number of guesses that the player makes. If the number
is 10 or fewer, the program should print “Either you know the secret, or you got
lucky!”. If the player guesses the number in 10 tries, then print “Ahah! You know the
secret!”. If the player makes more than 10 guesses, then print “You should be able to
do better!”.
3. (Conditions and Loops) The distance a vehicle travels can be calculated as follows: distance =
speed * time. For example, if a train travels 40 miles per hour for 3 hours, the distance
traveled is 120 miles. Write a C++ program that asks the user for the speed of a vehicle (in
miles per hour) and how many hours it has traveled. The program should then use a loop to
1
display the distance the vehicle has traveled for each hour of that time period. Here is an
example of the output:
What is the speed of the vehicle in mph? 40
How many hours has it traveled? 3
Hour
Distance Traveled
—————————————1
40
2
80
3
120
Input validation: Do not accept a negative number for speed and don’t
accept any value less than 1 for time traveled.
1. (Functions) Write a C++ program (call it Triangle.cpp) that computes and prints out the
perimeter and area of a triangle given its three sides a, b and c. Note that side b is the base
of the triangle. Use two functions perimeter(a, b, c) and area(a, b, c) in your program that use
the following formulae.
!”#$%”&”# = ( + * + +
a
,#”( = ./(/ − ()(/ − *)(/ − +)
(+*++
3â„Ž”#” / =
2
c
b
2. (Functions) Write a C++ program (Mortgage.cpp) that computes the monthly mortgage
payment for a given mortgage and the total amount paid over the term of that mortgage.
Your code should prompt the user for loan amount, the loan term (in years) and the yearly
interest rate. The program should have two functions, one function computing the monthly
payment given by the following formula and another function computing the total payment.
(25 points)
;7(8 ∗ =(&” ∗ (1 + =(&”)!”#$%&
678&â„Ž9: !(:%”8& =
(1 + =(&”)!”#$%& − 1
Where Loan is the loan amount, months is the loan term (in months), and rate is the
monthly interest rate (i.e., the yearly rate divided by 12).
For example,
Enter the loan amount (in dollars): 200000
Enter the loan term (in years): 30
Enter the yearly interest rate (as a percentage): 4.5
2
Your monthly payment will be $1013.37
After 30 years, your payments will total $364813.2
3

Purchase answer to see full
attachment

  
error: Content is protected !!