Docsity

Object Oriented Programming in C++: Lecture Plan and Exercises, Study notes of C programming

Partial preview of the text

Download Object Oriented Programming in C++: Lecture Plan and Exercises and more Study notes C programming in PDF only on Docsity!

OBJECT ORIENTED

PROGRAMMING

Adeel M. Syed Adeel M. Syed [email protected] [email protected]

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 File – New – file Categories: Categories: Visual C++Visual C++ Templates: Templates: C++ file (.CPP)C++ file (.CPP) Write Code & Save it at Appropriate location. Write Code & Save it at Appropriate location. File – Move Source1.CPP into Project File – Move Source1.CPP into Project Select Appropriate Project Name. Select Appropriate Project Name.

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 { int feet; float inches; }; void main( ) { dist d1; cin>>d1.feet; cin>>d1.inches; dist d2 = { 30, }; cout<

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.

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. pounds.

DEFAULT ARGUMENTS

Example: void repchar (char ch=‘x’, int val = 5) ; void main ( ) { repchar( ); repchar( ‘w’ ); \repchar( ‘t’ , 20 ); \repchar( 20 ); getch( ); } void repchar (char ch, int n) { for (int j=0 ; j

Class Assignment (Def. Arg.)

Calculation of Area of SQUARE, RECTANGLE and TRIANGLE. func1 ( ): Comparing condition & calling of function mydef( ) mydef( ): multiply all arguments and print result. main( ): calling func1.

  • (^) Overloading of functions with different return type is not allowed in C++.
  • (^) When an overloaded function is called, the correct function is selected by comparing their argument list.

Examples:

  • (^) void func ( );
  • (^) void func (int a);
  • (^) void func (float a, int b);
  • (^) void func (float a, float b);
  • (^) void func (int a, char b);
  • (^) int func (float a, float b); // illegal function