Object Oriented Programming
Object Oriented Programming
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++ . Its 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(Write2adnanalamkhan@gmail.com)
(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: -
(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(Write2adnanalamkhan@gmail.com)
Max.Mark
Obtained
(XV)Desired Output:-
(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(Write2adnanalamkhan@gmail.com)
(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: -
(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
(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.
(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: -
(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
(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(Write2adnanalamkhan@gmail.com)
(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
(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.____________________________________________________________________________________ ____________________________________________________________________.
(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(Write2adnanalamkhan@gmail.com)
(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.________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ________________________________________________________________________________ ___________________________________________________________________.
(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
(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(Write2adnanalamkhan@gmail.com)
(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: -
(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
(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(Write2adnanalamkhan@gmail.com)
(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(Write2adnanalamkhan@gmail.com)
(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
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(Write2adnanalamkhan@gmail.com)
(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(Write2adnanalamkhan@gmail.com)
(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