CPL Assignment Task 1
CPL Assignment Task 1
SEM 1 - TASK 1
1. Write a program to calculate the selling price after applying a discount
#include <bits/stdc++.h>
using namespace std;
return disPercent;
}
int main()
{
int M, S;
M = 120;
S = 100;
M = 1000;
S = 500;
OUTPUT:- 16.67%
50.00%
2. Write a program to compare simple interest and compound interest for the same inputs.
#include <stdio.h>
#include <math.h>
int main() {
float p, r, t, si, ci;
si = simple_interest(p, r, t);
printf("Simple Interest = Rs. %.2f\n", si);
ci = compound_interest(p, r, t);
printf("Compound Interest = Rs. %.2f\n", ci);
return 0;
}
3. Implement a calculator that performs operations based on user input using if-else statements
#include <iostream>
using namespace std;
int main() {
char operation;
double num1, num2, result;
switch (operation) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
cout << "Error: Division by zero is not allowed.";
return 1;
}
break;
default:
cout << "Invalid operator!";
return 1;
}
void main()
{
int int1, int2
#include <stdio.h>
void checkNum(int N) {
if (N == 0) {
printf("Zeri\n");
}
else if (N < 0) {
printf("Negative\n");
}
else {
printf("Positive\n");
}
}
int main() {
int N = 10;
checkNum(N);
return 0;
}
OUTPUT:-Positive
#include <bits/stdc++.h>
using namespace std;
int main()
{
char input = 'Y';
int age;
while (input == 'Y') {
cout << "Enter your age: " << endl;
cin >> age;
To continue press Y
To exit press N
N
Program Terminated
8. Write a program that categorizes age groups: child, teenager, adult, or senior citizen
#include <stdio.h>
int main() {
int age;
printf("\nChild");
printf("\nTeen");
printf("\nAdult");
}else{
printf("\nSenior");
return 0;
Teen
9. Write a program to calculate the gross salary after deductions for tax and provident fund.
#include<stdio.h>
int main() {
scanf("%f", &basic_salary);
DA = basic_salary * 0.8;
DA = basic_salary * 0.9;
} else {
DA = basic_salary * 0.95;
return 0;
#include<bits/stdc++.h>
(100 * 15) +
(100 * 15) +
(100 * 20) +
return 0;
}
int main()
OUTPUT:-3500
11. Write a program to calculate the speed of a vehicle given distance and time.
#include <stdio.h>
#include <conio.h>
int main()
int d,t;
float s;
scanf("%d",&d);
scanf("%d",&t);
s=d/(float)t;
return 0;
#include <iostream>
int main() {
int speedLimit;
int vehicleSpeed;
std::cout << "The vehicle is exceeding the speed limit." << std::endl;
} else {
std::cout << "The vehicle is within the speed limit." << std::endl;
return 0;
#include <bits/stdc++.h>
int main()
float N = 20.0;
return 0;
#include <iostream>
int main() {
double temperature;
if (temperature < 0) {
} else {
}
return 0;
15. Write a program that categorizes temperatures as hot, warm, or cold based on user input.
#include<iostream>
int main()
int tmp;
cin>>tmp;
if(tmp<0)
cout<<"Freezing weather.\n";
else if(tmp<10)
else if(tmp<20)
cout<<"Cold weather.\n";
else if(tmp<30)
cout<<"Normal in temp.\n";
else if(tmp<40)
cout<<"Its Hot.\n";
else
}
OUTPUT:- Input the temperature: -5
Freezing weather.
Cold weather.
Normal in temp.
Its Hot.
#include <stdio.h>
int main()
int height=38;
int radius=35;
double pie=3.14285714286;
double volume=pie*(radius*radius)*height;
#include <stdio.h>
int main()
{
int radius=37;
double pie=3.14285714286;
double area_sphere=4*pie*(radius*radius);
18. Write a program to convert seconds into hours, minutes, and seconds.
#include <iostream>
#include <conio.h>
int main()
int h,m,s,ts;
cin>>ts;
h=ts/3600;
m=(ts%3600)/60;
s=(ts%3600)%60;
cout<<"Hours="<<h<<endl;
cout<<"Minutes="<<m<<endl;
cout<<"Seconds="<<s;
return 0;
Minutes=20
Seconds=30
#include <stdio.h>
struct Time {
int hours;
int minutes;
int seconds;
};
int main() {
result.minutes %= 60;
result.seconds %= 60;
20. Write a program to compare three numbers and print them in ascending order.
#include <iostream>
int main() {
cout << num2 << " " << num3 << endl;
} else {
cout << num3 << " " << num2 << endl;
cout << num1 << " " << num3 << endl;
} else {
cout << num3 << " " << num1 << endl;
} else {
cout << num1 << " " << num2 << endl;
} else {
cout << num2 << " " << num1 << endl;
return 0;
379
21. Create a program that checks if a person is eligible for a scholarship based on their grades and
income.
#include <iostream>
int main() {
float grades;
float income;
cout << "You are eligible for the scholarship!" << endl;
} else {
cout << "You are not eligible for the scholarship." << endl;
return 0;
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
} else {
}
return 0;
OUTPUT:-Enter a number: 15
15 is divisible by both 3 and 5.
23. Write a program to check whether a person is eligible to donate blood based on age and weight
using if-else.
#include <iostream>
int main() {
int age;
float weight;
} else {
cout << "You are not eligible to donate blood." << endl;
return 0;
}#include <iostream>
int age;
float weight;
} else {
cout << "You are not eligible to donate blood." << endl;
return 0;
24. . Create a program to determine whether a character is a vowel or a consonant using ifelse.
#include <iostream>
int main() {
char ch;
cout << "Enter a character: ";
ch == 'u' || ch == 'U') {
cout << "The character " << ch << " is a vowel." << endl;
} else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
cout << "The character " << ch << " is a consonant." << endl;
} else {
return 0;
25. Implement a program that checks if a person is eligible for a particular job role based on their
qualifications and experience using if-else.
#include <iostream>
int main() {
string qualification;
int experience;
cout << "Enter your highest qualification (e.g., 'Bachelor', 'Master', 'PhD'): ";
cin >> qualification;
cout << "You are eligible for the job role." << endl;
cout << "You are eligible for the job role." << endl;
} else {
cout << "You are not eligible for the job role." << endl;
return 0;
OUTPUT:- Enter your highest qualification (e.g., 'Bachelor', 'Master', 'PhD'): Master
26. Create a program that checks if a person is eligible for a student discount, senior citizen discount,
or no discount based on their age using if-else.
#include <iostream>
int main() {
int age;
cout << "You are eligible for a student discount." << endl;
cout << "You are eligible for a senior citizen discount." << endl;
} else {
cout << "You are not eligible for any discount." << endl;
return 0;
27. Implement a program to find the highest and lowest marks among five subjects and assign grades
accordingly.
#include <iostream>
int main() {
float marks[5];
char grade;
}
highest = lowest = marks[0];
highest = marks[i];
lowest = marks[i];
grade = 'A';
grade = 'B';
grade = 'C';
grade = 'D';
} else {
grade = 'F';
return 0;
}
Highest Marks: 92
Lowest Marks: 68
Grade: B
28. . Write a program to calculate the scholarship amount based on a sliding scale of academic
performance (e.g., 90% and above gets full scholarship, 80-89% gets partial scholarship).
#include <iostream>
int main() {
float percentage;
float scholarshipAmount;
scholarshipAmount = 10000;
cout << "You are eligible for a full scholarship of $" << scholarshipAmount << endl;
scholarshipAmount = 5000;
cout << "You are eligible for a partial scholarship of $" << scholarshipAmount << endl;
} else {
scholarshipAmount = 0;
cout << "You are not eligible for a scholarship." << endl;
}
return 0;
29. . Create a program to calculate the amount of student loan a person can apply for based on their
income, expenses, and academic performance.
#include <iostream>
int main() {
float loanAmount;
loanAmount = disposableIncome * 3;
} else {
loanAmount = disposableIncome * 1;
cout << "You can apply for a student loan of $" << loanAmount << endl;
return 0;
30. Write a program that checks if a student is eligible for a cash prize based on their performance in
a science fair and the number of awards won.
#include <iostream>
int main() {
float performanceScore;
int awardsWon;
cout << "You are eligible for a cash prize!" << endl;
cout << "You are eligible for a small cash prize!" << endl;
} else {
cout << "You are not eligible for a cash prize." << endl;
return 0;