We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

# Assignment # 3 - OOP SOLUTION - Let Start Learning Rather Cheating

Aslam o Aleekum Every One,

As you know assignment # 3 is ahead. So Why not try to solve it step by Step. Code only you will do and I will guide you through out.

So First Step is create 7 classes.

Engine

Door

Wheel

Passengers

Bus

Car

Driver

Vehicle

Remember class can't exist until there are attributes or behaviors in the class. therefore some of the attributes and behavior is already given by instructor for vehicle and Car. rest you can think of Own if you want. for example

Engine(engineCapacity:int, engineType:string)

i.e. engine capacity 1500, 1300 etc, engineType patrol, deisle, gas etc

Door(doorWeight: float, doorTransmission:string) , door weight 10.5, 25.2 KG etc, door transmission , automatic, manual

Wheel(diameter:int, type:string) 192 diameter etc and type is tubeless

So Think about all attributes for remaining.

and then below way is of coding step by step for all classes

1. create a class

2. Write attributes defined above as private

3. provide setter and getter for each and every attribute

Things to remember as best coding practice

a. Class name should be Capitalize means if it is single word start Capital if it is multiple word Start every word capital but no space for example if you name your class as AutmaticCar then A and C is capital.

b. all variable in clas should private and camle case which means if it is single word then small alphabet all if it is multi word then first word will be full small and rest all word should start with Capital for example

accountDeposit  , remainingBalance, lastMonthSalary etc

c. function should be public and name of function rule should same as variable

i.e setFuelType, getFuelType,

Step 1. Create a Class

`class Engine {     };Step 2. Write private attributes`
`class Engine {       private:      float engineCapacity;      char* engineType; };Step 3. Write Setter & Getter ( Encapsulation`
`Rule of writing setter and getter is as followsetter method should have no return type but setter must have one argument which should be same type as the attribute name. in this class we have two attributes engineCapacity, and engineType, therefore our setter will bet setEngineCapacity and setEngineTypeas i mentioned earlier function name should be camle casethe body of setter function will be only setting the value to the class member.for Getter there should be same return type as attribute type but no argument`
`class Engine {       private:      float engineCapacity;      char* engineType;  public:    void setEngineCapacity(float capacityParam ){              this->engineCapacity = capacityParam;     }     float getEngineCapacity(){     return this->engineCapacity;    }    void setEngineType(char* typeParam ){         this->engineType = typeParam;   }   char* getEngineType(){      return engineType;    } };`
`Now your next task is to compile this code and write all your classes in this format i suggest your to write all your classes in different cpp files and then include where it needed. you can also write all classes in single cpp file.I will be available from 1:30 pm to 2:15 PM in mondy to thursday. u can discuss there or reply in same thread. Once you complete writing all classes with attribute , setter getters etc then we will move our assignment to next level where we will do Inheritance and composition aggregation as mentioned in assignment.so this will complete our OOP design after that we will move to last step which is implementing business logic and writing the main program to run it.THank you very much.Good Bye TO ready made solutions. `

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?

Views: 4707

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

### Replies to This Discussion

very nice step by step approach , I like it.

Any One who bother to read and follow it? let me know so that next step I guide you.

Assalam o Alikum.

in the 3rd assginment we do not need to write the code for all classes. we just need to wrote code for vehicle and car class. and we have to inherit car from vehicle class.

i want to asked u that should i write constructor for the derived class. please explain how to it.

Yes You need to create constructor in derived class

as below

Car(string colorParam,int distance){
color = colorParam;
if(distance >=1 && distance <=1500){
this->distance = distance;
}else{
cout"Invalid Value";
}
}

Problem Statement:

Keeping in view the above class diagram, you have to write code for the below mentioned classes and show their relationship with each other:

1. Class Vehicle:

Attribute:

vehicleNo: string

color: string

Methods/Operations/Getters/Setters:

getVehicleNo(): string

getColor(): string

2. Class Car:

distance: int

Methods/Operations/Getters/Setters:

setDistance(int): void

calculateFare(int): int

displayInformation(): void

Important points:

• Your program should be able to create a Car object having a number, color and distance without creating an explicit object of Vehicle class.
• All Vehicle attributes should be directly accessible to Car and should not be accessible publically.
• Your program should accept value of distance only between 1-500 kilometers; any other value should be treated as invalid value.
• At the end, information about Car (car number, car color, distance covered) and total fare should be displayed whereas calculateFare(int) is a utility function. Fare is 5 rupees/kilometer.

BEST OF LUCK

Please look at code below and run it. Its working as per your assignment. Earlier i just saw class diagram and gave you idea so that you need to write code for all classes. but as mention by "Glaxy" you need to do only below code.

#include <iostream>
using namespace std;

class Vehicle {
protected:
string vehicleNumber;
string color;

public:
const string& getColor() const {
return color;
}

void setColor(const string& color) {
this->color = color;
}

};
class Car:Vehicle{
public:
Car(string colorParam,int distance){
color = colorParam;
if(distance >=1 && distance <=1500){
this->distance = distance;
}else{
cout"Invalid Value";
}
}
int getDistance() const {
return distance;
}

void setDistance(int distance) {
if(distance >=1 && distance <=1500){
this->distance = distance;
}else{
cout"Invalid Value";
}

}
void setCarNumber(string carNumber) {
this->vehicleNumber = carNumber;
}
string getCarNumber() {
this->vehicleNumber ;
}
int calculateFare(int distance){
return distance * 5;
}
void displayInformation(){
cout"Your Car Number is : " vehicleNumberendl;
cout"The Color of Your Car : " colorendl;
cout"Distance Covered : " distanceendl;
cout"Total fare which you have to pay is : " calculateFare(distance)endl;
}

private:
int distance = 0;

};
int main(){
char option;

string carNumber;
string color;
int distance;
cout"Enter car Number";
cin>>carNumber;
cout"Enter car Colour";
cin>>color;
cout"How long would you like to go ? Enter distance in KM";
cin>>distance;
Car c = Car(color,distance);
c.setCarNumber(carNumber);
c.displayInformation();
do{
cout"Do you want to calculate Fare of the different distance (y/Y for yes and another character for No )? ";
cin>>option;
if(option =='Y' || option == 'y'){
cout"How long would you like to go ? Enter distance in KM";
cin>>distance;
c.setDistance(distance);
c.displayInformation();
}else{
break;
}
}while(1);

return 1;
}

angle brackets are not printed in this post so use ang bracets before endl

Compiler apko error khud batata hy k kis line pe error hy aur kia error hy. as i mentioned earlier that angle bracties are missing with endl same is the case with ur CPP error is on line 48 where "distanceend" is written u need put angle bracets there

cout"Distance Covered : " distanceendl;

Line 52

private:
int distance = 0;
};

Error(ISO C++ forbids initializing of member distance)

ap sb logon ne ik ghlti ki h
distance 1 se 500 tk rkhna h sb logon ne jo code upload kiya h idr sb ne distance 1500 km set kiya h

run nhi ho rha code sir

Aslam O Alaikum

Dear all students I have problem with assignment no.3. In assignment image which teacher give us, output shows not any color, I mean empty. But in solutions which students are posting shows color output. Any suggestions?

## Latest Activity

Noman Ijaz liked + ! ! ! ❣ Sanam ❣ !+'s profile
54 minutes ago
Soldier liked Sukaina's profile
1 hour ago
Bilal joined +M.Tariq Malik's group

### MTH001 Elementary Mathematics

1 hour ago
Preety Girl is now a member of Virtual University of Pakistan
1 hour ago
Mani Siddiqui BS VIII liked + ! ! ! ❣ Sanam ❣ !+'s profile
3 hours ago
maheen mahan joined +M.Tariq Malik's group

### CS502 Fundamentals of Algorithms

7 hours ago
maheen mahan added a discussion to the group CS610 Computer Network

### cs610 gdb idea solution spring2020

8 hours ago
8 hours ago
8 hours ago
"hi i am new here! any one from sailkot?"
8 hours ago
+ ! ! ! ! !Marshmallow updated their profile
16 hours ago
17 hours ago

1

2

3