Starting from:

$25

CSE1321-Assignment 2 Solved

Program 1: Design (pseudocode) and implement (source code) a program (name it Cylinder) to compute the volume of a cylinder using the following formulas (PI is 3.14):

 

            Area   = radius * radius * PI   Volume = area * length 

 

The program reads the radius and length from the user and then computes the volume. Document your code and properly label the input prompts and the outputs as shown below.

 

 Sample run 1: 

 

Enter radius: 5.5   

Entered length: 12 

The Volume is 1140.4 

 

 Sample run 2: 

 

Enter radius: 1.0   

Entered length: 1.0 

The Volume is 6.28 

 

 Sample run 3: 

 

Enter radius: 6.5   

Entered length: 10.0 

The Volume is 1326.65 

 

 

Program 2: Design (pseudocode) and implement (source code) a program (name it SumDigits) to sum the total of all digits in an input integer number between 0 and 1000. Notice that you need to extract individual digits from the input number using the remainder and division mathematical operators. For example, if the input number is 123,m the sum of its digits is 6. Document your code and properly label the input prompts and the outputs as shown below.

 

 Sample run 1: 

 

Entered number: 123 

Sum of digits:  6 

 

 Sample run 2: 

 

Entered number: 5588 

Sum of digits:  26 

 

 Sample run 3: 

 

Entered number: 100 Sum of digits:  1 Program 3: Design (pseudocode) and implement (source code) a program (name it Distance) to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formals is:

 

Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] 

 

Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs.  

 

 Sample run 1: 

 

Entered X1: 1.5 

Entered Y1: -3.4 

Entered X2: 4 

Entered Y2: 5 

Distance:   8.764131445842194 

 

 Sample run 2: 

 

Entered X1: -5.5 

Entered Y1: -8.8 

Entered X2: 25 

Entered Y2: 4.5 

Distance:   33.27371334852784 

 

 Sample run 3: 

 

Entered X1: 2 

Entered Y1: 2 

Entered X2: 10 

Entered Y2: 10 

Distance:   811.313708498984761 

 

 

Program 4: Design (pseudocode) and implement (source code) a program (name it

DrivingCost) to compute the cost of a road trip. The program prompts the user to enter the distance to be traveled, the car fuel efficiency (mile per gallon), and the fuel cost per gallon. The program computes and displays the trip cost. Document your code and properly label the input prompts and the outputs as shown below.

 

 Sample run 1: 

 

Distance traveled (miles): 100 Miles per gallon (miles): 20 

Price per gallon (dollars): 2.0 

Trip cost (dollars): 10.00 

 

 Sample run 2: 

 

Distance traveled (miles): 500 

Miles per gallon (miles): 35 

Price per gallon (dollars): 2.50 

Trip cost (dollars): 35.71 

 

 

 Sample run 3: 

 

Distance traveled (miles): 78 

Miles per gallon (miles): 25 

Price per gallon (dollars): 3.0 

Trip cost (dollars): 9.36 

 

More products