1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

M The University Of Michigan Andrew M. Morgan Andrew M Morgan1 EECS Lecture 03 Savitch Ch. 3-4, Misc More on Functions Memory, Activation Records,
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
Starting Out with C++, 3 rd Edition 1 Chapter 11 – Structured Data Abstract data types (ADTs) are data types created by the programmer. ADTs have their.
Starting Out with C++, 3 rd Edition 1 Chapter 14 – More About Classes.
Inheritance (2).
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Template Implicit function overload. Function overload Function overload double ssqq(double & a, double & b) { return(a*b);} float ssqq(float & a, float.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
1 CSC241: Object Oriented Programming Lecture No 21.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Pointers. andy = 25; fred = andy; ted = &andy; andy = 25; ted = &andy; beth = *ted;
Revision.
Introduction to Programming Lecture 39. Copy Constructor.
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
String in C++. String Series of characters enclosed in double quotes.“Philadelphia University” String can be array of characters ends with null character.
Sort the given string, without using string handling functions.
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Function Overloading. 2 Function Overloading (Function Polymorphism) Function overloading is a feature of C++ that allows to create multiple functions.
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Passing arguments by value void func (int x) { x = 4; }... int a = 10;... func(a); cout
CS Oct 2006 Chap 6. Functions General form; type Name ( parameters ) { … return value ; }
Multiple-Subscripted Array
 Review structures  Program to demonstrate a structure containing a pointer.
Chapter 1 Quiz Questions (CGS-3464) Mahendra Kumar
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Switch Statement in C++. Syntax switch (selector) { case L1: statements1; break; case L2: statements2; break; … default: statements_n; } Semantics: This.
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Structure TDate struct TDate { int year, month, day; }; // Define a new data type.
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Class 15 - Overhead 1Object Oriented Programming Using C #include class telephone { public: telephone(char *number, int volume); int dial(char *outgoing_number);
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Lecture 20 Polymorphism. Introduction General meaning ; the ability to take on different forms. Programming language term: –Allows an entity to take a.
Introduction to Programming Lesson 3. #include #include main ( ) { cout
Comparison of Batak & C++. Hello world C++ #include int main() { cout
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Static Variables. Function Scope  “Normal” local variables go out of scope and are deallocated when a function terminates.
Virtual Functions Use a single pointer variable to refer to the objects of different classes. That is the base class pointer. The compiler ignores the.
Introduction to Programming
C++ Arrays.
Null-Terminated Character Arrays
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
Introduction to Programming
The Run-Time Stack and Reference Parameters
Introduction to Programming
CS 1430: Programming in C++.
Default Arguments.
Dynamic Memory A whole heap of fun….
Objective - To subtract decimals.
VEHICLE TECHNOLOGY AIR CONDITIONING SYSTEMS.
VEHICLE TECHNOLOGY BRAKE SYSTEMS.
Introduction to Programming
BCA-II Object Oriented Programming using C++
Function Overloading.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Inline Functions.
The Stack.
CS150 Introduction to Computer Science 1
Complete Vehicle Systems.
Presentation transcript:

1 Class Vehicle #include #define N 10../.

2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];

3 Class Vehicle vehicle(); void move(){cout << "Moving!...\n";} void stop(){cout << "Stopped!...\n";} void showAttributes(); void setSpeed(float theSpeed) {speed = theSpeed;} float getSpeed() {return speed;} };

4 Class Vehicle vehicle::vehicle() { speed = 0.0; cout << "Enter colour of the vehicle :"; cin.getline(colour, N); cout << "\n"; cout << "Enter make of the vehicle :"; cin.getline(make, N); cout << "\n"; }

5 Class Vehicle void vehicle::showAttributes() { cout << "This vehicle is a " << colour << " " << make << " with max speed of " << getSpeed() << " mph " << "\n"; }

6 Class Vehicle class PersonPoweredVehicle:public vehicle { protected: int wheels; };

7 Class Vehicle class Bicycle:public PersonPoweredVehicle { public: int gear; };

8 Class Vehicle class EnginePoweredVehicle:public vehicle{ protected: bool EngineState; public: EnginePoweredVehicle(){EngineState = false;} void StartEngine(); void StopEngine(); void move();};

9 Class Vehicle void EnginePoweredVehicle::StartEngine() { if(EngineState == false) { cout << "The engine is now on!...\n"; EngineState = true; }

10 Class Vehicle else cout << "The engine is already on!...\n"; }

11 Class Vehicle void EnginePoweredVehicle::StopEngine(){ if(EngineState == false) cout << "The engine is off anyway!...\n"; else{ stop(); EngineState = false; cout << "The engine is now off!...\n";} }

12 Class Vehicle void EnginePoweredVehicle::move() { if(EngineState == false) StartEngine(); cout << "Moving!...\n"; }

13 Class Vehicle class TwoWheeledEPV:public EnginePoweredVehicle { };

14 Class Vehicle class FourWheeledEPV:public EnginePoweredVehicle { };

15 Class Vehicle class Motorcycle:public TwoWheeledEPV { protected: int passenger; public: Motorcycle(){passenger = 1;} int getPassenger() const {return passenger;} };

16 Class Vehicle class Scooter:public TwoWheeledEPV { protected: int passenger; public: Scooter(){passenger = 2;} int getPassenger() const {return passenger;} };

17 Class Vehicle class Moped:public TwoWheeledEPV { protected: int passenger; public: Moped(){passenger = 2;} int getPassenger() const {return passenger;} };

18 Class Vehicle main() { Motorcycle M; M.setSpeed(150); cout << "That takes " << M.getPassenger() << " passengers\n"; M.showAttributes();

19 Class Vehicle M.move(); M.StartEngine(); M.StopEngine(); return 0; }