0% found this document useful (0 votes)
7 views5 pages

Assignment 3 4

The document outlines an assignment on an online food ordering system using Object-Oriented Programming (OOP) concepts. It describes the structure of the system, including classes for Person, Customer, and DeliveryRider, and demonstrates the use of constructors, inheritance, encapsulation, friend functions, and friend classes. The code implementation showcases how these concepts are applied to create a functional food delivery service with tracking capabilities.

Uploaded by

defaultersupreme
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)
7 views5 pages

Assignment 3 4

The document outlines an assignment on an online food ordering system using Object-Oriented Programming (OOP) concepts. It describes the structure of the system, including classes for Person, Customer, and DeliveryRider, and demonstrates the use of constructors, inheritance, encapsulation, friend functions, and friend classes. The code implementation showcases how these concepts are applied to create a functional food delivery service with tracking capabilities.

Uploaded by

defaultersupreme
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/ 5

UNIVERSITY OF MANAGEMENT AND

TECHNOLOGY

COURSE: OOPS (THEORY)

TOPIC: ASSIGINMENT # 3 & 4

NAME SAAD ALI


DEPARTMENT BS-SE
SECTION A
ROLL NO 043

SUBMITTED TO : MA’AM AQSA


ASSIGNMENT

ScenArio – online Food ordering SySteM


This system models a simple food delivery service. A Customer can place an order and a Delivery
Rider delivers it. Both share some common information like name and ID, so we use a base class
Person, and then create Customer and DeliveryRider classes that inherit from it.
A friend function is used to display private customer address. A friend class tracks rider details.

FunctionAl Flow

• Objects are created using constructors

• Private members like address and vehicle type are set through constructors

• Friend function shows private customer data

• Friend class accesses private delivery rider info

• Inheritance is used from Person → Customer and DeliveryRider

ooP concePtS uSed

Concept How It Was Used

Classes & Objects Person, Customer, DeliveryRider, OrderSystem

Constructor All classes use constructors to set values

Inheritance Customer and DeliveryRider inherit from Person

Encapsulation address and vehicleType are private

Friend Function showCustomerAddress() accesses private address of customer

Friend Class OrderSystem accesses private data of delivery rider


code iMPleMentAtion
#include <iostream>
using namespace std;

// Forward declaration
class Customer;

// Friend function declaration


void showCustomerAddress(Customer c);

// Base Class: Person


class Person {
protected:
string name;
int id;
public:
Person(string n, int i) {
name = n;
id = i;
}

void showBasicInfo() {
cout << "Name: " << name << ", ID: " << id << endl;
}
};

// Derived Class: Customer


class Customer : public Person {
private:
string address;
public:
// Constructor without using initializer list
Customer(string n, int i, string a) : Person("", 0) {
name = n;
id = i;
address = a;
}

void placeOrder() {
cout << name << " placed an order from " << address << endl;
}

// Friend function
friend void showCustomerAddress(Customer c);
};

// Friend function definition


void showCustomerAddress(Customer c) {
cout << " Customer Address is " << c.address << endl;
}
// Derived Class: DeliveryRider
class DeliveryRider : public Person {
private:
string vehicleType;
public:
DeliveryRider(string n, int i, string v) : Person("", 0) {
name = n;
id = i;
vehicleType = v;
}

void deliverOrder() {
cout << name << " is delivering the order using a " << vehicleType << endl;
}

// Friend class
friend class OrderSystem;
};

// Friend Class: OrderSystem


class OrderSystem {
public:
void trackRider(DeliveryRider r) {
cout << "[Tracking] Rider: " << r.name << ", Vehicle: " << r.vehicleType << endl;
}
};

// Main function
int main() {
// Creating objects
Customer c1("Saad", 101, "Lahore");
DeliveryRider r1("Ali", 202, "Bike");

// Using class methods


c1.showBasicInfo();
c1.placeOrder();

// Using friend function


showCustomerAddress(c1);

cout << endl;

r1.showBasicInfo();
r1.deliverOrder();

// Using friend class


OrderSystem system;
system.trackRider(r1);

return 0; }
ScreenShot oF outPut

You might also like