HW3 - Programming For Eng

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1411113 Programming for Engineers

Assignment #3
Due Date: 29
th
April 2014
Submission Instructions:
Submit your assignment on the blackboard link, corresponding to your Section:
Please follow the following rules when sending the source code:
1) The name of the file should be q#_myID_section.cpp (for e.g: q1_u000002046_51.cpp)
2) In case two assignments are found to be similar, both students will get ZERO.
Chapter # 6:
1. The Write a program that:
a. Prompts the user to enter a positive integer N.
b. Generates N integers between 7 and 19 inclusive.
c. Prints the integers, the number of odds, and the number of evens.
d. Counts how many odd and how many even integers generated.
Sample input / output:

2. The Write a program that:
a. Prompts the user to enter a positive integer N.
b. Calls the user-defined function isPerfect( ) which checks if N is perfect or not. A
number is perfect if the sum of its divisors other than the number itself. For
example 28 is perfect since 28 = 1 + 2 + 4 + 7 + 14, while 8 is not perfect since 8
1+ 2 + 4
c. Prints a message.
Sample input / output:



Chapter # 7:
3. Write a function (and the main method to test it) that prompts the user to input the
total distance in centimeters. The function then returns the distance in kilometers,
meters, and centimeters.
void distanceKMC(int totalDist, int & km, int & m, int & cm)

4. Write the following program:
A. Write a value-returning function called length() that takes a positive integer and
returns the number of digits in that integer.
B. Using the written function in part A, write a value-returning function called
isPalindrome() that checks if a positive integer is a palindrome or not. A number is
palindrome if it reads the same left to right and right to left. For example 23432 is a
palindrome, while 5675 is not palindrome. The function takes a positive integer and
returns true if the integer is a palindrome and false otherwise.
Test your functions by writing a main function that prompts the user to input an integer
and outputs its number of digits and "It Is a Palindrome" message if it is a palindrome,
otherwise "It Is not a Palindrome".

You might also like