0% found this document useful (0 votes)
14 views13 pages

1

Uploaded by

Muhammad Sarmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

1

Uploaded by

Muhammad Sarmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

OBJECT ORIENTED

PROGRAMMING

Adeel M. Syed
[email protected]
LECTURE PLAN
1. Introduction to Visual C++ / Visual Studio. Net
2. Structures & Classes.
3. Function Overloading & Default Arguments.
4. Friend Function & Friend Class
5. Constructor & Destructor
6. Operator Overloading.
7. C++ Standard String Class. MID TERM EXAM
8. Static Variable & Functions.
9. Inheritance.
10. Virtual Function & Templates (Polymorphism).
11. File Streams.
12. Exception Handling.
13. Project. FINAL EXAM
Introduction to Visual Studio .Net

• Visual Studio .NET is a complete set of development


tools for building Web applications, XML Web
services, Desktop applications, and Mobile
applications.

• Visual Basic .NET, Visual C++ .NET, Visual C# .NET, and


Visual J# .NET all use the same integrated
development environment (IDE), which allows them
to share tools and facilitates in the creation of mixed-
language solutions.
Creating New Project :
• File – New – Project
• Project Types: Visual C++ Project
• Templates: Empty Project (.NET)
Window Console 32 Application (Visual C++)
• Name: Project Name
• Location: Location to Save

File – New – file


Categories: Visual C++
Templates: C++ file (.CPP)
Write Code & Save it at Appropriate location.

File – Move Source1.CPP into Project -


Select Appropriate Project Name.
Structure
• A structure is a collection of simple variables of different
data types.
• The data in a structure is called “members of the
structure”.
• The keyword “struct” introduces the structure
definition.

EXAMPLE :
struct part
{
int modelnumber;
float cost;
};
Structure (Contd.)
• Next to struct is structure name (or Tag).

• The declaration of the structure members are enclosed in braces.

• Each structure definition must end with a semicolon ;

• Two different structures may contain members of the same


name.

• Members of the structure can be accessed by the DOT


OPERATOR. (e.g. part.cost)

• Data members cannot be initialized in structure except “const


static integral data members”.
struct dist cout<<d1.feet<<endl;
{ cout<<d2.feet<<endl;
int feet; cout<<d1.inches<<endl;
float inches; cout<<d2.inches<<endl;
};
void main( ) int f = d1.feet + d2.feet;
{ float i = d1.inches +
dist d1; d2.inches;
cin>>d1.feet; i /=12;
cin>>d1.inches; f += i;
dist d2 = { 30,40 cout<<f<<“ Feet ”;
}; getch( );
}
struct Dist void main( )
{ {
int feet; Room dining;
float inches; dining.length.feet = 13;
dining.length.inches = 6;
}; dining.width.feet = 10;
dining.width.inches = 5;
struct Room float length = dining.length.feet +
{ (dining.length.inches/12);
Dist length; float width = dining.width.feet +
(dining.width.inches/12);
Dist width;
}; cout<<“\n Length: "<< length;
cout<<“\n Width: "<< width;
getch( );
}
Passing Objects to a function:
Similar to passing variables to functions , one may pass the
objects of a structure to a function.

Vice Versa, objects can also be returned from a function.


Q1.
Create a employee structure. The member data
should comprise one integer for storing the
employee id, one long integer for storing his
salary, and a floating number for storing the
employee’s pension. Create two functions, one
for entering this data and other to display it.
Write a main( ) that allows the user to call these
functions.
Q2: Calculate Areas.

Press

1 To calculate Area of Circle (Π R2)


2 To calculate Area of Square (L2)
3 To calculate Area of Rectangle (L*W)
4 To calculate Area of Triangle (B*H*0.5)
Q3:

Write a C++ structure function which converts a sum


of money given as an integer number of pence into a
floating point value representing the equivalent
number of pounds. For example 365 pence would be
3.65 pounds.

You might also like