5 Programs
5 Programs
Today 11 20 AM No catego
Program 1
#include <iostream>
using namespace std;
int main() {
char ch;
cout << "Enter a character: ";
cin >> ch;
if (ch >= 'a' && ch <= 'z') {
cout << "Entered character is a
lowercase letter" << endl;
} else {
cout << "Entered character is not a
lowercase letter" << endl;
}
return 0;
}
Program 2
#include <iostream>
using namespace std;
int main() {
char status;
cout << "Enter the salesperson's status
(s/S for senior, j/J for junior): ";
cin >> status;
if (status == 's' | status == 'S') {
cout << "Senior salesperson's sala :
Rs. 400 per week" << endl;
} else if (status == 'j' | status == 'J') {
cout << "Junior salesperson's sala :
Rs. 275 per week" << endl;
} else {
cout << "Error: Invalid status" << endl;
}
return 0;
}
Program 3
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "Enter three integers: ";
cin >> a >> b >> c;
if (a != 0) {
if (b % a == 0 && c % a == 0) {
cout << a << " is a common divisor
of " << b << " and " << c << endl;
} else {
cout << a << " is not a common
divisor of " << b << " and " << c << endl;
}
} else {
cout << "a cannot be zero" << endl;
}
return 0;
}
Program 4
#include <iostream>
using namespace std;
int main() {
char gure;
double side, base, height, area;
cout << "Enter the rst character of the
gure name (S for square, T for triangle): ";
cin >> gure;
if ( gure == 'S' | gure == 's') {
cout << "Enter the side of the square: ";
cin >> side;
area = side * side;
} else if ( gure == 'T' | gure == 't') {
cout << "Enter the base and height of
the triangle: ";
cin >> base >> height;
area = 0.5 * base * height;
} else {
cout << "Invalid gure" << endl;
return 1; // Indicate error
}
cout << "The area of the " << gure << "
is: " << area << endl;
return 0;
}
Program 5
#include <iostream>
using namespace std;
int main() {
double number;
char letter;
cout << "Enter a number and a letter (f
for Fahrenheit, c for Celsius): ";
cin >> number >> letter;
if (letter == 'f' | letter == 'F') {
double celsius = (number - 32) * 5 / 9;
cout << number << " degrees
Fahrenheit is " << celsius << " degrees
Celsius." << endl;
} else if (letter == 'c' | letter == 'C') {
double fahrenheit = (number * 9 / 5) +
32;
cout << number << " degrees Celsius
is " << fahrenheit << " degrees Fahrenheit."
<< endl;
} else {
cout << "Error: Invalid letter. Please
enter 'f' or 'c'." << endl;
return 1; // Indicate error
}
return 0;
}
Program 6
#include <iostream>
using namespace std;
int main() {
int code;
cout << "Enter the code number: ";
cin >> code;
switch (code) {
case 1:
cout << "Western Digital" << endl;
break;
case 2:
cout << "3M Corporation" << endl;
break;
case 3:
cout << "Maxell Corporation" <<
endl;
break;
case 4:
cout << "Sony Corporation" << endl;
break;
case 5:
cout << "Verbatim Corporation" <<
endl;
break;
default:
cout << "Invalid code number" <<
endl;
}
return 0;
}
Program 7
#include <iostream>
using namespace std;
int main() {
char movieCode;
cout << "Movie Catego Menu:\n";
cout << "A: Adventure\n";
cout << "C: Comedy\n";
cout << "F: Family\n";
cout << "H: Horror\n";
cout << "S: Science Fiction\n";
cout << "Enter the movie code: ";
cin >> movieCode;
switch (movieCode) {
case 'A':
cout << "Adventure Movies\n";
break;
case 'C':
cout << "Comedy Movies\n";
break;
case 'F':
cout << "Family Movies\n";
break;
case 'H':
cout << "Horror Movies\n";
break;
case 'S':
cout << "Science Fiction Movies\n";
break;
default:
cout << "Invalid movie code.\n";
}
return 0;
}
Program 8
#include <iostream>
using namespace std;
int main() {
double value;
char conversion_type;
cout << "Enter a value: ";
cin >> value;
cout << "Enter the conversion type (i for
inches to centimeters, g for gallons to
liters, m for miles to kilometers, p for
pounds to kilograms): ";
cin >> conversion_type;
if (conversion_type == 'i') {
double centimeters = value * 2.54;
cout << value << " inches is equal to "
<< centimeters << " centimeters." << endl;
} else if (conversion_type == 'g') {
double liters = value * 3.785;
cout << value << " gallons is equal to "
<< liters << " liters." << endl;
} else if (conversion_type == 'm') {
double kilometers = value * 1.609;
cout << value << " miles is equal to "
<< kilometers << " kilometers." << endl;
} else if (conversion_type == 'p') {
double kilograms = value * 0.4536;
cout << value << " pounds is equal to
" << kilograms << " kilograms." << endl;
} else {
cout << "Invalid conversion type." <<
endl;
}
return 0;
}
Program 9
#include <iostream>
using namespace std;
int main() {
int year;
cout << "Enter a year: ";
cin >> year;
if ((year % 4 == 0 && year % 100 != 0) |
year % 400 == 0) {
cout << year << " is a leap year" <<
endl;
} else {
cout << year << " is not a leap year"
<< endl;
}
return 0;
}
Program 10
#include <iostream>
using namespace std;
int main() {
int temperature;
cout << "Enter the temperature: ";
cin >> temperature;
if (temperature > 35) {
cout << "Hot day" << endl;
} else if (temperature >= 25) {
cout << "Pleasant day" << endl;
} else {
cout << "Cool day" << endl;
}
return 0;
}
Program 11
#include <iostream>
using namespace std;
int main() {
int obtainedMarks;
double percentage;
cout << "Enter the obtained marks: ";
cin >> obtainedMarks;
percentage = (obtainedMarks / 1100.0)
* 100;
if (percentage >= 80) {
cout << "Grade: A+" << endl;
} else if (percentage >= 70) {
cout << "Grade: A" << endl;
} else if (percentage >= 60) {
cout << "Grade: B" << endl;
} else if (percentage >= 50) {
cout << "Grade: C" << endl;
} else if (percentage >= 40) {
cout << "Grade: D" << endl;
} else if (percentage >= 33) {
cout << "Grade: E" << endl;
} else {
cout << "Grade: F" << endl;
}
return 0;
}
Program 12
#include <iostream>
using namespace std;
int main() {
int milita Time;
cout << "Enter milita time (0000 -
2359): ";
cin >> milita Time;
if (milita Time < 0 | milita Time >
2359) {
cout << "Invalid milita time." <<
endl;
return 1;
}
int hours = milita Time / 100;
int minutes = milita Time % 100;
string period = "AM";
if (hours > 12) {
hours -= 12;
period = "PM";
} else if (hours == 0) {
hours = 12;
}
cout << "Standard time: " << hours << ":"
<< set ll('0') << setw(2) << minutes << " "
<< period << endl;
return 0;
}
Program 13
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int a, b, c;
cout << "Enter the coe cients a, b, and
c: ";
cin >> a >> b >> c;
double discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
double root1 = (-b +
sq (discriminant)) / (2 * a);
double root2 = (-b -
sq (discriminant)) / (2 * a);
cout << "Roots of the equation are "
<< root1 << " and " << root2 << endl;
} else if (discriminant == 0) {
double root = -b / (2 * a);
cout << "The solution is " << root <<
endl;
} else {
cout << "Sor , the roots are not real."
<< endl;
}
return 0;
}
Program 14
#include <iostream>
using namespace std;
int main() {
double sala , income_tax, net_sala ;
cout << "Enter the sala of the
employee: ";
cin >> sala ;
if (sala > 30000) {
income_tax = 0.2 * sala ;
} else if (sala >= 20000) {
income_tax = 0.15 * sala ;
} else {
income_tax = 0.1 * sala ;
}
net_sala = sala - income_tax;
cout << "Sala : Rs. " << sala << endl;
cout << "Income Tax: Rs. " << income_tax
<< endl;
cout << "Net Sala : Rs. " << net_sala
<< endl;
return 0;
}
Program 15
#include <iostream>
using namespace std;
int main() {
int year, month;
cout << "Enter the year: ";
cin >> year;
cout << "Enter the month (1-12): ";
cin >> month;
if (month < 1 | month > 12) {
cout << "Invalid month." << endl;
return 1;
}
int days_in_month;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days_in_month = 31;
break;
case 4:
case 6:
case 9:
case 11:
days_in_month = 30;
break;
case 2:
if (year % 4 == 0 && (year % 100 !=
0 | year % 400 == 0)) {
days_in_month = 29; // Leap year
} else {
days_in_month = 28;
}
break;
default:
cout << "Invalid month." << endl;
return 1;
}
string month_name;
switch (month) {
case 1:
month_name = "Janua ";
break;
case 2:
month_name = "Februa ";
break;
case 3:
month_name = "March";
break;
case 4:
month_name = "April";
break;
case 5:
month_name = "May";
break;
case 6:
month_name = "June";
break;
case 7:
month_name = "July";
break;
case 8:
month_name = "August";
break;
case 9:
month_name = "September";
break;
case 10:
month_name = "October";
break;
case 11:
month_name = "November";
break;
case 12:
month_name = "December";
break;
}
cout << month_name << " " << year << "
has " << days_in_month << " days." << endl;
return 0;
}
Program 16
#include <iostream>
using namespace std;
int main() {
char vehicleType;
int days;
double totalCharges;
cout << "Parking Area Menu:\n";
cout << "M = Motorcycle\n";
cout << "C = Car\n";
cout << "B = Bus\n";
cout << "Enter the type of vehicle (M/C/
B): ";
cin >> vehicleType;
cout << "Enter the number of days: ";
cin >> days;
switch (vehicleType) {
case 'M':
totalCharges = days * 10;
break;
case 'C':
totalCharges = days * 20;
break;
case 'B':
totalCharges = days * 30;
break;
default:
cout << "Invalid vehicle type." <<
endl;
return 1;
}
cout << "Total charges: Rs. " <<
totalCharges << endl;
return 0;
}
Program 17
#include <iostream>
using namespace std;
int main() {
double value;
char conversionType;
cout << "Enter a value: ";
cin >> value;
cout << "Enter the conversion type (c
for cm to inches, l for liters to gallons, k for
kilometers to miles, p for kilograms to
pounds): ";
cin >> conversionType;
if (conversionType == 'c') {
double inches = value * 0.394;
cout << value << " cm is equal to " <<
inches << " inches." << endl;
} else if (conversionType == 'l') {
double gallons = value * 0.264;
cout << value << " liters is equal to "
<< gallons << " gallons." << endl;
} else if (conversionType == 'k') {
double miles = value * 0.622;
cout << value << " kilometers is equal
to " << miles << " miles." << endl;
} else if (conversionType == 'p') {
double pounds = value * 2.2;
cout << value << " kilograms is equal
to " << pounds << " pounds." << endl;
} else {
cout << "Invalid conversion type." <<
endl;
}
return 0;
}