شيئية OOP
281 subscribers
53 photos
10 files
12 links
عمي رحمة لوالديك ولعشيرتك وللعزاز وللعراق وللشرق الأوسط، لا تكعد تحفظ الأكواد
الكود فهم فهم فهم مو حفظ
و السلام
Download Telegram
Channel created
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;
}
👍1
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;
}
1👍1
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;
}
1👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1
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;
}
👍1