LONG Programs in C++
LONG Programs in C++
# include <iostream>
#include <string>
int main() {
string citizenship,name;
int age;
getline(cin,name);
if (name.length()>=4){
if (citizenship == "yes") {
} else {
cout << "\nYou are not eligible to vote due to age." << endl;
} else {
cout << "\nYou are not eligible to vote due to citizenship." << endl;
}else{
return 0;
#include <iostream>
int main() {
char ch;
switch(ch) {
case 'a':
cout << ch << " is a vowel.\n";
break;
case 'e':
break;
case 'i':
break;
case 'o':
break;
case 'u':
break;
default:
return 0;
3. Write a program that takes a number (1–7) as input and displays the
corresponding day of the week.
# include <iostream>
using namespace std;
int main() {
int day;
cout << "Enter a number (1-7) to represent a day of the week: ";
cin >> day;
switch (day) {
case 1:
cout << "Sunday" << endl;
break;
case 2:
cout << "Monday" << endl;
break;
case 3:
cout << "Tuesday" << endl;
break;
case 4:
cout << "Wednesday" << endl;
break;
case 5:
cout << "Thursday" << endl;
break;
case 6:
cout << "Friday" << endl;
break;
case 7:
cout << "Saturday" << endl;
break;
default:
cout << "Invalid day number." << endl;
}
return 0;
}
#include <iostream>
int main() {
int marks;
cout<<"Pass.\n";
cout<<"Pass.\n";}
cout<<"Pass\n";}
else if (marks >= 60){
cout<<"Pass\n";}
else{
return 0;
5. Calculator Program
Write a program in all arithmetic operators
# include <iostream>
using namespace std;
int main() {
char op;
double num1, num2;
cout << "Enter operator (+, -, *, /): ";
cin >> op;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
switch (op) {
case '+':
cout << "Result: " << num1 + num2 << endl;
break;
case '-':
cout << "Result: " << num1 - num2 << endl;
break;
case '*':
cout << "Result: " << num1 * num2 << endl;
break;
case '/':
if (num2 != 0) {
cout << "Result: " << num1 / num2 << endl;
} else {
cout << "Error: Division by zero." << endl;
} break;
default:
cout << "Invalid operator." << endl;
}
return 0;
}
# include <iostream>
using namespace std;
int main() {
double length, width;
cout << "Enter length of the rectangle: ";
cin >> length;
cout << "Enter width of the rectangle: ";
cin>>width;
double area = length * width;
double perimeter = 2 * (length + width);