0% found this document useful (0 votes)
19 views29 pages

CPL Assignment Task 1

Uploaded by

sonishivam.2905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views29 pages

CPL Assignment Task 1

Uploaded by

sonishivam.2905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

FET – BTECH

SEM 1 - TASK 1
1. Write a program to calculate the selling price after applying a discount

#include <bits/stdc++.h>
using namespace std;

float discountPercentage(float S, float M)


{
float discount = M - S;

float disPercent = (discount / M) * 100;

return disPercent;
}

int main()
{
int M, S;
M = 120;
S = 100;

cout << std::fixed << std::setprecision(2)


<< discountPercentage(S, M) << "%" << endl;

M = 1000;
S = 500;

cout << std::fixed << std::setprecision(2)


<< discountPercentage(S, M) << "%" << endl;
return 0;
}

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>

float simple_interest(float p, float r, float t) {


return (p * r * t) / 100;
}

float compound_interest(float p, float r, float t) {


return p * pow((1 + r / 100), t);
}

int main() {
float p, r, t, si, ci;

printf("Enter the principal amount: ");


scanf("%f", &p);

printf("Enter the rate of interest: ");


scanf("%f", &r);

printf("Enter the time in years: ");


scanf("%f", &t);

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;
}

OUTPUT:- Enter the principal amount: 5000


Enter the rate of interest:18
Enter the time in years: 5
Simple Interest = Rs. 4500.00
Compound Interest = Rs. 11438.79

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;

cout << "Enter operator (+, -, *, /): ";


cin >> operation;

cout << "Enter two numbers: ";


cin >> num1 >> num2;

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;
}

cout << "Result: " << result << endl;


return 0;

OUTPUT:- Enter operator (+, -, *, /): +

Enter two numbers: 10 5


Result: 15

5. Write a program to check whether two numbers are equal or not.


#include <stdio.h

void main()
{
int int1, int2

printf("Input the values for Number1 and Number2 :


scanf("%d %d", &int1, &int2
if (int1 == int2
printf("Number1 and Number2 are equal\n”);
else
printf("Number1 and Number2 are not equal\n");
}

OUTPUT:- Input the values for Number1 and Number2 : 15 15

Number1 and Number2 are equal

6. Implement a program that checks if a number is positive, negative, or zero.

#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

7. Write a program to check if a person is eligible to vote based on their age

#include <bits/stdc++.h>
using namespace std;
int main()
{
char input = 'Y';
int age;
while (input == 'Y') {
cout << "Enter your age: " << endl;
cin >> age;

if (age >= 18) {


cout << "Person is allowed to vote" << endl;
}
else {
cout << "Person is not allowed to vote" << endl;
}
cout << "To continue press Y" << endl;
cout << "To exit press another key" << endl;
cin >> input;
}
cout << "Program Terminated" << endl;
}
OUTPUT:- Enter your age: 12

Person is not allowed to vote

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("Please Enter Your Age: ");

scanf(" %d", &age);

if(age < 13){

printf("\nChild");

}else if(age < 20) {

printf("\nTeen");

}else if(age < 50) {

printf("\nAdult");

}else{

printf("\nSenior");

return 0;

OUTPUT:-Please Enter Your Age:18

Teen
9. Write a program to calculate the gross salary after deductions for tax and provident fund.

#include<stdio.h>

int main() {

float basic_salary, gross_salary, HRA, DA;

printf("Enter the basic salary: ");

scanf("%f", &basic_salary);

if(basic_salary <= 10000) {

HRA = basic_salary * 0.2;

DA = basic_salary * 0.8;

} else if(basic_salary <= 20000) {

HRA = basic_salary * 0.25;

DA = basic_salary * 0.9;

} else {

HRA = basic_salary * 0.3;

DA = basic_salary * 0.95;

gross_salary = basic_salary + HRA + DA;

printf("Gross Salary is: %.2f\n", gross_salary);

return 0;

OUTPUT:- Enter the basic salary: 15000

Gross Salary is: 32250.00


10. Write a program to calculate the electricity bill based on the number of units consumed.

#include<bits/stdc++.h>

using namespace std;

int calculateBill(int units)

if (units <= 100)

return units * 10;

else if (units <= 200)

return (100 * 10) +

(units - 100) * 15;

else if (units <= 300)

return (100 * 10) +

(100 * 15) +

(units - 200) * 20;

else if (units > 300)

return (100 * 10) +

(100 * 15) +

(100 * 20) +

(units - 300) * 25;

return 0;
}

int main()

int units = 250;

cout << calculateBill(units);

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;

printf("Enter distance in km ");

scanf("%d",&d);

printf("Enter time in minutes ");

scanf("%d",&t);

s=d/(float)t;

printf("Speed = %.2f km per minute",s);

return 0;

OUTPUT:- Enter distance in km 70

Enter time in minutes 50

Speed = 1.40 km per minute


12. Determine whether a vehicle is exceeding the speed limit using conditional statements.

#include <iostream>

int main() {

int speedLimit;

int vehicleSpeed;

std::cout << "Enter the speed limit: ";

std::cin >> speedLimit;

std::cout << "Enter the vehicle's speed: ";

std::cin >> vehicleSpeed;

if (vehicleSpeed > speedLimit) {

std::cout << "The vehicle is exceeding the speed limit." << std::endl;

} else if (vehicleSpeed == speedLimit) {

std::cout << "The vehicle is at the speed limit." << std::endl;

} else {

std::cout << "The vehicle is within the speed limit." << std::endl;

return 0;

OUTPUT:- Enter the speed limit: 60

Enter the vehicle's speed: 70

The vehicle is exceeding the speed limit.

13. Write a program to convert temperatures between Celsius and Fahrenheit.

#include <bits/stdc++.h>

using namespace std;


float Cel_To_Fah(float N)

return ((N * 9.0 / 5.0) + 32.0);

int main()

float N = 20.0;

cout << Cel_To_Fah(N);

return 0;

OUTPUT:- Temperature in Fahrenheit : 68.00

14. Write a program that checks if a temperature is below freezing point

#include <iostream>

using namespace std;

int main() {

double temperature;

cout << "Enter the temperature in Celsius: ";

cin >> temperature;

if (temperature < 0) {

cout << "The temperature is below freezing point." << endl;

} else {

cout << "The temperature is above freezing point." << endl;

}
return 0;

OUTPUT:- Enter the temperature in Celsius: -5

The temperature is below freezing point.

15. Write a program that categorizes temperatures as hot, warm, or cold based on user input.

#include<iostream>

using namespace std;

int main()

int tmp;

cout<<"Input the temperature : ";

cin>>tmp;

if(tmp<0)

cout<<"Freezing weather.\n";

else if(tmp<10)

cout<<"Very cold weather.\n";

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

cout<<"Its very hot.\n";

}
OUTPUT:- Input the temperature: -5

Freezing weather.

Input the temperature: 5

Very cold weather.

Input the temperature: 15

Cold weather.

Input the temperature: 25

Normal in temp.

Input the temperature: 35

Its Hot.

Input the temperature: 45

Its very hot.

16. Create a program that calculates the volume of a cylinder.

#include <stdio.h>

int main()

int height=38;

int radius=35;

double pie=3.14285714286;

double volume=pie*(radius*radius)*height;

printf("Volume of the cylinder=%f",volume);

OUTPUT:- Volume of the cylinder=146300.000000

17. Write a program to calculate the surface area of a sphere.

#include <stdio.h>

int main()
{

int radius=37;

double pie=3.14285714286;

double area_sphere=4*pie*(radius*radius);

printf("Surface area of the sphere=%f",area_sphere);

OUTPUT:- Surface area of the sphere=17210.285714

18. Write a program to convert seconds into hours, minutes, and seconds.

#include <iostream>

#include <conio.h>

using namespace std;

int main()

int h,m,s,ts;

cout<<"Enter total seconds ";

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;

OUTPUT:- Enter total seconds 4830


Hours=1

Minutes=20

Seconds=30

19. Write a program that adds two time durations together.

#include <stdio.h>

struct Time {

int hours;

int minutes;

int seconds;

};

int main() {

struct Time time1, time2, result;

printf("Input the first time (hours minutes seconds): ");

scanf("%d %d %d", &time1.hours, &time1.minutes, &time1.seconds);

printf("Input the second time (hours minutes seconds): ");

scanf("%d %d %d", &time2.hours, &time2.minutes, &time2.seconds);

result.seconds = time1.seconds + time2.seconds;

result.minutes = time1.minutes + time2.minutes + result.seconds / 60;

result.hours = time1.hours + time2.hours + result.minutes / 60;

result.minutes %= 60;

result.seconds %= 60;

printf("\nResultant Time: %02d:%02d:%02d\n", result.hours, result.minutes, result.seconds);


return 0;

OUTPUT:- Input the first time (hours minutes seconds): 7 12 20

Input the second time (hours minutes seconds): 8 10 55

Resultant Time: 15:23:15

20. Write a program to compare three numbers and print them in ascending order.

#include <iostream>

using namespace std;

int main() {

int num1, num2, num3;

cout << "Enter three numbers: ";

cin >> num1 >> num2 >> num3;

if (num1 <= num2 && num1 <= num3) {

cout << num1 << " ";

if (num2 <= num3) {

cout << num2 << " " << num3 << endl;

} else {

cout << num3 << " " << num2 << endl;

} else if (num2 <= num1 && num2 <= num3) {

cout << num2 << " ";

if (num1 <= num3) {

cout << num1 << " " << num3 << endl;

} else {
cout << num3 << " " << num1 << endl;

} else {

cout << num3 << " ";

if (num1 <= num2) {

cout << num1 << " " << num2 << endl;

} else {

cout << num2 << " " << num1 << endl;

return 0;

OUTPUT:- Enter three numbers: 7 3 9

379

21. Create a program that checks if a person is eligible for a scholarship based on their grades and
income.

#include <iostream>

using namespace std;

int main() {

float grades;

float income;

cout << "Enter your grades (0-100): ";

cin >> grades;

cout << "Enter your family income: ";


cin >> income;

if (grades >= 75 && income < 50000) {

cout << "You are eligible for the scholarship!" << endl;

} else {

cout << "You are not eligible for the scholarship." << endl;

return 0;

OUTPUT:- Enter your grades (0-100): 80

Enter your family income: 45000

You are eligible for the scholarship!

22. Write a program that determines if a number is divisible by 3 and 5.

#include <stdio.h>

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

if (num % 3 == 0 && num % 5 == 0) {

printf("%d is divisible by both 3 and 5.\n", num);

} else {

printf("%d is not divisible by both 3 and 5.\n", num);

}
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>

using namespace std;

int main() {

int age;

float weight;

cout << "Enter your age: ";

cin >> age;

cout << "Enter your weight in kg: ";

cin >> weight;

if (age >= 18 && weight >= 50) {

cout << "You are eligible to donate blood." << endl;

} else {

cout << "You are not eligible to donate blood." << endl;

return 0;

}#include <iostream>

using namespace std;


int main() {

int age;

float weight;

cout << "Enter your age: ";

cin >> age;

cout << "Enter your weight in kg: ";

cin >> weight;

if (age >= 18 && weight >= 50) {

cout << "You are eligible to donate blood." << endl;

} else {

cout << "You are not eligible to donate blood." << endl;

return 0;

OUTPUT:- Enter your age: 25

Enter your weight in kg: 55

You are eligible to donate blood.

24. . Create a program to determine whether a character is a vowel or a consonant using ifelse.

#include <iostream>

using namespace std;

int main() {

char ch;
cout << "Enter a character: ";

cin >> ch;

if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' ||

ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' ||

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 {

cout << "Invalid input. Please enter a letter." << endl;

return 0;

OUTPUT:- Enter a character: 3

Invalid input. Please enter a letter.

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>

using namespace std;

int main() {

string qualification;

int experience;

cout << "Enter your highest qualification (e.g., 'Bachelor', 'Master', 'PhD'): ";
cin >> qualification;

cout << "Enter your years of experience: ";

cin >> experience;

if ((qualification == "Master" || qualification == "PhD") && experience >= 2) {

cout << "You are eligible for the job role." << endl;

} else if (qualification == "Bachelor" && experience >= 3) {

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

Enter your years of experience: 3

You are eligible for the job role.

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>

using namespace std;

int main() {

int age;

cout << "Enter your age: ";

cin >> age;


if (age < 18) {

cout << "You are eligible for a student discount." << endl;

} else if (age >= 60) {

cout << "You are eligible for a senior citizen discount." << endl;

} else {

cout << "You are not eligible for any discount." << endl;

return 0;

OUTPUT:- Enter your age: 16

You are not eligible for any discount.

27. Implement a program to find the highest and lowest marks among five subjects and assign grades
accordingly.

#include <iostream>

using namespace std;

int main() {

float marks[5];

float highest, lowest;

char grade;

cout << "Enter marks for 5 subjects: ";

for (int i = 0; i < 5; i++) {

cin >> marks[i];

}
highest = lowest = marks[0];

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

if (marks[i] > highest) {

highest = marks[i];

if (marks[i] < lowest) {

lowest = marks[i];

float average = (marks[0] + marks[1] + marks[2] + marks[3] + marks[4]) / 5;

if (average >= 90) {

grade = 'A';

} else if (average >= 75) {

grade = 'B';

} else if (average >= 60) {

grade = 'C';

} else if (average >= 50) {

grade = 'D';

} else {

grade = 'F';

cout << "Highest Marks: " << highest << endl;

cout << "Lowest Marks: " << lowest << endl;

cout << "Average Marks: " << average << endl;

cout << "Grade: " << grade << endl;

return 0;
}

OUTPUT:- Enter marks for 5 subjects: 85 78 92 68 74

Highest Marks: 92

Lowest Marks: 68

Average Marks: 79.4

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>

using namespace std;

int main() {

float percentage;

float scholarshipAmount;

cout << "Enter your percentage: ";

cin >> percentage;

if (percentage >= 90) {

scholarshipAmount = 10000;

cout << "You are eligible for a full scholarship of $" << scholarshipAmount << endl;

} else if (percentage >= 80) {

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;

OUTPUT:- Enter your percentage: 92

You are eligible for a full scholarship of $10000

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>

using namespace std;

int main() {

float income, expenses, percentage;

float loanAmount;

cout << "Enter your monthly income: ";

cin >> income;

cout << "Enter your monthly expenses: ";

cin >> expenses;

cout << "Enter your academic performance percentage: ";

cin >> percentage;

float disposableIncome = income - expenses;

if (percentage >= 90) {

loanAmount = disposableIncome * 3;

} else if (percentage >= 80) {


loanAmount = disposableIncome * 2;

} else {

loanAmount = disposableIncome * 1;

cout << "You can apply for a student loan of $" << loanAmount << endl;

return 0;

OUTPUT:- Enter your monthly income: 4000

Enter your monthly expenses: 2000

Enter your academic performance percentage: 75

You can apply for a student loan of $2000

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>

using namespace std;

int main() {

float performanceScore;

int awardsWon;

cout << "Enter your performance score (out of 100): ";

cin >> performanceScore;

cout << "Enter the number of awards won: ";

cin >> awardsWon;


if (performanceScore >= 90 && awardsWon >= 3) {

cout << "You are eligible for a cash prize!" << endl;

} else if (performanceScore >= 80 && awardsWon >= 2) {

cout << "You are eligible for a small cash prize!" << endl;

} else {

cout << "You are not eligible for a cash prize." << endl;

return 0;

OUTPUT:- Enter your performance score (out of 100): 95

Enter the number of awards won: 4

You are eligible for a cash prize!

You might also like