diff --git a/Circle_Task2.cpp b/Circle_Task2.cpp new file mode 100644 index 0000000..72c8ae0 --- /dev/null +++ b/Circle_Task2.cpp @@ -0,0 +1,12 @@ +#include "Circle_Task2.h" + +Circle::Circle(char* pSomeColor, int SomeCoord, float SomeRadius) : mRadius(SomeRadius), Shape(pSomeColor, SomeCoord) { } + +void Circle::Draw() { + cout << "Drawing a Circle of radius " << mRadius << " ." << endl; + Shape::Draw(); +} + +float Circle::ComputeArea() { + return (3.1429*mRadius*mRadius); +} \ No newline at end of file diff --git a/Circle_Task2.h b/Circle_Task2.h new file mode 100644 index 0000000..4eb9380 --- /dev/null +++ b/Circle_Task2.h @@ -0,0 +1,14 @@ +#ifndef CIRCLE_HEADER_Task2 +#define CIRCLE_HEADER_Task2 + +#include "Shape_Task2.h" + +class Circle :public Shape{ + float mRadius; +public: + Circle(char* = NULL, int = 0, float = 0.0); + void Draw(); + float ComputeArea(); +}; + +#endif \ No newline at end of file diff --git a/Doctor_Task1.cpp b/Doctor_Task1.cpp new file mode 100644 index 0000000..c315d03 --- /dev/null +++ b/Doctor_Task1.cpp @@ -0,0 +1,41 @@ +#include "Doctor_Task1.h" + +Doctor::Doctor(char* aName, int anAge, char aGender, char* aDesignation, int aSalary) :Person(aName, anAge, aGender), Designation(aDesignation), Salary(aSalary) { + if (aDesignation != NULL) { + int len = strlen(aDesignation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, aDesignation); + } + else { + Designation = new char; + strcpy_s(Designation, 1, "\0"); + } +} + +Doctor::Doctor(const Doctor& rhs) :Person(rhs) { + int len = strlen(rhs.Designation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, rhs.Designation); +} + +Doctor::~Doctor() { + if (Designation){ + delete[] Designation; + } +} + +Doctor& Doctor::operator = (const Doctor& rhs) { + Person::operator = (rhs); + int len = strlen(rhs.Designation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, rhs.Designation); + return *this; +} + +void Doctor::checkUp() { + cout << getName() << " is checking up." << endl; +} + +void Doctor::prescribe() { + cout << getName() << " is giving prescribtion." << endl; +} \ No newline at end of file diff --git a/Doctor_Task1.h b/Doctor_Task1.h new file mode 100644 index 0000000..94502da --- /dev/null +++ b/Doctor_Task1.h @@ -0,0 +1,18 @@ +#ifndef Doctor_HEADER_Task1 +#define Doctor_HEADER_Task1 + +#include"Person_Task1.h" + +class Doctor :public Person { + char* Designation; + int Salary; +public: + Doctor(char* = NULL, int = 0, char = '\0', char* = NULL, int = 0); + Doctor(const Doctor&); + ~Doctor(); + Doctor& operator = (const Doctor&); + void checkUp(); + void prescribe(); +}; + +#endif \ No newline at end of file diff --git a/Line_Task2.cpp b/Line_Task2.cpp new file mode 100644 index 0000000..d42b86e --- /dev/null +++ b/Line_Task2.cpp @@ -0,0 +1,8 @@ +#include "Line_Task2.h" + +Line::Line(char* pSomeColor, int SomeCoord, float SomeLength) : mLength(SomeLength), Shape(pSomeColor, SomeCoord) { } + +void Line::Draw() { + cout << "Drawing a Line of length " << mLength << " ." << endl; + Shape::Draw(); +} \ No newline at end of file diff --git a/Line_Task2.h b/Line_Task2.h new file mode 100644 index 0000000..4c52e5f --- /dev/null +++ b/Line_Task2.h @@ -0,0 +1,13 @@ +#ifndef LINE_HEADER_Task2 +#define LINE_HEADER_Task2 + +#include "Shape_Task2.h" + +class Line :public Shape{ + float mLength; +public: + Line(char* = NULL, int = 0, float = 0.0); + void Draw(); +}; + +#endif \ No newline at end of file diff --git a/Person_Task1.cpp b/Person_Task1.cpp new file mode 100644 index 0000000..de73643 --- /dev/null +++ b/Person_Task1.cpp @@ -0,0 +1,44 @@ +#include "Person_Task1.h" + +Person::Person(char* aName, int anAge, char aGender) :Name(aName), Age(anAge), Gender(aGender) { + if (aName != NULL) { + int len = strlen(aName) + 1; + Name = new char[len]; + strcpy_s(Name, len, aName); + } + else { + Name = new char; + strcpy_s(Name, 1, "\0"); + } +} + +Person::Person(const Person& rhs) { + int len = strlen(rhs.Name) + 1; + Name = new char[len]; + strcpy_s(Name, len, rhs.Name); +} + +Person::~Person() { + if (Name){ + delete [] Name; + } +} + +Person& Person:: operator = (const Person& rhs) { + int len = strlen(rhs.Name) + 1; + Name = new char[len]; + strcpy_s(Name, len, rhs.Name); + return *this; +} + +void Person::eat() { + cout << Name << " is eating." << endl; +} + +void Person::walk() { + cout << Name << " is walking." << endl; +} + +const char * Person::getName()const { + return Name; +} \ No newline at end of file diff --git a/Person_Task1.h b/Person_Task1.h new file mode 100644 index 0000000..d886d06 --- /dev/null +++ b/Person_Task1.h @@ -0,0 +1,23 @@ +#ifndef Person_HEADER_Task1 +#define Person_HEADER_Task1 + +#include +using namespace std; + +class Person { + char* Name; + int Age; + char Gender; +public: + Person(char* = NULL, int = 0, char = '\0'); + Person(const Person&); + ~Person(); + Person& operator = (const Person&); + + void eat(); + void walk(); + + const char * getName()const; +}; + +#endif \ No newline at end of file diff --git a/Person_Task3.cpp b/Person_Task3.cpp new file mode 100644 index 0000000..4b99795 --- /dev/null +++ b/Person_Task3.cpp @@ -0,0 +1,29 @@ +#include "Person_Task3.h" + +Person::Person(char * aName, int anAge, char aGender) : Name(aName), Age(anAge), Gender(aGender){ + if (aName != NULL) { + int len = strlen(aName) + 1; + Name = new char[len]; + strcpy_s(Name, len, aName); + } + else{ + Name = new char; + strcpy_s(Name, 1, "\0"); + } +} + +void Person::eat(){ + cout << Name << " is eating." << endl; +} + +void Person::walk(){ + cout << Name << " is walking." << endl; +} + +const char * Person::getName()const{ + return Name; +} + +char Person::getGender()const{ + return Gender; +} \ No newline at end of file diff --git a/Person_Task3.h b/Person_Task3.h new file mode 100644 index 0000000..2b581c2 --- /dev/null +++ b/Person_Task3.h @@ -0,0 +1,20 @@ +#ifndef Person_HEADER_Task3 +#define Person_HEADER_Task3 + +#include +using namespace std; + +class Person{ + char * Name; + int Age; + char Gender; +public: + Person(char * = NULL, int = 0, char = '\0'); + void eat(); + void walk(); + + const char * getName()const; + char getGender()const; +}; + +#endif \ No newline at end of file diff --git a/PostgraduateStudent_Task3.cpp b/PostgraduateStudent_Task3.cpp new file mode 100644 index 0000000..731c9e9 --- /dev/null +++ b/PostgraduateStudent_Task3.cpp @@ -0,0 +1,11 @@ +#include "PostgraduateStudent_Task3.h" + +PostgraduateStudent::PostgraduateStudent(char * aName, int anAge, char aGender, char * aProgram, int aStudyYear, int aProgramLength) : ProgramLength(aProgramLength), Student(aName, anAge, aGender, aProgram, aStudyYear) { } + +void PostgraduateStudent::teach() { + cout << getName() << " is teaching." << endl; +} + +int PostgraduateStudent::getProgramLength()const { + return ProgramLength; +} \ No newline at end of file diff --git a/PostgraduateStudent_Task3.h b/PostgraduateStudent_Task3.h new file mode 100644 index 0000000..5aaf338 --- /dev/null +++ b/PostgraduateStudent_Task3.h @@ -0,0 +1,14 @@ +#ifndef PostgraduateStudent_HEADER +#define PostgraduateStudent_HEADER + +#include "Student_Task3.h" + +class PostgraduateStudent :public Student { + int ProgramLength; +public: + PostgraduateStudent(char * = NULL, int = 0, char = '\0', char * = NULL, int = 0, int = 0); + void teach(); + int getProgramLength()const; +}; + +#endif \ No newline at end of file diff --git a/Shape_Task2.cpp b/Shape_Task2.cpp new file mode 100644 index 0000000..bb2e97d --- /dev/null +++ b/Shape_Task2.cpp @@ -0,0 +1,54 @@ +#include "Shape_Task2.h" + +Shape::Shape(char* pSomeColor, int SomeCoord) : mColor(pSomeColor), mCoord(SomeCoord){ + if (pSomeColor != NULL) { + int Len = strlen(pSomeColor) + 1; + mColor = new char[Len]; + strcpy_s(mColor, Len, pSomeColor); + } + else { + int Len = strlen("invisible") + 1; + mColor = new char[Len]; + strcpy_s(mColor, Len, "invisible"); + } +} + +Shape::Shape(const Shape& rhs) { + int len = strlen(rhs.mColor) + 1; + mColor = new char[len]; + strcpy_s(mColor, len, rhs.mColor); +} + +Shape::~Shape() { + if (mColor){ + delete[] mColor; + } +} + +Shape& Shape::operator = (const Shape& rhs) { + int len = strlen(rhs.mColor) + 1; + mColor = new char[len]; + strcpy_s(mColor, len, rhs.mColor); + return *this; +} + +void Shape::Draw() { + cout << "The Shape is drawn in " << mColor <<" color." << endl; +} + +void Shape::Rotate() { + cout << "Rotating a Shape of " << mColor << " color." << endl; +} + +void Shape::SetColor(char* pSomeColor) { + if (pSomeColor != NULL) { + int Len = strlen(pSomeColor) + 1; + mColor = new char[Len]; + strcpy_s(mColor, Len, pSomeColor); + } + else { + int Len = strlen("invisible") + 1; + mColor = new char[Len]; + strcpy_s(mColor, Len, "invisible"); + } +} \ No newline at end of file diff --git a/Shape_Task2.h b/Shape_Task2.h new file mode 100644 index 0000000..c637ff2 --- /dev/null +++ b/Shape_Task2.h @@ -0,0 +1,20 @@ +#ifndef SHAPE_HEADER_Task2 +#define SHAPE_HEADER_Task2 + +#include +using namespace std; + +class Shape{ + char* mColor; + int mCoord; +public: + Shape(char* = NULL, int = 0); + Shape(const Shape&); + ~Shape(); + Shape& operator = (const Shape&); + void Draw(); + void Rotate(); + void SetColor(char*); +}; + +#endif \ No newline at end of file diff --git a/Student_Task1.cpp b/Student_Task1.cpp new file mode 100644 index 0000000..956172f --- /dev/null +++ b/Student_Task1.cpp @@ -0,0 +1,40 @@ +#include"Student_Task1.h" +Student::Student(char* aName, int anAge, char aGender, char* aProgram, int aStudyYear) :Person(aName, anAge, aGender), Program(aProgram), StudyYear(aStudyYear) { + if (aProgram != NULL) { + int len = strlen(aProgram) + 1; + Program = new char[len]; + strcpy_s(Program, len, aProgram); + } + else { + Program = new char; + strcpy_s(Program, 1, "\0"); + } +} + +Student::Student(const Student& rhs) : Person(rhs) { + int len = strlen(rhs.Program) + 1; + Program = new char[len]; + strcpy_s(Program, len, rhs.Program); +} + +Student::~Student() { + if (Program) { + delete[] Program; + } +} + +Student& Student::operator = (const Student& rhs) { + Person::operator = (rhs); + int len = strlen(rhs.Program) + 1; + Program = new char[len]; + strcpy_s(Program, len, rhs.Program); + return *this; +} + +void Student::study() { + cout << getName() << " is studying." << endl; +} + +void Student::heldExam() { + cout << getName() << " is giving exam." << endl; +} \ No newline at end of file diff --git a/Student_Task1.h b/Student_Task1.h new file mode 100644 index 0000000..f69d84e --- /dev/null +++ b/Student_Task1.h @@ -0,0 +1,18 @@ +#ifndef Student_HEADER_Task1 +#define Student_HEADER_Task1 +#include"Person_Task1.h" + +class Student :public Person { + char* Program; + int StudyYear; +public: + Student(char* = NULL, int = 0, char = '\0', char* = NULL, int =0); + Student(const Student&); + ~Student(); + Student& operator = (const Student&); + + void study(); + void heldExam(); +}; + +#endif \ No newline at end of file diff --git a/Student_Task3.cpp b/Student_Task3.cpp new file mode 100644 index 0000000..3e463af --- /dev/null +++ b/Student_Task3.cpp @@ -0,0 +1,29 @@ +#include "Student_Task3.h" + +Student::Student(char * aName, int anAge, char aGender, char * aProgram, int aStudyYear) : Program(aProgram), StudyYear(aStudyYear), Person(aName, anAge, aGender){ + if (aProgram != NULL) { + int len = strlen(aProgram) + 1; + Program = new char[len]; + strcpy_s(Program, len, aProgram); + } + else{ + Program = new char; + strcpy_s(Program, 1, "\0"); + } +} + +void Student::study(){ + cout << getName() << " is studying." << endl; +} + +void Student::heldExam(){ + cout << getName() << " is taking exam." << endl; +} + +const char * Student::getProgram()const{ + return Program; +} + +int Student::getStudyYear()const{ + return StudyYear; +} \ No newline at end of file diff --git a/Student_Task3.h b/Student_Task3.h new file mode 100644 index 0000000..9e5177d --- /dev/null +++ b/Student_Task3.h @@ -0,0 +1,17 @@ +#ifndef Student_HEADER +#define Student_HEADER + +#include "Person_Task3.h" + +class Student:public Person{ + char * Program; + int StudyYear; +public: + Student(char * = NULL, int = 0, char = '\0', char * = NULL, int = 0); + void study(); + void heldExam(); + const char * getProgram()const; + int getStudyYear()const; +}; + +#endif \ No newline at end of file diff --git a/Task1_main.cpp b/Task1_main.cpp new file mode 100644 index 0000000..587978c --- /dev/null +++ b/Task1_main.cpp @@ -0,0 +1,24 @@ +#include "Teacher_Task1.h" +#include "Student_Task1.h" +#include "Doctor_Task1.h" + +void main() { + Student s1; { + Student s2("Muhammad Rafael", 17, 'M', "Computer Science", 2014); + s1 = s2; + cout << "Student 2: " << endl << "Name: " << s2.getName() << endl; + + s2.eat(); + s2.walk(); + s2.study(); + s2.heldExam(); + } + + cout << "Student 1: " << endl << "Name: " << s1.getName() << endl; + s1.eat(); + s1.walk(); + s1.study(); + s1.heldExam(); + + system("pause"); +} \ No newline at end of file diff --git a/Task2_main.cpp b/Task2_main.cpp new file mode 100644 index 0000000..3524299 --- /dev/null +++ b/Task2_main.cpp @@ -0,0 +1,19 @@ +#include "Circle_Task2.h" +#include "Line_Task2.h" +#include "Triangle_Task2.h" + +void main(){ + Circle c1; + { + Circle c2("black", 3, 2.3); + c2.SetColor("Light Green"); + c1 = c2; + } + + cout << "Circle 1" << endl; + c1.Draw(); + c1.Rotate(); + cout << "The Area of Circle 1 is: " << c1.ComputeArea() << endl << endl; + + system("pause"); +} \ No newline at end of file diff --git a/Task3_main.cpp b/Task3_main.cpp new file mode 100644 index 0000000..890835a --- /dev/null +++ b/Task3_main.cpp @@ -0,0 +1,40 @@ +#include "Teacher_Task3.h" +#include "UndergraduateStudent_Task3.h" +#include "PostgraduateStudent_Task3.h" + +void main(){ + UndergraduateStudent UGs("Muhammad Rafael", 17, 'M', "Computer Science", 2014,4); + PostgraduateStudent PGs("Bilal Hussain", 23, 'M', "Management Science", 2015, 2); + Teacher t1("Saif Ullah Ijaz", 28, 'M', "Lecturer"); + + cout << "Undergraduate Student : " << endl << "Name: " << UGs.getName() << endl << "Gender: " << UGs.getGender() << endl; + cout << "Program: " << UGs.getProgram() << endl; + cout << "Year of Study: " << UGs.getStudyYear() << endl; + cout << "Program Duration: " << UGs.getProgramLength() << endl; + + UGs.eat(); + UGs.walk(); + UGs.study(); + UGs.heldExam(); + UGs.play(); + + cout << endl << endl; + cout << "Postgraduate Student : " << endl << "Name: " << PGs.getName() << endl << "Gender: " << PGs.getGender() << endl; + cout << "Program: " << PGs.getProgram() << endl; + cout << "Year of Study: " << PGs.getStudyYear() << endl; + cout << "Program Duration: " << PGs.getProgramLength() << endl; + + PGs.eat(); + PGs.walk(); + PGs.study(); + PGs.heldExam(); + PGs.teach(); + + cout << endl << "Teacher 1: " << endl << "Name: " << t1.getName() << endl << "Gender: " << t1.getGender() << endl; + t1.eat(); + t1.walk(); + t1.teach(); + t1.takeExam(); + + system("pause"); +} \ No newline at end of file diff --git a/Teacher_Task1.cpp b/Teacher_Task1.cpp new file mode 100644 index 0000000..90f6fcc --- /dev/null +++ b/Teacher_Task1.cpp @@ -0,0 +1,41 @@ +#include "Teacher_Task1.h" + +Teacher::Teacher(char* aName, int anAge, char aGender, char* aDesignation, int aSalary) :Person(aName, anAge, aGender), Designation(aDesignation), Salary(aSalary) { + if (aDesignation != NULL) { + int len = strlen(aDesignation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, aDesignation); + } + else { + Designation = new char; + strcpy_s(Designation, 1, "\0"); + } +} + +Teacher::Teacher(const Teacher& rhs) :Person(rhs) { + int len = strlen(rhs.Designation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, rhs.Designation); +} + +Teacher::~Teacher() { + if (Designation){ + delete[] Designation; + } +} + +Teacher& Teacher::operator = (const Teacher& rhs) { + Person::operator = (rhs); + int len = strlen(rhs.Designation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, rhs.Designation); + return *this; +} + +void Teacher::teach() { + cout << getName() << " is teaching." << endl; +} + +void Teacher::takeExam() { + cout << getName() << " is taking exam." << endl; +} \ No newline at end of file diff --git a/Teacher_Task1.h b/Teacher_Task1.h new file mode 100644 index 0000000..aef5cb2 --- /dev/null +++ b/Teacher_Task1.h @@ -0,0 +1,17 @@ +#ifndef Teacher_HEADER_Task1 +#define Teacher_HEADER_Task1 +#include"Person_Task1.h" + +class Teacher :public Person { + char* Designation; + int Salary; +public: + Teacher(char* = NULL, int = 0, char = '\0', char* = NULL, int = 0); + Teacher(const Teacher&); ~Teacher(); + Teacher& operator = (const Teacher&); + + void teach(); + void takeExam(); +}; + +#endif \ No newline at end of file diff --git a/Teacher_Task3.cpp b/Teacher_Task3.cpp new file mode 100644 index 0000000..43c4d95 --- /dev/null +++ b/Teacher_Task3.cpp @@ -0,0 +1,21 @@ +#include "Teacher_Task3.h" + +Teacher::Teacher(char * aName, int anAge, char aGender, char * aDesignation, int aSalary) :Designation(aDesignation), Salary(aSalary), Person(aName, anAge, aGender){ + if (aDesignation != NULL) { + int len = strlen(aDesignation) + 1; + Designation = new char[len]; + strcpy_s(Designation, len, aDesignation); + } + else{ + Designation = new char; + strcpy_s(Designation, 1, "\0"); + } +} + +void Teacher::teach(){ + cout << getName() << " is teaching." << endl; +} + +void Teacher::takeExam(){ + cout << getName() << " is taking exam." << endl; +} \ No newline at end of file diff --git a/Teacher_Task3.h b/Teacher_Task3.h new file mode 100644 index 0000000..93ad0fe --- /dev/null +++ b/Teacher_Task3.h @@ -0,0 +1,15 @@ +#ifndef Teacher_HEADER_Task3 +#define Teacher_HEADER_Task3 + +#include "Person_Task3.h" + +class Teacher:public Person{ + char * Designation; + int Salary; +public: + Teacher(char * = NULL, int = 0, char = '\0', char * = NULL, int = 0); + void teach(); + void takeExam(); +}; + +#endif \ No newline at end of file diff --git a/Triangle_Task2.cpp b/Triangle_Task2.cpp new file mode 100644 index 0000000..c92dc9c --- /dev/null +++ b/Triangle_Task2.cpp @@ -0,0 +1,12 @@ +#include "Triangle_Task2.h" + +Triangle::Triangle(char* pSomeColor, int SomeCoord, float SomeAngle) : mAngle(SomeAngle), Shape(pSomeColor, SomeCoord) { } + +void Triangle::Draw() { + cout << "Drawing a Triangle of angle " << mAngle << " ." << endl; + Shape::Draw(); +} + +void Triangle::ComputeArea() { + cout << "Computing the area of Triangle with angle " << mAngle << " ." << endl; +} \ No newline at end of file diff --git a/Triangle_Task2.h b/Triangle_Task2.h new file mode 100644 index 0000000..617546d --- /dev/null +++ b/Triangle_Task2.h @@ -0,0 +1,14 @@ +#ifndef TRIANGLE_HEADER_Task2 +#define TRIANGLE_HEADER_Task2 + +#include "Shape_Task2.h" + +class Triangle :public Shape{ + float mAngle; +public: + Triangle(char* = NULL, int = 0, float = 0.0); + void Draw(); + void ComputeArea(); +}; + +#endif \ No newline at end of file diff --git a/UndergraduateStudent_Task3.cpp b/UndergraduateStudent_Task3.cpp new file mode 100644 index 0000000..1f91b00 --- /dev/null +++ b/UndergraduateStudent_Task3.cpp @@ -0,0 +1,11 @@ +#include "UndergraduateStudent_Task3.h" + +UndergraduateStudent::UndergraduateStudent(char * aName, int anAge, char aGender, char * aProgram, int aStudyYear, int aProgramLength) : ProgramLength(aProgramLength), Student(aName, anAge, aGender, aProgram, aStudyYear) { } + +void UndergraduateStudent::play(){ + cout << getName() << " is playing." << endl; +} + +int UndergraduateStudent::getProgramLength()const{ + return ProgramLength; +} \ No newline at end of file diff --git a/UndergraduateStudent_Task3.h b/UndergraduateStudent_Task3.h new file mode 100644 index 0000000..f2d7a70 --- /dev/null +++ b/UndergraduateStudent_Task3.h @@ -0,0 +1,14 @@ +#ifndef UndergraduateStudent_HEADER +#define UndergraduateStudent_HEADER + +#include "Student_Task3.h" + +class UndergraduateStudent :public Student { + int ProgramLength; +public: + UndergraduateStudent(char * = NULL, int = 0, char = '\0', char * = NULL, int = 0, int = 0); + void play(); + int getProgramLength()const; +}; + +#endif \ No newline at end of file