Sale!

CSC / CIS 175 Problem Solving and Programming – I Homework 4

$40.00 $24.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

1. Drivers are concerned with the mileage obtained by their cars. One driver has kept track of
several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a c++ program that uses a while statement to input the miles driven and gallons used
for each tankful. The program should calculate and display the miles per gallon obtained
for each tankful and print the combined miles per gallon obtained for all tankfuls up to that
point. If the mileage is -1, the program quits.
Sample Output:
Enter Mileage for Trip #1 : 200
Enter Gallons for Trip #1 : 10
MPG for Trip #1 : 20
MPG for all trips so far is 20
Enter Mileage for Trip #2 : 300
Enter Gallons for Trip #2 : 20
MPG for Trip #2 : 15
MPG for all trips so far is 16.6667
Enter Mileage for Trip #3 : -1
Thank you for using our MPG program!
2. Input an integer containing only 0s and 1s (i.e. binary integer) and prints its decimal equivalent. Use the modulus and division operators to pick off the binary digits as before. You
only need to handle a fixed-length, 5-digit binary integer for this question. Assume that the
user will always enter a 5-digit integer.
Sample Output:
Enter a binary number : 11011
Decimal equivalent of 11011 is 27.
3. The process of finding the largest and smallest numbers is used frequently in computer applications. Write a C++ program that uses a while statement to determine and print the
largest and the second largest number of x integers entered by the user, where x should also
be input by the user.
Data set Largest1 Largest2
======== ======== ========
9,9 9 9
9,9,7 9 7
9,9,9,9,9,7,8 9 8
1,1,1,1,8,6 8 6
Sample Output:
(i)
How many numbers do you want to enter? 3
Please enter an integer number 1 9
Please enter an integer number 2 9
Please enter an integer number 3 7
The largest is 9
The Second largest is 7
(ii)
How many numbers do you want to enter? 6
Please enter an integer number 1 1
2
Please enter an integer number 2 1
Please enter an integer number 3 1
Please enter an integer number 4 1
Please enter an integer number 5 8
Please enter an integer number 6 6
The largest is 8
The Second largest is 6
Note: In your output, please contain all four data sets as given above in the table.
4. Salespeople of a company are paid a fixed salary plus a commission based on sales. Base
salary is $200 and commission is 9% of their gross weekly sale. Develop a C++ program that
uses a while statement to input each salesperson’s gross sales for last week and calculates and
displays his earnings. If gross sales entered is -1, the program quits.
Sample Output:
Enter Sales for Salesman #1 : 5000
Salary for Salesman #1 : 650
Enter Sales for Salesman #2 : 6000
Salary for Salesman #2 : 740
Enter Sales for Salesman #3 : 7000
Salary for Salesman #3 : 830
Enter Sales for Salesman #4 : -1
Thank you for using our program!
5. Write a program that reads in the size of a square and then prints a hollow square of that
size out of asterisks and blanks. Your program should work for squares of all sizes between 1
and 20. If the input is greater than 20 or less than 1 use 20 or 1, retrospectively.
Sample Output:
Enter length of side:5
*****
* *
* *
* *
*****
3
Enter length of side:10
**********
* *
* *
* *
* *
* *
* *
* *
* *
**********
Enter length of side:25
Invalid Input
Using default value 20
********************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
********************
4
6. Extra credit (20%) : Extend q2 above to accept variable length binary integer up to 10
digits.
Binary(Input) Decimal(Output)
1 1
11 3
111 7
10101 21
1000000000 512
1111111111 1023
1010101010 682
Note: You do not have to tabulate your output. Just make sure your program will generate
the results as shown in the above table.
5
Deliverables:
1. Source Code: (.cpp file) that must start with a comment block similar to the following:
/*************************************************************************
** Author : Suleyman Uludag
** Program : hw1, q1
** Date Created : September 15, 2013
** Date Last Modified : September 16, 2013
** Usage : No command line arguments
**
** Problem:
Accept the following information from the user (keyboard):
– Hw1, hw2 and hw3 (out of 100)
– Midterm (out of 100)
– Final exam (out of 100)
Calculate the total grade out of 100 based on the following grading scale:
Hws –> 30% (10% each)
Midterm –> 30%
Final Exam –> 40%
** Pseudocode:
** 1)
** 2)
*************************************************************************/
2. Executable (.exe file under windows). You must explicitly state the platform of your executable (such as Linux, etc.) if it is not Windows. Please name your file by using the
question number: hw1-q1.exe (for Windows)
3. Screenshot of your app. For screenshot, you can use the following free program on windows:
http://www.wisdom-soft.com/downloads/setupscreenhunterfree.exe
For Linux/Unix, there are many alternatives. I personally like shutter.
File naming convention example:
hw1 q1.png (or .jpg or another graphics format)
4. You must zip all the above three files into ONE .zip file and submit your assignment by the
deadline on moodle system. Name your file as Lastname-Firstname-hw#.zip. For example,
Uludag-Suleyman-hw1.zip
For generating .zip file, you may use the following free software on Windows:
http://www.7-zip.org/download.html
Linux/Unix has many built-in.
6