Starting from:

$25

CSE1321-Assignment 5 Solved

Program 1: Design (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the following 3 methods:

 

Method isValid() returns true if the sum of the width and height is greater than 30

Method Area() returns the area of the rectangle if it is a valid rectangle

Method Perimeter() returns the perimeter of the rectangle if it is a valid rectangle

 

 

The main method of MyRectangle prompts the user to enter the width and height of a rectangle and uses MyRectangle methods to print out a message followed by the area and perimeter if the rectangle is valid. Otherwise, it prints out only the message “This is invalid rectangle. Try again.”.  Note that method isvalid() is used to validate the input before attempting to compute the area and perimeter. 

 

Document your code and properly label the input prompt and the outputs as shown below.

 

Sample run 1:

 

Entered width:  4

Entered height: 5

This is invalid rectangle. Try again

 

Sample run 2:

 

Entered width:  20

Entered height: 15

Area:           300 

Perimeter:      70  

 

Sample run 3:

 

Entered width:  10

Entered height: 5

This is invalid rectangle. Try again.

 

Sample run 4:

 

Entered width:  30

Entered height: 6

Area:           180

Perimeter:      72  

 

 

 

 

Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly.

 

 

Feet
Meter
1.0
0.305
2.0
0.610
3.0
0.915
. . .
. . .
19.0
5.7.95
20.0
6.100
 

 

Meter
Feet
1.0
3.279
2.0
6.558
3.0
9.837
. . .
. . .
19.0
62.301
20.0
65.574
 

The program defines the following methods:

 

Method feetToMeter() converts from feet to meter.  (formula: meter = 0.305 * feet)

Method meterToFeet() converts from meter to feet.   (formula: feet = 3.279 * meter)

 

The main method calls these methods to produce the display the output in tabular format. Document your code and format the outputs as shown above.

 

 

Program 3: Design (pseudocode) and implement (source code) a program (name it PrintTableSeries) to display the following table for the following series:

 

sum(i) = 1/2 + 2/3 + 3/4 + 4/5 + … i/(i+1)

 

 

i
Sum(i)
1
0.5000
2
1.1667
3
1.1960
. . .
 
 

The program defines the following methods:

 

Method displaySums()print the table as shown above.

 

The main method prompts the user to enter an integer value, say n, and then calls method displaySums()to display the table for i = 1 to n. Document your code and format the outputs as shown above.

 

 

Program 4:  A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods:

 

Method isPalindome() to check if  a number is palindrome or not.

Method isPrime() to check if a number is prime or not.

 

In the main method, use a loop structure to invokes these methods and print out the palindromic primes. Document your code and properly format the outputs as shown below.

 

Output format (each x is a palindromic prime number):

 

     x x x x x x x x x x

     x x x x x x x x x x

     x x x x x x x x x x

     x x x x x x x x x x

     x x x x x x x x x x

 

Hint: Use modulus and division by 10 to reverse the number.

More products