0% found this document useful (0 votes)
16 views8 pages

LONG Programs in C++

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

LONG Programs in C++

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

LONG (Programs IN C++ Language)

1. Checking Eligibility for Voting

A person is eligible to vote if:

1. They are a citizen.


2. They are at least 18 years old.

# include <iostream>

#include <string>

using namespace std;

int main() {

string citizenship,name;

int age;

cout<<"Enter your original identity name :";

getline(cin,name);

cout << "Enter your citizenship status (yes or no): ";

cin >> citizenship;

cout << "Enter your age: ";

cin >> age;

if (name.length()>=4){

if (citizenship == "yes") {

if (age >= 18) {

cout << "\nYou are eligible to vote." << endl;

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

cout <<"\nYour name is incorrect and eligible for this vote."<<endl;

return 0;

2. Vowel or Consonant Checker

Check if a character is a vowel or a consonant using switch

#include <iostream>

using namespace std;

int main() {

char ch;

cout << "Enter a character: ";

cin >> ch;

switch(ch) {

case 'a':
cout << ch << " is a vowel.\n";

break;

case 'e':

cout << ch << " is a vowel.\n";

break;

case 'i':

cout << ch << " is a vowel.\n";

break;

case 'o':

cout << ch << " is a vowel.\n";

break;

case 'u':

cout << ch << " is a vowel.\n";

break;

default:

cout << ch << " is a consonant.\n";

cout<< ch <<" AND is not a vowel character in this program.\n";

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

4. Student Grade Result.

Determine the grade of a student based on marks entered.

#include <iostream>

using namespace std;

int main() {

int marks;

cout << "Enter marks (0-100): ";

cin >> marks;

if (marks >= 90){

cout << "Grade: A\n";

cout<<"Pass.\n";

else if(marks >= 80){

cout << "Grade: B\n";

cout<<"Pass.\n";}

else if (marks >= 70){

cout << "Grade: C\n";

cout<<"Pass\n";}
else if (marks >= 60){

cout << "Grade: D\n";

cout<<"Pass\n";}

else{

cout << "Grade: F\n";

cout<<"\nThe student are fail"<<endl;

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

6. Calculate the Area and Perimeter of a Rectangle

# 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);

cout << "Area: " << area << endl;

cout << "Perimeter: " << perimeter << endl;


return 0;
}

You might also like