شيئية OOP
282 subscribers
53 photos
10 files
12 links
عمي رحمة لوالديك ولعشيرتك وللعزاز وللعراق وللشرق الأوسط، لا تكعد تحفظ الأكواد
الكود فهم فهم فهم مو حفظ
و السلام
Download Telegram
شيئية OOP
Photo
Q4/
A -
#include <iostream>
using namespace std;

int fun(int a)
{
return a;
}

int main() {
cout<<fun(5);
}

👇همين يعتبر حل حبيته هيج :
#include <iostream>
using namespace std;

string fun(string a ) {
return a;
}

int main() {
cout<<fun( " نجحنا واليحبنا يفرح ويانا ");
}


B - سؤال 33
#include <iostream>
using namespace std;
int main ()
{
char grade ;
cout << " take one from this ( A , B, C, D, F) ";
cin >> grade;
switch(grade)
{
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
cout << "Well done" << endl;
break;
case 'C' :
cout << "done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case 'F' :
cout << "Better try again" << endl;
break;
default :
cout << "Invalid grade" << endl;
}
cout << "Your grade is " << grade << endl;
return 0;
}

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Q5/
A -
#include<iostream>
using namespace std;

int Sum(int a[],int s)
{
int sum = 0;
for (int i = 0; i < s; i++) {
int current_item = a[i];
bool unique_ = true;
for (int j = 0; j < s; j++) {
if (i != j&&current_item == a[j]) {
unique_ = false;
}
}
if (unique_)sum += a[i];
}
return sum;
}
int main() {
int i[8] = {1,2,3,2,3,4,2,5};
cout << Sum(i,8);
}

B -
#include<iostream>
using namespace std;

double product(int a,double d){
return a*d;
}
int main() {
cout<<(2,1.5);
}

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Q6/
A -
#include<iostream>
using namespace std;

int power(int base, int pow) {
if (pow == 0)
return 1;
else if (pow == 1)
return base;
else
return base * power(base, pow - 1);
}

int main() {
cout << power(3, 3);
return 0;
}

B -
#include<iostream> 
using namespace std;

double calculateSin(double x, int n)
{
double result = 0;
double term = 1;
int sign = 1;

for (int i = 1; i <= n; ++i)
{
result += sign * term;
sign = -sign;
term *= (x * x) / ((2 * i) * (2 * i + 1));
}

return result;
}

int main()
{
double x;
int n;

cout << "Enter the value of x in radians: ";
cin >> x;

cout << "Enter the number of terms in the Taylor series approximation: ";
cin >> n;

double sinApproximation = calculateSin(x, n);

cout << "Approximation of sin(" << x << ") using Taylor series with " << n << " terms: " << sinApproximation << endl;

return 0;
}
1
اسئلة الهياكل OOP / الدور الثاني
2
شيئية OOP
Photo
Q1/
1-instance
2-blueprint
3-constructor
4-inheritance
5-encapsulation

Q2/
#include <iostream>
using namespace std;
class Circle{
protected:
float radius;

public:
Circle(float r):radius(r){}
};

class Cylinder : public Circle{
private:
float height;

public:
Cylinder(float r,float h):Circle(r),height(h){}

float volume(){
return (3.14*radius*radius*height);
}
};

int main(){
Cylinder c(3.5,6.1);
cout<<c.volume();
}


Q3/
#include <iostream>
using namespace std;

class smart_phone{
int battery_life,camera_quality,user_interface;

public:
smart_phone(int b,int c,int u):battery_life(b),camera_quality(c),
user_interface(u){}

bool operator > (smart_phone iphone){
int s_score=0,i_score=0;

if(battery_life>iphone.battery_life)s_score++;
else i_score++;

if(camera_quality>iphone.camera_quality)s_score++;
else i_score++;

if(user_interface>iphone.user_interface)s_score++;
else i_score++;

return s_score>i_score;
}
};
int main(){
smart_phone samsung(9,9,9);
smart_phone iphone(1,1,1);

if(samsung>iphone)cout<<"first phone is superior";
else cout<<"second phone is superior";
}


Q4/
#include <iostream>
using namespace std;

class bank {
private :
string AccountHolderName;
int AccountNumber;
double balance;
public:
bank ( string AH, int AN, double B) {
AccountHolderName = AH;
AccountNumber = AN;
balance = B;
}

void deposit (double amount) {
balance += amount;
}

void withDrawal(double amount);

friend void display (bank bank);
};

void bank::withDrawal(double amount) {
balance -= amount;
}

void display (bank bank) {
cout << "your balance is : " << bank.balance << endl;
};


int main()
{
bank client = {"mogo", 78904, 1090};

client.deposit(24.5);
client.withDrawal(9.5);
display(client);
return 0;
}


Q5/
#include <iostream>
using namespace std;

class Vehicle {
protected:
string Make;
int Model,LicensePlate;
public:
Vehicle(string m,int mo,int l)
: Make(m), Model(mo), LicensePlate(l) {}
virtual void rent(){
cout << "the virtual function" << endl;
};
};

class Car : public Vehicle {
bool serviced;
public:
Car(string m,int mo,int l, bool s)
: Vehicle(m,mo,l), serviced(s) {}
void rent(){
if (serviced) {
cout<<"Car rented successfully"<<endl;
} else {
cout<<"Car cannot be rented"<<endl;
}
}
};

class Truck : public Vehicle {
public:
Truck(string m, int mo, int l)
: Vehicle(m, mo, l) {}
void rent(){
cout<<"Truck rented"<<endl;
}
};

int main() {
Car c("crown",2000, 61947, true);
Truck t("Ford",2010 , 13512);

Vehicle* ptr;

ptr = &c;
ptr->rent();

ptr = &t;
ptr->rent();

}
1
شيئية OOP
Q1/ 1-instance 2-blueprint 3-constructor 4-inheritance 5-encapsulation Q2/ #include <iostream> using namespace std; class Circle{ protected: float radius; public: Circle(float r):radius(r){} }; class Cylinder : public Circle{ private: float…
Q6/
#include<iostream>
using namespace std;

class SecuritySystem{
protected:
bool MotionDetection;
string DoorWindow_Status;
int FireSmoke_Levels;

public:
SecuritySystem(bool MD, string DWS, int FSL): MotionDetection(MD), DoorWindow_Status(DWS), FireSmoke_Levels(FSL) {}
};

class HomeSecurity : public SecuritySystem {
public:
HomeSecurity(bool MD, string DWS, int FSL): SecuritySystem(MD, DWS, FSL) {}

void checkMD(){
if(MotionDetection){
throw "there is a Motion";
}
else
cout << "there is no Motion" << endl;
}

void checkDWS(){
if(DoorWindow_Status == "open") {
throw "the Door and Window are not closed";
}
else
cout << "the Door and Window are close" << endl;
}

void checkFSL(){
if(FireSmoke_Levels > 50) {
throw "the fire and somkes levels are not normal";
}
else
cout << "the fire and somkes levels are normal" << endl;
}
};


int main() {
HomeSecurity home1( false, "closed", 23);

try {
home1.checkMD();
home1.checkDWS();
home1.checkFSL();
} catch(const char* msg){
cerr << msg <<endl;
}
}
1👏1
هندسة الحاسبات - المرحلة الأولى²⁰²⁴⁻²⁰²³ :

كورس اول :
Programming and Problem Solving

كورس ثاني :
Object Oriented Programming and Data Structure
1
شيئية OOP
البرمجة : ملزمة دفعة²⁵ + حلول الواجبات: https://t.me/Q_code_cpp/311 شروحات: شرح كامل للغة Cpp من الصفر: https://youtube.com/playlist?list=PLEPx7DrqAqKAJm4wM3r7FvvX7y6tuBOAQ&si=moNpvaL7IPGRFJv8 شرح المتسلسلة سؤال 31: https://t.me/no_zero_any_more/359 طريقة…
البرمجة :
5 فراغات
5 البوابات المنطقية
20 من اول 50 سؤال ( ملف ال75 سؤال )
10 مصفوفات
10 فنكشن

والاسئلة مراح تطلع من اطار ال75 سؤال

كل التوفيق ان شاء الله بحق محمد وآل محمد نشوفكم ناجحين ونفرح بيكم🐧🤍♥️
هذني الي اقصدهن بالبوابات المنطقية
1
اسئلة البرمجة / الدور الأول²⁰²⁵
👎4
شيئية OOP
Photo
Q1/A
1-(X+=Y)=57
2-(X||Y)=1(True)
3-(X!=Y)=1(True)
4-(X^=4)=34
5-(X»=4)=2
Q1/B
1-Instructions
2-logical
3-sizeof
4-continue
5-start

Q2/A
#include<iostream>
using namespace std;
int main () {
for(int i=50;i<=65;++i) {
if (i==57||i==62)continue;
cout<<i<<',';
}
return 0;
}

Q2/B
#include<iostream>
using namespace std;
int main() {
int salary,performance_rating,years_of_service;
float bonus=0;
cin>>salary>>performance_rating>>years_of_service;
if(years_of_service>=5) {
if (performance_rating>8) {
bonus=20;
}else {
bonus=10;
}
}else {
if (performance_rating>8) {
bonus=10;
}else {
bonus=5;
}
}
cout<<"bonus:"<<bonus<<'%'<<endl;

return 0;
}

Q3/A
#include<iostream>
using namespace std;

int main () {
char drink_size;
cin>>drink_size;
switch (drink_size) {
case 's':
cout<<"small";
break;
case'm':
cout<<"medium";
break;
case'l':
cout<<"large";
case'x':
cout<<"extra large";
default:
cout<<"size not available";
}
return 0;
}

Q3/B
#include <iostream> 
using namespace std;

int main() {
int A[3][4]={{3,4,6,1},{4,8,0,9},{5,7,1,2}};
int B[4][3];

for (int i=0; i<3;i++)
{
for (int j=0;j<4;j++)
{
B[j][i]=A[i][j]; // The main idea of the code
}
}
for(int i=0;i<4;i++)
{
for (int j=0;j<3;j++)
{
cout<<B[i][j]<<" ";

}
cout<<endl;
}
return 0;
}

Q4/
#include<iostream>
using namespace std;

int power(int base,int exponent) {
int ans=1;
for (int i=1;i<=exponent;i++) {
ans*=base;
}
return ans;
}
int fact(int n) {
int f=1;
for (int i=1;i<=n;i++) {
f*=i;
}
return f;
}
int main() {
double x,n,sum=0;
cin>>x>>n;
for (int i=0;i<n;i++) {
sum+=power(x,i)/fact(i);
}
cout<<sum;

}

Q5/
#include<iostream>
using namespace std;

int mostf(int a[],int s) {
int m=a[0];
int c=0;
for (int i=0;i<s;i++) {
int counter=0;
for (int j=0;j<s;j++) {
if (a[i]==a[j]) {
counter++;
}
}
if (counter>c) {
c=counter;
m=a[i];
}
}
return m;
}
int main() {
int ar[8]={1,6,3,6,3,4,6,5};
cout<<mostf(ar,8);
}
2
الهياكل OOP - المِد 2025
1👎1