0% found this document useful (0 votes)
47 views11 pages

Zuuh's Group Work

Uploaded by

ericcostermboya
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)
47 views11 pages

Zuuh's Group Work

Uploaded by

ericcostermboya
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/ 11

THE UNIVERSITY OF DODOMA

THE COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION

Department: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Course Name: OBJECT ORIENTED SYSTEM DESIGN

Course Code: CP 223

Course Instructor: MR. JUSTIN WOISSO

Degree Program: Bsc.SE

S/NO STUDENT NAMES REGISTRATION NUMBER


1. CHARLES KADETE T/UDOM/2020/00369
2. ABDULHAMID ALEY T/UDOM/2020/07099
3. SHIMBE MAJESTIC T/UDOM/2020/00362
4. MASEILI MUSA T/UDOM/2020/00384
5. ZUHRA BAKARI T/UDOM/2020/00348
6. NASRA MOHAMED T/UDOM/2020//00376
7. DENNIS SOSTHENES T/UDOM/2020/07100
8. ANUARI ISSA T/UDOM/2020/00345
9. JOSEPH MWANUKE T/UDOM/2020/00347
10. BRIGHTNESS SHIYO T/UDOM/2020/00344
QUESTIONS
1. IMPLEMENTATION OF OBJECT ORIENTED DESIGN (OOD) IN C++

 Encapsulation
#include<iostream>
using namespace std;
class Employee //create class Employee

{
//everything in class in c++ is private by default unless specified
//members of class (attributes)
private:
string Name;
int EmployeeID;
int Age;

public:
void setName(string name) //setter method
{
Name=name;
}
string getName() //getter method
{
return Name;
}
void setEmployeeID(int ID)
{
EmployeeID=ID;
}
int getEmployeeID()
{
return EmployeeID;
}
void setAge(int age)
{
Age=age;
}
int getAge()
{
return Age;
}
void EmployeeAvailable() //method/function
{
cout<<"Employee Name: "<<Name<<endl;
cout<<"Employee ID: "<<EmployeeID<<endl;
cout<<"Employee Age: "<<Age<<endl;
}

Employee(string name, int ID, int age) //constructor


{
Name = name;
EmployeeID = ID;
Age = age;
}
};

int main()
{
//create variable of type Employee
//invoke constructor that is ready to receive argument
Employee e1 = Employee("Anna",2345,23);
e1.EmployeeAvailable(); //invoke function

Employee e2 = Employee("John",2567,25);
e2.EmployeeAvailable();

e1.setAge(40);
cout<<e1.getName()<<" is "<<e1.getAge()<<" years old"<<endl;
}
 Abstraction
#include<iostream>
using namespace std;
class AbstractEmployee
{
//obligatory that is force any class that signs this contract (abstract class) to
implement this method
virtual void Promotion()=0;
};
class Employee:AbstractEmployee
{
private:
string Name;
int EmployeeID;
int Age;

public:
void setName(string name) //setter method
{
Name=name;
}
string getName() //getter method
{
return Name;
}
void setEmployeeID(int ID)
{
EmployeeID=ID;
}
int getEmployeeID()
{
return EmployeeID;
}
void setAge(int age)
{
Age=age;
}
int getAge()
{
return Age;
}
void EmployeeAvailable() //method/function
{
cout<<"Employee Name: "<<Name<<endl;
cout<<"Employee ID: "<<EmployeeID<<endl;
cout<<"Employee Age: "<<Age<<endl;
}

void Promotion()
{
if(Age>30)
cout<<Name<<" Got Promoted!"<<endl;
else
cout<<Name<<" Sorry No Promotion!"<<endl;
}

Employee(string name, int ID, int age) //constructor


{
Name = name;
EmployeeID = ID;
Age = age;
}
};

int main()
{

Employee e1 = Employee("Anna",2345,23);
Employee e2 = Employee("John",2567,35);
e1.Promotion();
e2.Promotion();
}
 Inheritance
#include<iostream>
using namespace std;
class AbstractEmployee
{
virtual void Promotion()=0;
};
class Employee:AbstractEmployee
{
//everything in class in c++ is private by default unless specified
//members of class (attributes)
private:
string Name;
int EmployeeID;
int Age;

public:
void setName(string name) //setter method
{
Name=name;
}
string getName() //getter method
{
return Name;
}
void setEmployeeID(int ID)
{
EmployeeID=ID;
}
int getEmployeeID()
{
return EmployeeID;
}
void setAge(int age)
{
Age=age;
}
int getAge()
{
return Age;
}
void EmployeeAvailable() //method/function
{
cout<<"Employee Name: "<<Name<<endl;
cout<<"Employee ID: "<<EmployeeID<<endl;
cout<<"Employee Age: "<<Age<<endl;
}

void Promotion()
{
if(Age>30)
cout<<Name<<" Got Promoted!"<<endl;
else
cout<<Name<<" Sorry No Promotion!"<<endl;
}

Employee(string name, int ID, int age) //constructor


{
Name = name;
EmployeeID = ID;
Age = age;
}
};

class Supervisor:public Employee //inheritance is private by default


{
public:
int salary;
Supervisor(string name, int ID, int age, int Salary)
:Employee(name,ID,age)
{
salary=Salary;
}
void Supervise()
{
cout<<getName()<<" has a salary of "<<salary<<endl;
}
};

int main()
{
Supervisor s1 = Supervisor("Happy",23456,24,300000);
s1.Supervise();
s1.Promotion();
}

 Polymorphism
#include<iostream>
using namespace std;
class AbstractEmployee
{
virtual void Promotion()=0;
};
class Employee:AbstractEmployee
{
//everything in class in c++ is private by default unless specified
//members of class (attributes)
private:
string Name;
int EmployeeID;
int Age;

public:
void setName(string name) //setter method
{
Name=name;
}
string getName() //getter method
{
return Name;
}
void setEmployeeID(int ID)
{
EmployeeID=ID;
}
int getEmployeeID()
{
return EmployeeID;
}
void setAge(int age)
{
Age=age;
}
int getAge()
{
return Age;
}

void EmployeeAvailable() //method/function


{
cout<<"Employee Name: "<<Name<<endl;
cout<<"Employee ID: "<<EmployeeID<<endl;
cout<<"Employee Age: "<<Age<<endl;
}

void Promotion()
{
if(Age>30)
cout<<Name<<" Got Promoted!"<<endl;
else
cout<<Name<<" Sorry No Promotion!"<<endl;
}

void work()
{
cout<<Name<<" is checking emails"<<endl;
}
Employee(string name, int ID, int age) //constructor
{
Name = name;
EmployeeID = ID;
Age = age;
}

};
class Supervisor:public Employee //inheritance is private by default
{
public:
int salary;
Supervisor(string name, int ID, int age, int Salary)
:Employee(name,ID,age)
{
salary=Salary;
}
void Supervise()
{
cout<<getName()<<" has a salary of "<<salary<<endl;
}

void work()
{
cout<<getName()<<" is collecting reports from all employees"<<endl;
}
};

int main()
{
Employee e1 = Employee("Anna",4567,23);
Supervisor s1 = Supervisor("Happy",23456,24,300000);
e1.work();
s1.work();
}
2. DIFFERENTIATE IMPLEMENTATION OF OOD CONCEPTS BETWEEN
JAVA AND C++
i. In terms of encapsulation both JAVA and C++ use the set and get method which
are public to access the private properties (attributes).

ii. In abstraction, for C++ the abstract class doesn’t use the abstract keyword (and it
is known as contract) as well as its method, instead the method inside the abstract
class is made obligatory that means to force any class that signs this contract
(abstract class) to implement the method by using the virtual keyword and that
class can implement the contract by class classname: contractname
(abstractclassname) WHILE in JAVA it uses the abstract keyword for both the
class and method and uses the extend keyword to access the abstract class.

iii. In Inheritance, JAVA uses the extend keyword for the child class to inherit from
the parent class WHILE in C++ it uses to the colon (:) for the child class to
inherit from the parent class as well as the attributes have to be set to public since
in C++ the attributes are private by default otherwise use the set and get method.

iv. In polymorphism, JAVA uses the extend keyword as well as the method can be
accessed by the object created in the main class WHILE for C++ it uses the colon
(:) or the parent class reference is used to refer to a child class object that is by
creating a pointer of the parent class and assign to it a reference of the child class
(Example classname* pointername = &objectname of the child class) and to
access it, instead of using a dot as applied in JAVA, the pointers created can
access the method by using -> (Example pointername->methodname(); )

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy