Professional Documents
Culture Documents
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>
int main() {
int num;
if (num <= 0) {
cout << "Invalid input: Please enter a positive integer." << endl;
return 1;
int sum = 0;
cout << "Proper factors of " << num << ": ";
if (num % i == 0) {
sum += i;
} else {
cout << "Sum of proper factors: " << sum << endl;
return 0;
Output:-
Page 3 of 24
Code:-
#include<iostream>
int main()
cout<<"***************************************************"<<endl;
int
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<<"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<<"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<<"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<<"points="<<bangladesh<<endl;
cout<<"*************"<<endl;
if(oneteam<= srilanka)
cout<<"points="<<srilanka <<endl;
cout<<"*************"<<endl;
else
if(twoteam<= srilanka)
cout<<"points="<<srilanka <<endl;
cout<<"*************"<<endl;
Page 8 of 24
else{
if(threeteam<= srilanka)
cout<<"points="<<srilanka <<endl;
cout<<"*************"<<endl;
else
cout<<"points="<<srilanka <<endl;
cout<<"*************"<<endl;
if(oneteam<= india)
cout<<"points="<<india<<endl;
cout<<"*************"<<endl;
else
if(twoteam<= india)
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<<"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>
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;
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:
break;
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>
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;
return 0;
Page 15 of 24
int main()
int largest = 0;
int second_largest = 0;
while (true) {
int num;
if (num == 0) {
break;
second_largest = largest;
largest = num;
second_largest = num;
if (second_largest == 0) {
} 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