0% found this document useful (0 votes)
29 views

Assignment#01

The document provides 7 programming assignments to be completed in C++. The assignments include: 1) Determining if a positive integer is abundant, deficient, or perfect based on the sum of its factors. 2) Finding the top 3 teams from a list of countries and points using nested if-else statements. 3) Finding the second largest number from a set of positive integers entered by the user. 4) Determining the type of triangle that can be formed from 3 integer side lengths. 5) Calculating total retail value from input pairs of product numbers and quantities using a switch statement. 6) Calculating the number of palindromic integers within a given range. 7) Determining if each digit segment of a number is evenly divisible

Uploaded by

mishkatk417
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Assignment#01

The document provides 7 programming assignments to be completed in C++. The assignments include: 1) Determining if a positive integer is abundant, deficient, or perfect based on the sum of its factors. 2) Finding the top 3 teams from a list of countries and points using nested if-else statements. 3) Finding the second largest number from a set of positive integers entered by the user. 4) Determining the type of triangle that can be formed from 3 integer side lengths. 5) Calculating total retail value from input pairs of product numbers and quantities using a switch statement. 6) Calculating the number of palindromic integers within a given range. 7) Determining if each digit segment of a number is evenly divisible

Uploaded by

mishkatk417
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

University of Poonch Rawalakot

Department of Computer Sciences & IT

Course Title: Programming Fundamentals Due Date: 26 Feb, 2024


Marks: 100 Semester: BSDS-1st
Session:Fall-2023 Roll No:
Assignment #01
Implement the following problems in Dev C++/Visual Studio. Copy code and paste it in a word
file. After executing code take a screenshot of output and paste it in word file along with code.
Make sure to submit your own solved assignment. Copied assignments will not be considered.

1. Are You My Type?


Description
Positive integers can be classified as abundant, deficient, or perfect. Abundant integers are
those whose proper factors sum to a larger number. For example, 36 is an abundant number
because its proper factors (1, 2, 3, 4, 6, 9, 12, 18) sum to 55 which is greater than 36.
Deficient integers are those whose proper factors sum to a smaller number. For example,
27 is a deficient integer because its proper factors (1, 3, 9) sum to 13 which is less than 27.
Perfect integers are those whose proper factors sum to exactly that number. For example,
28 is a perfect integer because its proper factors (1, 2, 4, 7, 14) sum to exactly 28. Given a
positive integer value, determine if it is abundant, deficient, or perfect. Also list its perfect
factors and the sum of those perfect factors.

Detailed Requirements

a. Prompt for and accept as input a positive integer having a minimum of one digit. You
do not need to edit this input. Only valid positive integer values will be entered.
b. Read the number from the standard input device.
c. You may use a console application or build a simple GUI application for the input and
output.
d. Display the output as shown in the Test Data below.
e. Each input number can be tested by rerunning the application.
f. The judges will enter additional test data not provided below to further test your
application.

Test Data
Input Output
36 Abundant Factors are: 1 2 3 4 6 9 12 18
Sum is: 55
27 Deficient Factors are: 1 3 9
Sum is: 13
28 Perfect Factors are: 1 2 4 7 14
Sum is: 28
97 Deficient Factors are: 1
Sum is: 1
100 Abundant Factors are:
1 2 4 5 10 20 25 50
Sum is: 117
6 Perfect Factors are: 1 2 3
Sum is: 6

NOTE: There are different definitions for proper factors. For this problem the definition of a
perfect factor is a number that divides evenly into another number. This includes 1 but not the
original number. For example, if the number is 39 then 1 is a perfect factor but 39 is not.
2. Suppose T20 World Cup Teams are at following points:
Countries Points
Pakistan 99
India 52
Bangladesh 80
New Zealand 72
Sri Lanka 45
West Indies 84

Write a C++ Program to find the top three teams Using Nested If –else Statement.

3. Write a program that continuously inputs positive integer values from the user. The user
enters a zero to show that he has no more values to enter. The program should finally
display the second largest number entered.

4. Triangles
Problem Description
Create a program that reads three integer numbers. Each of these numbers represents one side of a
triangle. The program must determine if lines of these three lengths could be used to create a
triangle. If a triangle could be created, the program must further determine if that triangle would be
an equilateral triangle, an isosceles triangle, a right triangle or a regular triangle.
Assume three lines can make a triangle if the sum of the lengths of the two shorter lines is greater
than or equal to the length of the longest line. For example, you can make a triangle given lines of
lengths 5, 3 and 7 because 5 + 3 is greater than 7. However, you cannot make a triangle with lines
of lengths 3, 5 and 9 because 3 + 5 is less than 9.

If the lines can make a triangle, determine if the triangle is an equilateral triangle, an isosceles
triangle, a right triangle or a regular triangle. An isosceles triangle is one in which two of the three
sides are equal and the conditions above are met. An equilateral triangle is one in which all three
sides are equal and the conditions above are met. A right triangle is one in which the sum of the
squares of two sides equals the sum of the square of the third side and the conditions above are met.
For example, a triangle with side lengths of 3, 4 and 5 is a right triangle because 32 + 42 = 52.

Input

Three positive integer values representing the three sides of a triangle will be entered. You do not
need to edit to ensure that only numbers are entered. You may request the input be entered at one
time or use three separate prompts — one for each input value. The values for the line lengths can
be entered in any order. For example, you can't assume that the longest length will always be
entered first, nor can you assume that the lengths will always be entered in descending or ascending
order.

Your values may be input as a single set of data or as a grouping of three individual pieces of data.
Your application can be created to process a single set of data. That is, after processing a set of
data, your application can end. You can then start the application again and enter a second set of
data. If you create a command line application, you can prompt for the input numbers one at a time
or enter them all in a single input statement.

Sample Input/Output
Input Output
345 Right triangle
353 Isosceles triangle
2 10 2 Not a triangle
333 Equilateral triangle
5 10 20 Not a triangle
10 0 5 Not a triangle
7 14 20 Regular triangle
5. Write a program that reads a series of pairs of numbers as follows:
a. product number
b. quantity sold
Your program should use a switch statement to determine the retail price for each
product. Your program should calculate and display the total retail value of all products
sold. Use a sentinel-controlled loop to determine when the program should stop looping
and display the final results.

6. Problem Description

A palindrome is a word that is the same forward as backward: “mom” and “bib” are
examples. Positive integers can be palindromic. For example the numbers 3, 484, 12621,
and 458854 are all palindromic. How many palindromic integers are there between x and
y inclusive given that x will be > 0 and y will be <= 10,000?

Detailed Requirements

a. You will enter an x value and a y value within the above constraints. The x value will
be less that the y value. Each will be an integer. You do not need to edit these numbers.
b. The application must calculate and display the number of palindromes within that
range.
c. Include x and y as potential palindromes. For example, if x = 343 and y = 6226 then
the number of palindromes is at least two because x and y are both palindromes.
d. Add comments at the top of your source code for your name and the problem number.
e. The judges will enter additional test data not provided below to further test your
application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single number indicating how many palindromes exist in the range for each test
case. Format the output exactly as shown in the test data below.

Test Data

X value Y Value
Input Output
55 757 71
1 1000000 1998
11111 100000 889
1 100 18

A sample console interface is provided below. Your user interface is not being judged.
Each set of data can be tested by rerunning the application.

Lower bound:
55
Upper bound:
75
The number of palindromes is 2

7. Magic Numbers
Description
Develop a program that can determine if each segment (starting from the left) of a number
is even divisible by the number of digits in that segment. What? Consider the number
4412. The first segment is 4, the second is 44, the third is 441, and the last segment is
4412. Each of those segments must be evenly divisible by the number of digits in that
segment as shown below to be called a magic number.
Segment Division Remainder
4 4/1 0
44 44 / 2 0
441 441 / 3 0
4412 4412/4 0

Detail Requirements

a. Prompt for and accept as input a positive integer having a minimum of two digits and
at most nine digits. You do not need to edit this input. Only valid values will be entered.
b. You may use a console application for the input and output.
c. Determine if the number has the property described above.
d. Display the output as shown in the Test Data below.
e. Each input number can be tested by rerunning the application.
f. The judges will enter additional test data not provided below to further test your
application.

Test Data
Input Output
987654321 987654321 is not a magic number
4412 4412 is a magic number!
987654 987654 is a magic number!
1234567 1234567 is not a magic number
8. Divisors
Description

Find all numbers between X and Y inclusive that have exactly N even divisors (i.e.
remainder = 0). X, Y, and N are all positive integers greater than zero. Also X < Y. For
example, if X = 4, Y = 14, and N = 3, we want to find all numbers between 4 and 14
(inclusive) that have exactly 3 numbers which divide that number evenly. There are two
numbers that fit this description:

• 4 which is evenly divisible by 1, 2, and 4


• 9 which is evenly divisible by 1, 3, and 9

Detail Requirements

a. Prompt the user to enter X and read it. Prompt the user to enter Y and read it. Prompt
the user to enter N and read it.
b. You do not need to edit the input. Only valid integer values will be entered.
c. You may use a console application or build a simple GUI application for the input and
output.
d. Determine the number of even divisors (remainder = 0) that match N as described
above.
e. Display the output as shown in the Test Data below.
f. Each set of input numbers can be tested by rerunning the application.
g. The judges will enter additional test data not provided below to further test your
application.
Test Data
X Y N
Input Output
4 14 3 49
1 24 6 12 18 20
20 100 5 81
5 100 6 12 18 20 28 32 44 45 50 52 63 68 75 76 92 98 99

9. Prime
Description
A prime number is a number greater than 1 that is divisible evenly only by 1 and itself. Find
each prime number between X and Y that has a palindrome that is also prime. For example
the number 17 is prime and its palindrome, 71, is also prime. X and Y will be integers such
that X > 1 and Y > 1. Also X < Y.

Detail Requirements

a. Prompt the user to enter X and read it. Prompt the user to enter Y and read it.
b. You do not need to edit the input. Only valid integer values will be entered.
c. You may use a console application or build a simple GUI application for the input and
output.
d. Determine each prime number whose palindrome is also prime within the required range
of numbers as described above.
e. Display the output as shown in the Test Data below.
f. Each set of input numbers can be tested by rerunning the application.
g. The judges will enter additional test data not provided below to further test your
application.

Test Data
Input Output
X Y
1000 1050 1009 1021 1031 1033
100 500 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337
347 353 359 373 383 389
5 100 5 7 11 13 17 31 37 71 73 79 97

10. Write a program that prints the following diamond shape. You may use output statements
that print a single asterisk (*), a single blank or a single newline. Maximize your use of
repetition (with nested for statements) and minimize the number of output statements.

You might also like