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

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

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 follow
setter 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 setEngineType
as i mentioned earlier function name should be camle case
the 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 Follow the New Added Discussions at Your Mail Address?

+ 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?


See Your Saved Posts Timeline

Views: 4674

.

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

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

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

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? 

RSS

Latest Activity

Taiba Rajput joined + M.Tariq Malik's group
25 minutes ago
+"Mission Impossible"++ replied to + "αяsαℓ " Ќąƶµяɨ •"'s discussion The World's most expensive Proposal
26 minutes ago
+"Mission Impossible"++ liked + "αяsαℓ " Ќąƶµяɨ •"'s discussion The World's most expensive Proposal
27 minutes ago
+"Mission Impossible"++ liked +Umar Amin+'s discussion Happy Birthday to my sweet and lovely friend mmm
28 minutes ago
Taiba Rajput liked + M.Tariq Malik's group IT430 E-Commerce
32 minutes ago
Taiba Rajput joined + M.Tariq Malik's group
34 minutes ago
M. Umair Shahid left a comment for Sami
37 minutes ago
+ Iuuoɔǝut + posted videos
56 minutes ago
Profile IconTalha Asad, MUHAMMAD SALMAN, FIDA MUHAMMAD KHAN and 9 more joined Virtual University of Pakistan
58 minutes ago
MUHAMMAD SALMAN liked Noorfatima's profile
1 hour ago
+ ! ❤️ ░S░I░N░G░E░R liked + ! ! ! ! ! MySterIouS's discussion ~ Khoobsorat Ahsaas ~
2 hours ago
+ ! ! ! ! ! MySterIouS posted a discussion
3 hours ago
+ ! ! ! ! ! MySterIouS replied to + Iuuoɔǝut +'s discussion Phly Dosti phir mohabbat ......
3 hours ago
+ ! ! ! ! ! ! BLaiRe ! !+ replied to +Umar Amin+'s discussion Happy Birthday to my sweet and lovely friend mmm
4 hours ago
+ ! ! ! ! ! ! BLaiRe ! !+ liked +Umar Amin+'s discussion Happy Birthday to my sweet and lovely friend mmm
4 hours ago
彡Tweety彡 ❤️ replied to + "αяsαℓ " Ќąƶµяɨ •"'s discussion The World's most expensive Proposal
6 hours ago
彡Tweety彡 ❤️ replied to + Iuuoɔǝut +'s discussion Phly Dosti phir mohabbat ......
6 hours ago
KAMRAN replied to + M.Tariq Malik's discussion MGT611 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 14-11-2019 in the group MGT611 Business & Labor Law
7 hours ago
+ Abb@s replied to + Iuuoɔǝut +'s discussion Phly Dosti phir mohabbat ......
7 hours ago
Profile IconKAMRAN and kiran ashraf joined + M.Tariq Malik's group
7 hours ago

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service