You are on page 1of 24

Page 1 of 24

University of Poonch Rawalakot


Department of Computer Sciences & IT
Name:-laiq Uz zaman. Roll number:-07
Course:- : Programming Fundamentals. Semester:-BSDS-1st.
Assignment#01

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.

Code:-
#include <iostream>

using namespace std;

int main() {

int num;

cout << "Enter a positive integer: ";

cin >> num;

if (num <= 0) {

cout << "Invalid input: Please enter a positive integer." << endl;

return 1;

int sum = 0;

cout << "Proper factors of " << num << ": ";

for (int i = 1; i < num; i++) {


Page 2 of 24

if (num % i == 0) {

cout << i << " ";

sum += i;

cout << endl;

if (sum > num) {

cout << num << " is an abundant number." << endl;

} else if (sum < num) {

cout << num << " is a deficient number." << endl;

} else {

cout << num << " is a perfect number." << endl;

cout << "Sum of proper factors: " << sum << endl;

return 0;

Output:-
Page 3 of 24

Code:-

#include<iostream>

using namespace std;

int main()

cout<<"T20 worldcup ranking according to their points:-"<<endl;

cout<<"***************************************************"<<endl;

int

pak=52, westindies=84, bangladesh=80, india=92, Newzealand=72, srilanka=45, oneteam=90,


twoteam=84, threeteam=80;

if(oneteam<=pak)

cout<<"pakistan 1st"<<endl;

cout<<"points="<<pak<<endl;

cout<<"*************"<<endl;
Page 4 of 24

else

if(twoteam<=pak)

cout<<"pakistan 2nd"<<endl;

cout<<"points="<<pak<<endl;

cout<<"*************"<<endl;

else{

if(threeteam<=pak)

cout<<"pakistan 3rd"<<endl;

cout<<"points="<<pak<<endl;

cout<<"*************"<<endl;

else

cout<<"pakistan team is not in top 3 rankings"<<endl;

cout<<"points="<<pak<<endl;

cout<<"*************"<<endl;

if(oneteam<=westindies)

cout<<"westindies 1st"<<endl;

cout<<"points="<<westindies<<endl;

cout<<"*************"<<endl;

else

{
Page 5 of 24

if(twoteam<=westindies)

cout<<"westindies 2nd"<<endl;

cout<<"points="<<westindies<<endl;

cout<<"*************"<<endl;

else{

if(threeteam<=westindies)

cout<<"westindies 3rd"<<endl;

cout<<"points="<<westindies<<endl;

cout<<"*************"<<endl;

else

cout<<"westindies team is not in top 3 rankings"<<endl;

cout<<"points="<<westindies<<endl;

cout<<"*************"<<endl;

if(oneteam<=Newzealand)

cout<<"newzealand 1st"<<endl;

cout<<"points="<<Newzealand<<endl;

cout<<"*************"<<endl;

else

if(twoteam<=Newzealand)

cout<<"newzealand 2nd"<<endl;

cout<<"points="<<Newzealand<<endl;
Page 6 of 24

cout<<"*************"<<endl;

else{

if(threeteam<=Newzealand)

cout<<"newzealand 3rd"<<endl;

cout<<"points="<<Newzealand<<endl;

cout<<"*************"<<endl;

else

cout<<"Newzealand team is not in top 3 rankings"<<endl;

cout<<"points="<<Newzealand<<endl;

cout<<"*************"<<endl;

if(oneteam<=bangladesh)

cout<<"bangladesh 1st"<<endl;

cout<<"points"<<bangladesh<<endl;

cout<<"*************"<<endl;

else

if(twoteam<=bangladesh)

cout<<"bangladesh 2nd"<<endl;
Page 7 of 24

cout<<"points="<<bangladesh<<endl;

cout<<"*************"<<endl;

else{

if(threeteam<=bangladesh)

cout<<"bangladesh 3rd"<<endl;

cout<<"points="<<bangladesh<<endl;

cout<<"*************"<<endl;

else

cout<<"Bangladesh team is not in top 3 rankings"<<endl;

cout<<"points="<<bangladesh<<endl;

cout<<"*************"<<endl;

if(oneteam<= srilanka)

cout<<" srilanka 1st"<<endl;

cout<<"points="<<srilanka <<endl;

cout<<"*************"<<endl;

else

if(twoteam<= srilanka)

cout<<" srilanka 2nd"<<endl;

cout<<"points="<<srilanka <<endl;

cout<<"*************"<<endl;
Page 8 of 24

else{

if(threeteam<= srilanka)

cout<<" srilanka 3rd"<<endl;

cout<<"points="<<srilanka <<endl;

cout<<"*************"<<endl;

else

cout<<"srilanka team is not in top 3 rankings"<<endl;

cout<<"points="<<srilanka <<endl;

cout<<"*************"<<endl;

if(oneteam<= india)

cout<<" india 1st"<<endl;

cout<<"points="<<india<<endl;

cout<<"*************"<<endl;

else

if(twoteam<= india)

cout<<" india 2nd"<<endl;

cout<<"points="<<india<<endl;

cout<<"*************"<<endl;

else{
Page 9 of 24

if(threeteam<=india)

cout<<"india 3rd"<<endl;

cout<<"points="<<india<<endl;

cout<<"*************"<<endl;

else

cout<<"India team is not in top 3 rankings"<<endl;

cout<<"points="<<india<<endl;

cout<<"*************"<<endl;

cout<<"*******************************************"<<endl;

cout<<"Note:- points greater than 90 consider as 1st ,point greater than 84 and less than 90 is consider as 2nd,points
greater than 75 and less than 84 is consider as 3rd number."<<endl;

return 0;

}
Page 10 of 24

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.

Code:-
#include <iostream>

using namespace std;

int main() {

cout<<"****************************************************************************************************"<<endl;

cout<<"note:-"<<"product value for apple is 1, for oranges is 2, for pineapple is 3 , for kiwis is 5 etc."<<"**"<<endl;

cout<<"****************************************************************************************************"<<endl;

int totalValue;

int productNumber;

int quantitySold;
Page 11 of 24

cout << "Enter product number and quantity sold (enter -1 for product number to end):" << endl;

while (productNumber != -1) {

cin >> productNumber >> quantitySold;

if (productNumber != -1) {

int price;

switch (productNumber) {

case 1:

cout<<"apple"<<endl;

price = 2.98;

break;

case 2:

price = 4.50;

cout<<"*******"<<endl;

break;

case 3:

price = 9.98;

cout<<"********"<<endl;

break;

case 5:

price = 6.87;

break;

default:

cout << "Invalid product number." << endl;

break;

int productValue = price * quantitySold;

totalValue += productValue;

cout << "Product " << productNumber << " value: $" << productValue << endl;

cout<<"***************"<<endl;

}
Page 12 of 24

cout << "Total retail value of all products sold: $" << totalValue << endl;

return 0;

}
Page 13 of 24

Code:-
#include <iostream>

using namespace std;

string triangleType(int a, int b, int c) {


if (a <= 0 || b <= 0 || c <= 0) {
return "Not a triangle";
} else if (a + b < c || a + c < b || b + c < a) {
return "Not a triangle";
}

if (a == b && b == c) {
return "Equilateral triangle";
}

else if (a == b || a == c || b == c) {
return "Isosceles triangle";
}

else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
{
return "Right triangle";
Page 14 of 24

else {
return "Scalene triangle";
}
}

int main() {
int side1, side2, side3;

cout << "Enter the lengths of the three sides of the triangle (separated by
spaces): ";
cin >> side1 >> side2 >> side3;

string triangleTypea= triangleType(side1, side2, side3);


cout << "Triangle type: " << triangleTypea << endl;

return 0;
Page 15 of 24

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.
Code:-
#include <iostream>

using namespace std;

int main()

int largest = 0;

int second_largest = 0;

while (true) {

cout << "Enter a positive number ( Enter 0 to stop): ";

int num;

cin >> num;

if (num == 0) {

break;

if (num >= largest) {


Page 16 of 24

second_largest = largest;

largest = num;

} else if (num > second_largest && num != largest) {

second_largest = num;

if (second_largest == 0) {

cout << "You entered fewer than 2 positive integers." <<endl;

} else {

cout << "The second largest number entered is: " << second_largest <<endl;

return 0;

Output:-
Page 17 of 24
Page 18 of 24
Page 19 of 24
Page 20 of 24
Page 21 of 24
Page 22 of 24
Page 23 of 24
Page 24 of 24

You might also like