Object Oriented Programming

Published on June 2017 | Categories: Documents | Downloads: 48 | Comments: 0 | Views: 432
of 53
Download PDF   Embed   Report

Comments

Content

Institute of Business & Technology (Object Oriented Programming)

Object Oriented Programming

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
LIST OF EXPERIMENTS 1. To learn how to write first C++ Program. 2. To learn arithmetic operations and expression in C++ . 3. To learn iteration in C++ . 4. To learn increment and decrement operations in C++ . 5. To learn FOR loop in C++ 6.To learn function creation in C++ . 7.To learn parameters in C++ . 8.To learn operator overloading in C++ . 9.To learn class in C++ Program.

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
INDEX S.N O. NAME OF THE EXPERIMENT PERFORMED DATE SUBMITTED DATE PAGE NO. REMARKS

__________________________ SIGNATURE OF FACULTY

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
C++ AND OBJECT-ORIENTED PROGRAMMING: Object-oriented programming (OOP) is a currently popular and powerful programming technique. The main characteristics of OOP are encapsulation, inheritance, and polymorphism. Encapsulation is a form of information hiding or abstraction. Inheritance has to do with writing reusable code. Polymorphism refers to a way that a single name can have multiple meanings in the context of inheritance. Having made those statements, we must admit that they will hold little meaning for readers who have not heard of OOP before. C++ TERMINOLOGY All procedure-like entities are called functions in C++. Things that are called procedures, methods, functions, or subprograms in other languages are all called functions in C++. A C++ program is basically just a function called main; when you run a program, the run-time system automatically invokes the function named main. Other C++ terminology is pretty much the same as most other programming languages, and in any case, will be explained when each concept is introduced. A C++ program is really a function definition for a function named main. When the program is run, the function named main is invoked. The body of the function main is enclosed in braces, {}. When the program is run, the statements in the braces are executed. The following two lines set up things so that the libraries with console input and output facilities are available to the program. #include <iostream> using namespace std; The following line says that main is a function with no parameters that returns an int (integer) value: int main( ) Some compilers will allow you to omit the int or replace it with void, which indicates a function that does not return a value. However, the above form is the most universally accepted way to start the main function of a C++ program. The program ends when the following statement is executed:return 0;

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

EXPERIMENT NO. 01
Title: - To learn how to write first C++ Program. Objective: - To display a sample comment using basic operators of C++ . It’s a simple C++ program and two possible screen displays that might be generated when a user runs the program. (I) Practical Significance: - A C++ program is really a function definition for a function named main. When the program is run, the function named main is invoked. The body of the function main is enclosed in braces,{}. When the program is run, the statements in the braces are executed. Students will learn the usage of int main(),return 0,variable declaration , cin>> ,cout<< and If else statement. (II) Competency Skill: - generic & hence should be repeated in several experiments. (III) Experiment Objective: 1. To learn basic variables declaration in C++. 2. To find basic characteristics of loop . (IV) Theoretical Background: If you have not programmed in C++ before, then the use of cin and cout for console I/O is likely to be new to you. That topic is covered a little later in this chapter, but the general idea can be observed in this sample program. For example, consider the following two lines from forthcoming program cout << "How many programming languages have you used? "; cin >> numberOfLanguages; The first line outputs the text within the quotation marks to the screen. The second line reads in a number that the user enters at the keyboard and sets the value of the variable numberOfLanguages to this number. The lines cout << "Read the preface. You may prefer\n" << "a more elementary book by the same author.\n";
Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
output two strings instead of just one string. The symbolism \n is the newline character, which instructs the computer to start a new line of output. Although you may not yet be certain of the exact details of how to write such statements, you can probably guess the meaning of the ifelse statement.
(V) C++ Experiment Code: -

(VI) Resource required: - Dev C++

(VII) Precautions: 1. It’s a case sensitive software. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
2. Use preprocessor directives E.g.# include & using namespace std; 3. Curly braces are necessary after int main(). 4. For debug use F8 and execution use Cntrl+F9.

(VIII) Procedure: 1. Write a program as per mentioned above in Dev C++. 2. Ctrl+N for new C++ program. 3. Ctrl+F9 for compile. 4. Ctrl+F10 to Run the program. 5. Following is the main menu of Dev C++.

(IX) Observation or Calculations: 1. Type your observation =……………………………. 2. ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 1. Student must type the result or output of the program=…………………………………….. 2. ____________________________________________________________________________________ ____________________________________________________________________. (XI) INTERPRETATION OF RESULT: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(XII) CONCLUSION: -

(XIII) Experiment Related Que.1. Define main() , return 0 , cin>> , cout<< , loop. 2. Define variables. 3. Define preprocessor directives, and their significance. 4. Display your name in C++ with your facebook ID. (XIV) Assessment:S.No. 1 2 3 4 5 1 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result 2 2 2 2 2 Product 2.5 Developed by:Adnan Alam
Khan([email protected])

Max.Mark

Obtained

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
2 3 4 Interpretation of Result Dev C++ handling Viva 2.5 2.5 2.5

(XV)Desired Output:-

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 02
Title: - To learn arithmetic operations and expression in C++ . Objective: - Aim of this lab to teach the use of declaration modifier constant. (I) Practical Significance: - As in most other languages, C++ allows you to form expressions using variables, constants, and the arithmetic operators: + (addition), - (subtraction), * (multiplication),/ (division), and % (modulo, remainder). These expressions can be used anyplace it is legal to use a value of the type produced by the expression. All the arithmetic operators can be used with numbers of type int, numbers of type double, and even with one number of each type. However, the type of the value produced and the exact value of the result depend on the types of the numbers being combined. If both operands (that is, both numbers) are of type int, then the result of combining them with an arithmetic operator is of type int. If one or both of the operands are of type double, then the result is of type double. (II) Competency Skill: - generic & hence should be repeated in several mathematical experiments. (III) Experiment Objective: 3. To learn basic variables declaration in C++. 4. To find basic characteristics of loop . (IV) Theoretical Background: You can specify the order of operations in an arithmetic expression by inserting parentheses. If you omit parentheses, the computer will follow rules called precedence rules that determine the order in which the operations, such as addition and multiplication, are performed. When used with one or both operands of type double, the division operator, /,behaves as you might expect. However, when used with two operands of type int, the division operator yields the integer part resulting from division. In other words, integer division discards the part after the decimal point. So, 10/3 is 3 (not 3.3333…), 5/2 is 2 (not 2.5), and 11/3 is 3 (not 3.6666…). Notice that the number is not rounded ; the part after the decimal point is discarded no matter how large it is. The operator % can be used with operands of type int to recover the information lost when you use / to do division with numbers of type int. When used with values of type int, the two operators / and % yield the two numbers produced when you perform the
Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
long division algorithm you learned in grade school. For example, 17 divided by 5 yields 3 with a remainder of 2.

(V) C++ Experiment Code: -

(VI) Resource required: - Dev C++

(VII) Precautions: 5. Use BODMAS rule for arithmetic operations. 6. Here we use int and double data types for different types of operations. 7. Here RATE is used as NAMING CONSTANTS with the const MODIFIER. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
8. For debug use F8 and execution use Cntrl+F9.

(VIII) Procedure: 6. Write a program as per mentioned above in Dev C++. 7. Ctrl+N for new C++ program. 8. Ctrl+F9 for compile. 9. Ctrl+F10 to Run the program. 10.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 3. Type your observation =……………………………. 4. ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 3. Student must type the result or output of the program=…………………………………….. 4. ____________________________________________________________________________________ ____________________________________________________________________. (XI) INTERPRETATION OF RESULT: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(XII) CONCLUSION: -

(XIII) Experiment Related Que.5. Define main() , return 0 , cin>> , cout<< , loop. 6. Define NAMING CONSTANTS. 7. Define operator precedence, and their significance. 8. How income tax will be deducted from salary above 0.5 million, where tax return is 5%. (XIV) Assessment:S.No. 1 2 3 4 5 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership 2 2 2 2 2 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
Product 1 2 3 4 Desired Result Interpretation of Result Dev C++ handling Viva 2.5 2.5 2.5 2.5

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 03
Title: - To learn iteration in C++ . Objective: - The Aim of this lab to teach loops in C++. (I) Practical Significance: - Looping mechanisms in C++ are similar to those in other high-level languages. The three C++ loop statements are the while statement, the do-while statement, and the for statement. The same terminology is used with C++ as with other languages. The code that is repeated in a loop is called the loop body. Each repetition of the loop body is called an iteration of the loop. (II) Competency Skill: - generic & hence should learn loops with mathematical expression. (III) Experiment Objective: 5. To learn While and Do while statements declaration in C++. 6. To find basic characteristics of loop . (IV) Theoretical Background: The syntax for the while statement and its variant, the dowhile statement, is given in the accompanying box. In both cases, the multi-statement body syntax is a special case of the syntax for a loop with a single-statement body. The multi-statement body is a single compound statement. Examples of a while statement and a do-while statement are given in following figures.

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(VI) Resource required: - Dev C++

(VII) Precautions: 9. Semi colon usage will be treated as loop termination. 10.Boolean expression is checked before execution. 11.If condition is true loop will execute else stopped. 12.For debug use F8 and execution use Cntrl+F9.

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(VIII) Procedure: 11.Write a program as per mentioned above in Dev C++. 12.Ctrl+N for new C++ program. 13.Ctrl+F9 for compile. 14. Ctrl+F10 to Run the program. 15.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 5. Type your observation =……………………………. 6. ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 5. Student must type the result or output of the program=…………………………………….. 6. ____________________________________________________________________________________ ____________________________________________________________________. (XI) INTERPRETATION OF RESULT: -

(XII) CONCLUSION: Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(XIII) Experiment Related Que.9. Define while, do-while and For. 10. How to transform while loop into for loop. 11. Define Boolean checking. 12. What is the difference between loop body and iteration. (XIV) Assessment:S.No. 1 2 3 4 5 1 2 3 4 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result Interpretation of Result Dev C++ handling Viva 2 2 2 2 2 Product 2.5 2.5 2.5 2.5 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 04
Title: - To learn increment and decrement operations in C++ . Objective: - The Aim of this lab to teach increment and decrement operators expressions in C++. (I) Practical Significance: - In general, we discourage the use of the increment and decrement operators in expressions. However, many programmers like to use them in the controlling Boolean expression of a while or do-while statement. If done with care, this can work out satisfactorily. An example is given in Display 2.6. Be sure to notice that in count++ <= number-OfItems, the value returned by count++ is the value of count before it is incremented. (II) Competency Skill: - generic & hence should learn a++ or b—for controlling the expression. (III) Experiment Objective: 7. To learn increment & decrement declaration in C++. 8. To find its usage in controlled expressions. (IV) Theoretical Background: The aim of this expression is to control the expression execution and the following program will explain its usage in more efficient manners.

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(VI) Resource required: - Dev C++

(VII) Precautions: 13. It is necessary to learn n++ & ++n also n-- & --n , and their technical difference. 14. Use of comparison operators like <=,>=. 15.For debug use F8 and execution use Cntrl+F9.

(VIII) Procedure: 16.Write a program as per mentioned above in Dev C++. 17.Ctrl+N for new C++ program. 18.Ctrl+F9 for compile. 19. Ctrl+F10 to Run the program. 20.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 7. Type your observation =……………………………. 8. ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 7. Student must type the result or output of the program=…………………………………….. 8. ____________________________________________________________________________________ ____________________________________________________________________. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(XI) INTERPRETATION OF RESULT: -

(XII) CONCLUSION: -

(XIII) Experiment Related Que.13. Define n++ and n-- expression. 14. Compare ++n&--n. 15. Define Boolean checking. (XIV) Assessment:S.No. 1 2 3 4 5 1 2 3 4 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result Interpretation of Result Dev C++ handling Viva 2 2 2 2 2 Product 2.5 2.5 2.5 2.5 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 05
Title: - To learn FOR loop in C++ . Objective: - The Aim of this lab to teach loop in C++. (I) Practical Significance: - The for statement is most commonly used to step through some integer variable in equal increments. The for statement is often used to step through an array. The for statement is, however, a completely general looping mechanism that can do anything that a while loop can do. For example, the following for statement sums the integers 1 through 10: sum = 0; for (n = 1; n <= 10; n++) sum = sum + n; A for statement begins with the keyword for followed by three things in parentheses that tell the computer what to do with the controlling variable. The beginning of a for statement looks like the following: for (Initialization_Action; Boolean_Expression; Update_Action) The first expression tells how the variable, variables, or other things are initialized; the second gives a Boolean expression that is used to check for when the loop should end;and the last expression tells how the loop control variable is updated after each iteration of the loop body. (II) Competency Skill: - generic & hence should learn FOR loop to control the expression. (III) Experiment Objective: 9. To learn FOR loop in C++. 10. To find its usage in controlled expressions. (IV) Theoretical Background: A for statement often uses a single int variable to control loop iteration and loop ending. However, the three expressions at the start of a for statement may be any C++ expressions; therefore, they may involve more (or even fewer) than one variable, and the variables may be of any type. The three expressions at the start of a for statement are separated by two—and only two— semicolons. Do not succumb to the temptation to place a semicolon after the third expression. (The technical explanation is that these three things are expressions, not statements, and so do not require a semicolon at the end.)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(VI) Resource required: - Dev C++

(VII) Precautions: 16. It is necessary to learn FOR loop , and their technical comparison with while. 17.Use of comparison operators like <=,>=. 18.For debug use F8 and execution use Cntrl+F9. (VIII) Procedure: 21.Write a program as per mentioned above in Dev C++. 22.Ctrl+N for new C++ program. 23.Ctrl+F9 for compile. 24. Ctrl+F10 to Run the program. 25.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 9. Type your observation =……………………………. 10.________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 9. Student must type the result or output of the program=…………………………………….. 10.____________________________________________________________________________________ ____________________________________________________________________.

(XI) INTERPRETATION OF RESULT: Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(XII) CONCLUSION: -

(XIII) Experiment Related Que.16. Define n++ and n-- expression. 17.Compare ++n&--n. 18. Define Boolean checking. (XIV) Assessment:S.No. 1 2 3 4 5 1 2 3 4 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result Interpretation of Result Dev C++ handling Viva 2 2 2 2 2 Product 2.5 2.5 2.5 2.5 Max.Mark Obtained

EXPERIMENT NO. 06
Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
Title: - To learn function creation in C++ . Objective: - The Aim of this lab to teach Do while loop in C++. (I) Practical Significance: - You can define your own functions, either in the same file as the main part of your program or in a separate file so that the functions can be used by several different programs The definition is the same in either case, but for now we will assume that the function definition will be in the same file as the main part of your program. This subsection discusses only functions that return a value. A later subsection tells you how to define void functions. Forthcoming paragraph contains a sample function definition in a complete program that demonstrates a call to the function. (II) Competency Skill: - Student will learn function declaration or function prototype expression. (III) Experiment Objective: 11. To learn function prototype in C++. 12. To find the usage of function definition, function header expressions. (IV) Theoretical Background: A function definition describes how the function computes the value it returns. A function definition consists of a function header followed by a function body. The function header is written similar to the function declaration, except that the header does not have a semicolon at the end. The value returned is determined by the statements in the function body. This subsection discusses only functions that return a value. A later subsection tells you how to define void functions. Display experiment code contains a sample function definition in a complete program that demonstrates a call to the function. The function is called totalCost and takes two arguments—the price for one item and the number of items for a purchase. The function returns the total cost, including sales tax, for that many items at the specified price. The function is called in the same way a predefined function is called. The definition of the function, which the programmer must write, is a bit more complicated. The description of the function is given in two parts. The first part is called the function declaration or function prototype. The following is the function declaration (function prototype) for the function defined in Display experimental code:

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(VI) Resource required: - Dev C++

(VII) Precautions: 19.For debug use F8 and execution use Cntrl+F9. 20.Note that the function body can contain any C++ statements and that the statements will be executed when the function is called. Thus, a function that returns a value may do any other action as well as return a value. In most cases, however, the main purpose of a function that returns a value is to return that value. Either the complete function definition or the function declaration (function prototype) must appear in the code before the function is called. The most typical arrangement is for the function declaration and the main part of the program to appear in one or more files, with the function declaration before the main part of the program, and for the function definition to appear in another file. (VIII) Procedure: 26.Write a program as per mentioned above in Dev C++. 27.Ctrl+N for new C++ program. 28.Ctrl+F9 for compile. 29. Ctrl+F10 to Run the program. 30.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 11.Type your observation =……………………………. 12.________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________.

(X) Result: Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
11.Student must type the result or output of the program=…………………………………….. 12.____________________________________________________________________________________ ____________________________________________________________________.

(XI) INTERPRETATION OF RESULT: -

(XII) CONCLUSION: -

(XIII) Experiment Related Que.19. Define function definition and function body. 20. Function call and function header. 21. Related mathematics. (XIV) Assessment:S.No. 1 2 3 4 5 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership 2 2 2 2 2 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
Product 1 2 3 4 Desired Result Interpretation of Result Dev C++ handling Viva 2.5 2.5 2.5 2.5

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 07
Title: - To learn parameters in C++ . Objective: - The Aim of this lab to teach parameters 1) call-by-value parameters 2) call-by-reference parameters in C++. (I) Practical Significance: - This lab describes the details of the mechanisms used by C++ for plugging in an argument for a formal parameter when a function is invoked. There are two basic kinds of parameters and therefore two basic plugging-in mechanisms in C++. The two basic kinds of parameters are call-byvalue parameters and call-by-reference parameters. With call-by-value parameters, only the value of the argument is plugged in. With call-by-reference parameters, the argument is a variable and the variable itself is plugged in; therefore, the variable’s value can be changed by the function invocation. A call-by-reference parameter is indicated by appending the ampersand sign, &, to the parameter type, as illustrated by the following function declarations: void getInput(double& variableOne, int& variableTwo); A call-by-value parameter is indicated by not using the ampersand. The details on call-by-value and call-by-reference parameters are given in the following subsections. (II) Competency Skill: - Students will learn two types of parameter Call by reference and parameters expression. (III) Experiment Objective: 13. To learn Call by reference in C++. 14. To explore Call by parameters. (IV) Theoretical Background: Call-by-value parameters are more than just blanks that are filled in with the argument values for the function. A call-byvalue parameter is actually a local variable. When the function is invoked, the value of a call-by-value argument is computed and the corresponding call-by-value parameter, which is a local variable, is initialized to this value. In most cases, you can think of a call-by-value parameter as a kind of blank, or placeholder, that is filled in by the value of its corresponding argument in the function invocation. However, in some cases it is handy to use a call-by-value parameter as a local variable and change the value of the parameter within the body of the function definition. Callby-value parameters are local variables just like the variables you declare within the body of a function. However, you should not add a variable declaration for the formal parameters. Listing the formal parameter minutesWorked in the function heading also serves as the variable declaration. The call-by-value mechanism that we used until now is not sufficient for all tasks Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
you might want a function to perform. For example, one common task for a function is to obtain an input value from the user and set the value of an argument variable to this input value. The call-by-value mechanism that we used until now is not sufficient for all tasks you might want a function to perform. For example, one common task for a function is to obtain an input value from the user and set the value of an argument variable to this input value. Call by reference explanation:

(V) C++ Experiment Code: - a) Call by parameters

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
b) Call by Reference Parameters

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(VI) Resource required: - Dev C++

(VII) Precautions: 21. It is necessary to learn variable declaration in with & and without & . 22. Demonstration of two different parameters. 23.For debug use F8 and execution use Cntrl+F9. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(VIII) Procedure: 31.Write a program as per mentioned above in Dev C++. 32.Ctrl+N for new C++ program. 33.Ctrl+F9 for compile. 34. Ctrl+F10 to Run the program. 35.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 13. Type your observation =a)……………………………b) …………………………….c) ……………………………. ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 13. Student must type the result or output of the program(a,b,c)=…………………………………….. 14.____________________________________________________________________________________ ____________________________________________________________________. (XI) INTERPRETATION OF RESULT: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(XII) CONCLUSION: -

(XIII) Experiment Related Que.22. Define parameters. 23. Define its types and explain. 24. Define technical difference between these parameters. (XIV) Assessment:S.No. 1 2 3 4 5 1 2 3 4 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result Interpretation of Result Dev C++ handling Viva 2 2 2 2 2 Product 2.5 2.5 2.5 2.5 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
EXPERIMENT NO. 08
Title: - To learn operator overloading in C++ . Objective: - The Aim of this lab to teach overloading in C++. (I) Practical Significance: - C++ allows you to give two or more different definitions to the same function name, which means you can reuse names that have strong intuitive appeal across a variety of situations. For example, you could have three functions called max: one that computes the largest of two numbers, another that computes the largest of three numbers, and yet another that computes the largest of four numbers. Giving two (or more) function definitions for the same function name is called overloading the function name. (II) Competency Skill: - Student will learn operator overloading. (III) Experiment Objective: 15. To learn operator overloading in C++. This is an example of overloading. In this case we have overloaded the function name ave.

(IV) Theoretical Background: If you have two or more function definitions for the same function name, that is called overloading. When you overload a function name, the function definitions must have different numbers of formal parameters or some formal parameters of different types. When there is a function call, the compiler uses the function definition whose number of formal parameters and types of formal parameters match the arguments in the function call. Whenever you give two or more definitions to the same function name, the various function definitions must have different specifications for their arguments; that is, any two function definitions that have the same function name must use different numbers of formal parameters or have one or more parameters of different types (or both). Notice that when you overload a function name, the declarations for the two different definitions must differ in their formal parameters. You cannot overload a function name by giving two definitions that differ only in the type of the value returned. Code is displayed at experiment objective. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

(VI) Resource required: - Dev C++

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(VII) Precautions: 24.For debug use F8 and execution use Cntrl+F9. 25.If you use overloading to produce two definitions of the same function name with similar (but not identical) parameter lists, then the interaction of overloading and automatic type conversion can be confusing. The rules that the compiler uses for resolving which of multiple overloaded definitions of a function name to apply to a given function call are as follows: 1. Exact match: If the number and types of arguments exactly match a definition (without any automatic type conversion), then that is the definition used. 2. Match using automatic type conversion: If there is no exact match but there is a match using automatic type conversion, then that match is used. If two matches are found at stage 1 or if no matches are found at stage 1 and two matches are found at stage 2, then there is an ambiguous situation and an error message will be issued. For example, the following overloading is dubious style, but is perfectly valid: void f(int n, double m); void f(double n, int m); (VIII) Procedure: 36.Write a program as per mentioned above in Dev C++. 37.Ctrl+N for new C++ program. 38.Ctrl+F9 for compile. 39. Ctrl+F10 to Run the program. 40.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 14.Type your observation =……………………………. 15.________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 15.Student must type the result or output of the program=…………………………………….. 16.____________________________________________________________________________________ ____________________________________________________________________. Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(XI) INTERPRETATION OF RESULT: -

(XII) CONCLUSION: -

(XIII) Experiment Related Que.25. Define operator overloading. 26.Define operator overloading and its types. 27. Related precautions. (XIV) Assessment:S.No. 1 2 3 4 5 1 2 3 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership Desired Result Interpretation of Result Dev C++ handling 2 2 2 2 2 Product 2.5 2.5 2.5 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
4 Viva 2.5

EXPERIMENT NO. 09
Title: - To learn class in C++ Program. Objective: - To display a class using basic operations in C++ . (I) Practical Significance: - A class is basically a structure with member functions as well as member data. Classes are central to the programming methodology known as object-oriented programming. A class is a type that is similar to a structure type, but a class type normally has member functions as well as member variables. An overly simple, but illustrative, example of a class called DayOfYear is given in forthcoming displayed code. This class has one member function named output, as well as the two member variables month and day. The term public: is called an access specifier. It simply means that there are no restrictions on the members that follow. We will discuss public: and its alternatives after going through this simple example. The type DayOfYear defined in following displayed class definition for objects whose values are dates, such as January 1 or July 4. (II) Competency Skill: - Class with public and private member function using experiment code. (III) Experiment Objective: 16. To learn basic class declaration in C++. 17. To explore basic public class . (IV) Theoretical Background: The value of a variable of a class type is called an object (therefore, when speaking loosely, a variable of a class type is also often called an object). An object has both data members and function members. When programming with classes, a program is viewed as a collection of interacting objects. The objects can interact because they are capable of actions, namely, invocations of member functions. Variables of a class type hold objects as values. Variables of a class type are declared in the same way as variables of the predefined types and in the same way as structure variables. For the moment ignore the word public: shown in Display 6.3. The rest of the definition of the class DayOfYear is very much like a structure definition, except that it uses the keyword class instead of struct and it lists the member function output (as well as the member
Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
variables month and day). Notice that the member function output is listed by giving its declaration (prototype). A class definition normally contains only the declaration for its member functions. The definitions for the member functions are usually given elsewhere. In a C++ class definition, you can intermix the ordering of the member variables and member functions in any way you wish, but the style we will follow has a tendency to list the member functions before the member variables. Member variables for an object of a class type are specified using the dot operator in the same way that the dot operator is used to specify member variables of a structure. For example, if today is a variable of the class type DayOfYear defined in following code ,then today.month and today.day are the two member variables of the object today.Member functions for classes that you define are invoked using the dot operator in a way that is similar to how you specify a member variable. For example, the following program declares two objects of type DayOfYear in the following way: DayOfYear today, birthday; The member function output is called with the object today as follows: today.output( ); and the member function output is called with the object birthday as follows: birthday.output( ); When a member function is defined, the definition must include the class name because there may be two or more classes that have member functions with the same name. There is only one class definition, but in other situations you may have many class definitions, and more than one class may have member functions with the same name. The definition for the member function output of the class DayOfYear is shown in part 2 of the program. The definition is similar to an ordinary function definition except that you must specify the class name in the heading of the function definition. The heading of the function definition for the member function output is as follows: void DayOfYear::output( ) The operator :: is called the scope resolution operator and serves a purpose similar to that of the dot operator.

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
(V) C++ Experiment Code: -

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(VI) Resource required: - Dev C++

(VII) Precautions: 26.Use semi-colon after declaring member functions. 27.Member objective is another important topic. 28.For debug use F8 and execution use Cntrl+F9. (VIII) Procedure: 41.Write a program as per mentioned above in Dev C++. 42.Ctrl+N for new C++ program. 43.Ctrl+F9 for compile. 44. Ctrl+F10 to Run the program. 45.Following is the main menu of Dev C++.

(IX) Observation or Calculations: 16.Type your observation =……………………………. 17.________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________. (X) Result: 17.Student must type the result or output of the program=…………………………………….. 18.____________________________________________________________________________________ ____________________________________________________________________. (XI) INTERPRETATION OF RESULT: Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)

(XII) CONCLUSION: -

(XIII) Experiment Related Que.28.Define main() , return 0 , cin>> , cout<< , loop. 29.Define variables. 30.Define preprocessor directives, and their significance. 31.Display your name in C++ with your facebook ID. (XIV) Assessment:S.No. 1 2 3 4 5 Experiment Process Sample code Algorithm Flow chart Syntax Team Leadership 2 2 2 2 2 Max.Mark Obtained

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Institute of Business & Technology (Object Oriented Programming)
Product 1 2 3 4 Desired Result Interpretation of Result Dev C++ handling Viva 2.5 2.5 2.5 2.5

Developed by:Adnan Alam
Khan([email protected])

Department of Computer Science & Information Technology

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close