csci p fall assignment 2 - college of saint benedict … 351 – parallel programming fall, 2015...

10
CSCI 351 PARALLEL P ROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Sample run (user inout in bold): Ente r 2 numbe rs : 5 20 20 is larger Ente r 2 numbe rs : 5 7 Numbers are equal Answer:

Upload: trantuyen

Post on 13-Mar-2018

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

CSCI 351 – PARALLEL PROGRAMMING

FALL, 2015

Assignment 2

Do Q2, Q5, Q7, Q8, Q10.

Q1.c Write a program that asks the user to enter two integers , obtains the numbers from the user, then prints the larger number followed by the

words “is larger.” If the numbers are equal, print the message “These numbers are equal .”

Sample run (user inout in bold):

Enter 2 numbers : 5 20

20 is larger

Enter 2 numbers : 5 7

Numbers are equal

Answer:

Page 2: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q2.c Write a program that reads in the radius of a ci rcle and prints the ci rcle’s diameter, ci rcumference and area. Use the constant value

3.14159 for π. Perform each of these calculations inside the printf s tatement(s ) and use the conversion speci fier %f.

Sample run:

Answer:

Page 3: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q3.c Write a program that reads in two integers and determines and prints i f the fi rs t is a multiple of the second.

Sample runs :

Answer:

Page 4: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q4.c Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording

miles driven and gallons used for each tankful .

Develop a program that will input the miles driven and gallons used for each tankful . The program should calculate and displa y the miles per

gallon obtained for each tankful . After processing all input information, the program should calculate and print the combined miles per

gallon obtained for all tankfuls . Here is a sample input/output dialog:

Sample run:

Answer:

Page 5: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q5.c Develop a C program that will determine i f a department s tore customer has exceeded the credit limit on a charge account. For each

customer, the following facts are available:

1. Account number

2. Balance at the beginning of the month

3. Total of all i tems charged by this customer this month

4. Total of all credits applied to this customer's account this month

5. Allowed credit limit

The program should input each of these facts , calculate the new balance (= beginning balance + charges – credits), and determine if the new

balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the customer's

account number, credit limit, new balance and the message “Credit limit exceeded.” Here is a sample input/ output dialog:

Sample run:

Answer:

Page 6: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q6.c One large chemical company pays i ts salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales

for that week. For example, a salesperson who sells $5000 worth o f chemicals in a week receives $200 plus 9% of $5000, or a total of $650.

Develop a program that will input each salesperson's gross sales for last week and will calculate and display that salesperson's earnings .

Process one salesperson's figures at a time.

Sample run:

Answer:

Page 7: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q7.c Write a program that es timates the value of the mathematical constant e by using the formula:

Sample run:

Answer:

Q8.c Write a program that calculates and prints the sum of the even integers from 2 to 30

Sample run:

Answer:

Page 8: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q9.c Function floor may be used to round a number to a speci fic decimal place. The s tatement y = floor( x * 10 + .5 ) / 10; rounds x to the

tenths position (the fi rst position to the right of the decimal point). The statement y = floor( x * 100 + .5 ) / 100; rounds x to the

hundredths posi tion (i .e., the second position to the right of the decimal point).

Wri te a program that defines four functions to round a number x in various ways

a) roundToInteger( number )

b) roundToTenths( number )

c) roundToHundreths( number )

d) roundToThousandths( number )

For each value read, your program should print the original value, the number rounded to the nearest integer, the number rounded to

the nearest tenth, the number rounded to the nearest hundredth, and the number rounded to the nearest thousandth.

Sample run:

Answer:

Page 9: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q10.c Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the fi rs t. The function should

take two integer arguments and return 1 (true) i f the second is a multiple of the fi rs t, and 0 (false) otherwise. Use this fu nction in a program

that inputs a series of pairs of integers .

Sample run:

Answer:

Page 10: CSCI P FALL Assignment 2 - College of Saint Benedict … 351 – PARALLEL PROGRAMMING FALL, 2015 Assignment 2 Do Q2, Q5, Q7, Q8, Q10. Q1.c Write a program that asks the user to enter

Q11.c Use a double-subscripted array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a

day, each salesperson passes in a slip for each different type of product sold. Each slip contains:

a) The salesperson number

b) The product number

c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write

a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored

in the double-subscripted array sales. After processing all the information for last month, print the results in tabular format with each of the columns

representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product

for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should in clude these cross totals to

the right of the totaled rows and to the bottom of the totaled columns.

Sample run:

Answer:

Online Submission Instructions:

Copy the folder <<yourname>>Asg2(e.g. JohnDoeAsg2) wth Q2.c, Q5.c, Q7.c, Q8.c,Q10.c to /usr/people/handin/CS160 before the deadline

posted in the class website.