ch
Feedback
شيئية OOP

شيئية OOP

前往频道在 Telegram

عمي رحمة لوالديك ولعشيرتك وللعزاز وللعراق وللشرق الأوسط، لا تكعد تحفظ الأكواد الكود فهم فهم فهم مو حفظ و السلام

显示更多
234
订阅者
无数据24 小时
-47 天
-930 天
帖子存档
Q17: Write a C++ program that classifies a person into different age groups: child (0-12), teenager (13-19), adult (20-59), or senior (60 and above).
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<" enter your age : ";
cin>>age;
if( age <= 12 )
{
cout<<"your a child"<<endl;
}
else if ( age <=19 )
{
cout<<"your a teenager"<<endl;
}
else if ( age <= 59 )
{
cout<<"your a adult"<<endl;
}
else if ( age >= 60 )
{
cout<<"your a senior"<<endl;
}
return 0;
}

Q16: Create a C++ program that takes a character as input and determines whether it is a vowel, consonant.
#include <iostream> 
using namespace std; 
 
int main()  
{ 
    char character; 
 
    cout << "Enter a character: "; 
    cin >> character; 
 
    if ((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z'))  
 { 
        switch (character)  
  { 
            case 'a': 
            case 'e': 
            case 'i': 
            case 'o': 
            case 'u': 
            case 'A': 
            case 'E': 
            case 'I': 
            case 'O': 
            case 'U': 
                cout << character << " is a vowel." << endl; 
                break; 
            default: 
                cout << character << " is a consonant." << endl; 
        } 
    }  
 else  
 { 
        cout << "Invalid input. Please enter a valid alphabet character." << endl; 
    } 
 
    return 0; 
}

Q15: Develop a simple C++ calculator program with a menu that performs addition, subtraction, multiplication, and division based on the user's choice.
#include <iostream> 
using namespace std; 
 
int main()  
{ 
    float num1, num2, result;
    char op;
    cout<<" enter the number1 : ";
    cin>>num1;
    cout<<" enter operator (+, -, *, /) : ";
    cin>>op;
    cout<<" enter the number2 : ";
    cin>>num2;
    switch (op)
    {
    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 "<<endl;
    return 1;
    }
    break;
    default:
    cout<<" error "<<endl;
    return 1;
    }
    
    cout<<result<<endl;
    
    return 0;
}

Q14: Write a C++ program to determine if a given number is positive, negative, or zero. Use appropriate conditional statements.
#include <iostream> 
using namespace std; 
 
int main()  
{ 
    int num;
    cout<<" enter the number ";
    cin>>num;
    if ( num > 0 )
    {
    cout<<" the number is positive "<<endl;
    }
    else if ( num < 0)
    {
    cout<<" the number is negative "<<endl;
    }
    
    else
    {
    cout<<" the number is zero "<<endl;
    } 
    return 0; 
}

Q13: Implement a C++ program that takes a student's percentage as input and assigns a grade according to the following criteria: 90% and above: A 80-89%: B 70-79%: C Below 70%: F
#include <iostream> 
using namespace std; 
 
int main()  
{ 
    int grade;
    cout<<" enter your grade ";
    cin>>grade;
    if ( grade > 90 )
    {
    cout<<" your grade is : A "<<endl;
    }
    else if ( grade > 80 )
    {
    cout<<" your grade is : B "<<endl;
    }
    else if ( grade > 70 )
    {
    cout<<" your grade is : C "<<endl;
    }
    else
    {
    cout<<" your grade is : F "<<endl;
    } 
    return 0; 
}

Q12: Create a C++ program that determines whether a given year is a leap year or not. Provide appropriate messages based on the result.
#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; 
}

Q11: Write a C++ program that takes two integers as input and checks if they are equal, greater than, or less than each other
#include <iostream>
using namespace std;
int main ()
{
int a, b;
cout<<"enter the value of a : ";
cin>>a;
cout<<"enter the value of b : ";
cin>>b;

if ( a == b )
{
cout<<" a equal b "<<endl;
}
else if ( a > b)
{
cout<<" a is greater than b "<<endl;
}
else if ( a < b )
{
cout<<" a is less than b "<<endl;
}
return 0;
}

Q10: Write a C++ program to print the sequence of even numbers from (10 - 30). Use do while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 10;
do
{
cout<<a<<", ";
a += 2;
}
while ( a < 30);
cout<<a<<", ";
return 0;
}

Q9: Write a C++ program to print the sequence of odd numbers from (11 - 29). Use do while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 11;
do
{
cout<<a<<", ";
a += 2;
}
while ( a < 29);
cout<<a<<", ";
return 0;
}

Q8: Write a C++ program to print the sequence of numbers (15, 16, 17 … 30). Use do while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 15;
do
{
cout<<a<<", ";
a++;
}
while ( a < 30);
cout<<a<<", ";
return 0;
}

Q7: Write a C++ program to print the sequence of even numbers from (10 - 30). Use while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 10;
while ( a <= 30)
{
cout<<a<<", ";
a += 2;
}
return 0;
}

Q6: Write a C++ program to print the sequence of odd numbers from (11 - 29). Use while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 11;
while ( a <= 29)
{
cout<<a<<", ";
a += 2;
}
return 0;
}

Q5: Write a C++ program to print the sequence of numbers (10, 11, 12 … 30). Use while loop statement.
#include <iostream>
using namespace std;
int main ()
{
int a = 10;
while ( a <= 30)
{
cout<<a<<", ";
a++;
}
return 0;
}

Q4: Write a C++ program to find the sum and average of six numbers.
#include <iostream>
using namespace std;

int main()
{
    float sum=0;
    float average;
    float number [6];
    cout<< " enter the six number : "<<endl;
    for (int i = 0; i < 6; i++)
    {
        cout<<" number "<<i+1<<" : ";
        cin>>number[i];
        sum += number[i];
        average = sum/6;
    }
    cout<<" the sum "<<sum<<endl;
    cout<<" the average "<<average<<endl;
    return 0;
}

Q3: Write a C++ program to read five numbers, find their sum, and print the numbers in reverse order.
#include <iostream>
using namespace std;

int main()
{
    int sum=0;
    int number [5];

    cout<<"enter the five number : "<<endl;

    for (int i = 0; i < 5; i++)
    {
        cout<<" number "<<i+1<<" : ";
        cin>>number[i];
        sum += number[i];
    }
    cout<<" the sum "<<sum<<endl;
    cout<<" number in reverse : "<<endl;
    for (int i = 4; i>=0; i--)
    {
        cout<< number[i]<<", ";
    }

    return 0;
}

Q2: Write a C++ code to swap two integer numbers (use Bitwise exclusive OR operator).
#include <iostream>
using namespace std;

int main()
{
    int a, b, temp;
    cout<<"enter the value of a ";
    cin >> a;
    cout<<"enter the value of b ";
    cin >> b;

   cout<< " before a = "<<a<<", b = "<<b<<endl;
   a = a ^ b;
   b = a ^ b;
   a = a ^ b;
   cout<<" after a = "<<a<<", b = "<<b<<endl;
return 0;
}

Q1: Write a C++ code to swap two integer numbers and find the sum of them (use temp variable).
#include <iostream>
using namespace std;

int main()
{
    int a, b, temp;
    cout<<"enter the value of a ";
    cin >> a;
    cout<<"enter the value of b ";
    cin >> b;

   cout<< " before a = "<<a<<", b = "<<b<<endl;
   temp = a;
   a = b;
   b=temp;
   int sum = a + b;
   cout<<" after a = "<<a<<", b = "<<b<<endl;
   cout<<" the sum is : "<<sum<<endl;
return 0;
}