My Project
5 subscribers
3 photos
3 links
Download Telegram
using namespace std;
int main()
{
int a, st1[6], st2[6], top1, top2, item, i;
top1 = top2 = -1;

for(i = 1; i <= 6; i++)
{
cin >> item;
top1++;
st1[top1] = item;
}

cout << "the st1=\n";
for(i = top1; i >= 0; i--)
cout << st1[i] << '\n';

for(i = 0; i < 6; i++)
{
item = st1[top1];
top1--;
top2++;
st2[top2] = item;
}

cout << "\nthe st2=\n";
for(i = top2; i >= 0; i--)
cout << st2[i] << '\n';

cin >> a;
}
.
Forwarded from Mohammed Ali Hudais
#include <iostream>
using namespace std;
#include <stdlib.h>

void insert(int cq[6], int &f, int &r)
{
int item;
if (f == 0 && r == 5)
cout << "over flow\n";
else if (f - r == 1)
cout << "over flow\n";
else if (r == 5 && f > 0)
{
cin >> item;
r = 0;
cq[r] = item;
}
else
{
cin >> item;
r++;
cq[r] = item;
}
if (f == -1)
f = 0;
}

void del(int cq[6], int &f, int &r)
{
int item;
if (f == -1)
cout << "under flow\n";
else if (f == r)
{
item = cq[f];
f = -1;
r = -1;
}
else
{
if (f == 5 && f > r)
{
item = cq[f];
f = 0;
}
else
{
item = cq[f];
f++;
}
}
}

void print(int cq[6], int f, int r)
{
int i;
if (r >= f)
{
for (i = f; i <= r; i++)
cout << cq[i] << " ";
cout << endl;
}
else
{
for (i = 0; i <= 5; i++)
cout << cq[i] << " ";
for (i = 0; i <= r; i++)
cout << cq[i] << " ";
cout << endl;
}
}

int main()
{
int cq[6], x, r = -1, f = -1;
do
{
cout << endl;
cout << "1_insert\n"
<< "2_delete\n"
<< "3_print\n";
cout << "enter your choice:";
cin >> x;
switch (x)
{
case 1:
insert(cq, f, r);
break;
case 2:
del(cq, f, r);
break;
case 3:
print(cq, f, r);
break;
case 4:
exit(0);
break;
default:
break;
}
} while (x != 4);
}
{"name": "Ali",  "days": ["sun","mon","tues"], "start": 8.0, "end": 14.0},
{"name": "Sara", "days": ["mon","wed","thu"], "start": 9.0, "end": 15.0}
]

appointments = []

while True:
print("\n1) Add 2) Show 3) Exit 4) Delete")
c = input("Choice: ")

# -------- ADD --------
if c == "1":
print("\n--- Doctors ---")
for d in doctors:
print(f"- {d['name']} Days:{','.join(d['days'])} Time:{d['start']}-{d['end']}")

doc = input("\nDoctor name: ")
d = next((x for x in doctors if x["name"] == doc), None)
if not d: print("Doctor not found"); continue

day = input("Day: ")
if day not in d["days"]: print("Doctor does not work this day"); continue

try: t = float(input("Time: "))
except: print("Invalid time"); continue

if not d["start"] <= t <= d["end"]: print("Outside working hours"); continue

if any(a["doctor"]==doc and a["day"]==day and a["time"]==t for a in appointments):
print("Already exists"); continue

appointments.append({"doctor": doc, "day": day, "time": t, "patient": input("Patient: ")})
print("Added")

# -------- SHOW --------
elif c == "2":
print("\n--- Booked Appointments ---")
if not appointments: print("No appointments")
else:
for i,a in enumerate(appointments,1):
print(f"{i}) Doctor:{a['doctor']} Day:{a['day']} Time:{a['time']}")

# -------- DELETE --------
elif c == "4":
if not appointments:
print("No appointments to delete")
continue

for i,a in enumerate(appointments,1):
print(f"{i}) Doctor:{a['doctor']} Day:{a['day']} Time:{a['time']}")

try:
n = int(input("Delete number: "))
appointments.pop(n-1)
print("Deleted")
except:
print("Invalid")

# -------- EXIT --------
elif c == "3":
break

else:
print("Invalid")
for a class restaurant that contain restaurant_name, food_name, food_price as data members, a constructor and discount method that gives discount of 5% for the customer. define 3 objects (Use pointer to Object) then give discount only to the first object.ّّّ`

#include <iostream>
using namespace std;
class restaurant
{ string rest_name;
string food_name;
int food_price;
public:
restaurant(string n,string f,int p)
{rest_name=n;
food_name=f;
food_price=p;

}
void discount()
{ float discount=0.05*food_price;
cout<<"price before discount :"<<food_price<<endl;
food_price-=discount;
cout<<"price after discount : "<< food_price<<endl;
}

void print()
{cout<<"rest_name :"<<rest_name<<" , ";
cout<<"food_name :"<<food_name<<" , ";
cout<<"food_price : "<<food_price<<" ;"<<endl;
}
};
int main()
{ restaurant *r1,*r2,*r3;
r1=new restaurant("Feiend Chicken","Chicken",8000);
r2=new restaurant("Barely","Burger++",12000);
r3=new restaurant("City Center","Shawarma",9000);
cout<<"restaurant 1"<<endl;
r1->print();
r1->discount();
cout<<"restaurant 2" <<endl;
r2->print();
r2->discount();
cout<<"restaurant 3"<<endl;
r3->print();
r3->discount();
delete r1;
delete r2;
delete r3;
}
Q1: Create a C++ class called Temperature that stores a temperature in Celsius. Overload the
following operators:
1. Unary ( - ) : returns a new Temperature object with its sign inverted.
2. Prefix (++ ): increases the temperature by 1°C.
#include <iostream>
using namespace std;
class Temperature {
double celsius;
public:
// Constructor
Temperature(double c = 0.0) : celsius(c) {}

// Unary minus operator
Temperature operator-() const {
return Temperature(-celsius);
}
// Prefix increment operator
Temperature& operator++() {
++celsius;
return *this;
}
// Display function (for testing)
void display() const {
cout << celsius << " °C" << endl;
}
};
int main() {
Temperature t1(25);
Temperature t2 = -t1; // Unary minus
++t1; // Prefix increment

t1.display(); // 26 °C
t2.display(); // -25 °C

return 0;
}
Q2: Create a C++ class Counter that stores an integer. Overload:
1. Prefix (++) → increment the counter.
2. Postfix (++) → increment but return the old value.
3. Prefix (--) → decrement the counter.
4. Postfix (--) → decrement but return the old value.
Write a main() program that demonstrates the difference between prefix and postfix operations.
#include <iostream>
using namespace std;

class Counter {
int value;
public:
Counter(int v = 0) {
value = v;
}
// Prefix ++
Counter& operator++() {
++value;
return *this;
}
// Postfix ++
Counter operator++(int) {
Counter temp = *this;
value++;
return temp;
}
// Prefix --
Counter& operator--() {
--value;
return *this;
}
// Postfix --
Counter operator--(int) {
Counter temp = *this;
value--;
return temp;
}
void display() const {
cout << value << endl;
}
};
int main() {
Counter c(10);
Counter a = ++c;
Counter b = c++;
Counter d = --c;
Counter e = c--;
cout << "c = "; c.display();
cout << "a = "; a.display();
cout << "b = "; b.display();
cout << "d = "; d.display();
cout << "e = "; e.display();
return 0;
}
Q3: Create a C++ class Point with two integers x and y. Overload the binary operator (+) to add
two points, and the binary operator (-) to subtract them. Display the result using a print member
function.
#include <iostream>
using namespace std;
class Point {
int x, y;
public:
Point(int xVal = 0, int yVal = 0) {
x = xVal;
y = yVal;
}
// Binary +
Point operator+(Point& p){
return Point(x + p.x, y + p.y);
}
// Binary -
Point operator-(Point& p){
return Point(x - p.x, y - p.y);
}
void print(){
cout << "(" << x << ", " << y << ")" << endl;
}
};
int main() {
Point p1(4, 6);
Point p2(1, 2);
Point sum = p1 + p2;
Point diff = p1 - p2;
sum.print();
diff.print();
return 0;
}
Q4 Create a C++ class Box with width, height, and depth. Overload the binary operator (==) to
compare the volumes of two boxes, and overload the binary operator (!=) based on the result of
(==).
#include <iostream>
using namespace std;

class Box {
private:
double width, height, depth;

public:
Box(double w = 0, double h = 0, double d = 0) {
width = w;
height = h;
depth = d;
}

double volume() {
return width * height * depth;
}

// Operator ==
bool operator==( Box& b){
return volume() == b.volume();
}

// Operator != (based on ==)
bool operator!=(Box& b){
return !(*this == b);
}
};

int main() {
Box b1(2, 3, 4);
Box b2(1, 6, 4);

if (b1 == b2)
cout << "Boxes have equal volume" << endl;
else
cout << "Boxes have different volume" << endl;

if (b1 != b2)
cout << "Boxes are not equal in volume" << endl;

return 0;
}
Q5: Create a C++ class Distance that stores a value in meters. Overload the following operators:
1. Unary (-) : return the negated distance
2. Binary (+) : add two Distance objects
3. Binary (<) : compare two distances
#include <iostream>
using namespace std;

class Distance {

double meters;

public:
Distance(double m = 0) {
meters = m;
}

// Unary -
Distance operator-() {
return Distance(-meters);
}

// Binary +
Distance operator+(Distance& d){
return Distance(meters + d.meters);
}

// Binary <
bool operator<(Distance& d){
return meters < d.meters;
}

void display(){
cout << meters << " meters" << endl;
}
};

int main() {
Distance d1(15.5);
Distance d2(10.2);

Distance d3 = -d1;
Distance d4 = d1 + d2;

d3.display();
d4.display();

if (d1 < d2)
cout << "d1 is less than d2" << endl;
else
cout << "d1 is not less than d2" << endl;

return 0;
}
Q6: Create a class Complex that stores real and imaginary parts of a complex number.
1. Overload the binary + operator to add two complex numbers.
2. Overload the binary * operator to multiply two complex numbers.
3. Overload the unary ~ operator to return the complex conjugate.
#include <iostream>
using namespace std;

class Complex {
double real, imag;

public:
Complex(double r = 0, double i = 0) {
real = r;
imag = i;
}

// Binary +
Complex operator+( Complex& c) {
return Complex(real + c.real, imag + c.imag);
}

// Binary *
Complex operator*( Complex& c) {
return Complex(
real * c.real - imag * c.imag,
real * c.imag + imag * c.real
);
}

// Unary ~ (complex conjugate)
Complex operator~(){
return Complex(real, -imag);
}

void print() {
cout << real;
if (imag >= 0)
cout << " + " << imag << "i" << endl;
else
cout << " - " << -imag << "i" << endl;
}
};

int main() {
Complex c1(2, 3);
Complex c2(1, -4);

Complex sum = c1 + c2;
Complex product = c1 * c2;
Complex conjugate = ~c1;

sum.print();
product.print();
conjugate.print();

return 0;
}
Q7: Write an object-oriented program in C++ that overloads the + operator to concatenate two
strings.
#include <iostream>
using namespace std;
class MyString {

string text;

public:
MyString(string s = "") {
text = s;
}

// Overload +
MyString operator+(MyString& s) {
return MyString(text + s.text);
}

void display(){
cout << text << endl;
}
};

int main() {
MyString s1(" Mousa ");
MyString s2("Saleh");

MyString s3 = s1 + s2;

s3.display();

return 0;
}
This media is not supported in your browser
VIEW IN TELEGRAM
Forwarded from My Project
appointments=[]
def add_appointments():
day=input("enter the day :")
time=input("enter the time:")
patient=input("enter the patient :")
for appt in appointments:
if appt["day"]==day and appt["time"]==time:
print("already have appointment")
return
new_appt={"day":day,"time":time,"patient":patient}
appointments.append(new_appt)
print("added appointment")
def show_appointments():
print("all appointment \n")
if not appointments:
print("no appointment")
return
for i, appt in enumerate(appointments,start=1):
print(f"{i})day:{appt['day']}|time:{appt['time']}|patient:{appt['patient']}")
def main():
while True:
print("welcome to the appointments system.")
print("1.add appointment")
print("2.show appointments")
print("3.exit")
choice=input("enter your choice(1 or 2 or3 ):")
if choice=="1":
add_appointments()
elif choice=="2":
show_appointments()
elif choice=="3":
print("exit")
break
else:
print("invalid choice")
if __name__=="__main__":
main()
customer = {
"name": "John Smith",
"age": 30,
"is_verified": True
}
print(customer["name"]) # "John Smith" سيطبع القيمة المرتبطة بمفتاح الاسم وهي

# "silver" سيعيد القيمة الافتراضية "type" بما أنه لا يوجد مفتاح باسم
print(customer.get("type", "silver"))
customer["name"] = "new name" # "new name" إلى "John Smith" تغيير قيمة الاسم من
print(customer)
# تطبيق عملي على الاستثناءات (Exceptions)

try:
# الكود الذي قد يتسبب في خطأ
age = int(input('Age: ')) # إذا أدخل المستخدم حرفاً، سيحدث خطأ من نوع ValueError
income = 20000
risk = income / age # إذا أدخل المستخدم 0، سيحدث خطأ من نوع ZeroDivisionError
print(f"Your age is: {age}")

except ValueError:
# هذا الكود يعمل فقط إذا كان الإدخال ليس رقماً
print('Invalid value. Please enter a number.')

except ZeroDivisionError:
# هذا الكود يعمل فقط إذا كان العمر 0
print('Age cannot be zero.')
هذا يوضح كيف ننشئ كلاس ونضيف له دوام (Methods):
```class Point:
def move(self):
print("move")

def draw(self):
print("draw")

# إنشاء كائن (Object) من الكلاس
point1 = Point()
point1.draw() # "draw" سيطبع```
```# الصنف الأساسي (الأب)
class Mammal:
def walk(self):
print("walk")

# الصنف المشتق (الابن) يرث من Mammal
class Dog(Mammal):
def bark(self):
print("bark")

# الصنف المشتق الآخر يرث أيضاً من Mammal
class Cat(Mammal):
pass # نستخدم pass إذا كان الكلاس فارغاً ولا نريد إضافة دوال جديدة حالياً

# تجربة الكود
dog1 = Dog()
dog1.walk() # تم استدعاؤها من الصنف الأب
dog1.bark() # دالة خاصة بصنف الكلب فقط

cat1 = Cat()
cat1.walk() # القطة أيضاً تستطيع المشي لأنها ورثت الدالة```