MC 0500 Object Oriented Programming using C++ INDEX. S.No. Contents Date of Completion. 3. Operator Overloading and type conversion

Size: px
Start display at page:

Download "MC 0500 Object Oriented Programming using C++ INDEX. S.No. Contents Date of Completion. 3. Operator Overloading and type conversion"

Transcription

1 MC 0500 Object Oriented Programming using C++ INDEX S.No. Contents Date of Completion 1. Simple Programs 2. Classes and Objects 3. Operator Overloading and type conversion 4. Inheritance 5. File I/O Staff Signature Page 1

2 Purpose: Syllabus MC 0500 Object oriented programming using C++ The course is designed to impart knowledge on the object oriented concepts and implementation using C++ with examples and applications. Instructional Objectives: At the end of the course, the student should able to: Get an idea of Class and objects Overload several operators, functions and constructors Inherit the properties from the base class Handle files Principles of Object oriented programming An overview of C++ - Data Types, Control structures Functions Classes and Objects Constructors and Destructors Arrays, Pointers, References, and Dynamic Allocation Operator overloading Type Conversion Inheritance Virtual functions and Polymorphism C++ I/O system basics and File I/O Text Book: 1. Herbert Schildet C++ The complete Reference Tata McGraw Hill Third Edition 2001 (Chapters 2,3,6,11 to 17, 20,21) Reference Books: 1. Rob McGregor Using C++ - Prentice Hall India Al Stevens C++ Programming Wiley Dreamtech India (P) Ltd. 7 th edition Page 2

3 Session 1: Principles of Object Oriented Programming 1. Define Software Development Process Software development is the process, which transforms the users needs and expectation to a software solution. It has a series of predictable steps such as analysis, design, implementation, testing and refinement. Figure 1.1 shows the major transformations of software development process in sequence. Transformation 1 Transformation 2 Transformation 3 User Needs & Expectations Problem Statement Detailed Design Software Product Figure 1.1 Software Development Process Transformations Transformation 1 (Analysis): In this phase, the users needs and expectations are gathered and transformed in the form of problem statement. Requirements of product development, responsibilities of development team and customers also will be analyzed and documented. Transformation 2 (Design): For each functional requirements identified in the problem statement, data storage, input and output forms are designed. This phase gives the details of how to build the system. The format and descriptions of each forms (input /output), development constraints and test cases of design are documented. Transformation 3 (Implementation): It refines the detailed design and deploys the software product to the expectations of customers. Test cases are applied to the developed software to ensure bug free product. User Manuals and Test reports are documented. [Fritz Bauer]: Software engineering is the establishment and use of sound engineering principles, methods, tools that can be used to produce high quality software that is reliable and works efficiently on real machine 2. Describe Structured Methodology. List the problems faced by it. A method is a planned procedure by which a specific goal is approached step by step. A software methodology is a science of method, which is a series of processes that can lead to the development of an application. The structured methodology of software engineering views the software program is the concatenation of algorithms and data structures as shown in Figure 1.2. Structured methods use a procedural approach to software design, that is, the structure of the software is based on top-down functional decomposition. The structured methodology is otherwise called as functional or procedural methodology. = + Software Algorithms Data Structures Figure 1.2 Software viewed in Structured Methodology Page 3

4 In structured approach, system is partitioned into its main areas or activities. Each of these areas may be viewed as a subsystem. Data is passed freely between the sub systems. The focus is primarily on function and less importance is given to data. Some of the characteristics of structured methodology are: More emphasis is given to algorithms. Program is decomposed in terms of functions. Data declared in global area are visible and shared by all functions. Those data moves freely around the system from function to function. Figure 1.3 depicts the global data sharing in structured methodology. Apply top-down approach in program design (Problem statement is analyzed for functional requirements rather than user interactive design perspective). Global Data Function 1 (Local Data) Function 2 (Local Data) Function 3 (Local Data) Figure 1.3 Global Data sharing in Structured Methodology Software systems developed using structured methodologies have shown significant improvements. It was applied to complete and correct the requirement phase in terms of identifying functional requirement. Common algorithms were derived for recurring phenomena. Software maintenance was made easy with proper documentation and configuration management. However, as the problems tackled by software developers have become progressively larger and more complex, it has become apparent that structured methods are not a complete answer. The limitations of structured methodology are: Some of the quality attributes such as extensibility, portability, reusability and user Interactions are not focused. Rapid growth of Internet has influenced a new trend in business and has brought ergonomic expectations to the customer. Component based construction and the improved quality process models insisting the optimized reusable engineering standards. Evolution of globalization and geographically distributed software development team has brought new challenges in maintaining common repository, shared and virtual work environment. 3. Describe Object Oriented Methodology. Over the last two decades, the function/procedure oriented structured methodology in software engineering being supplanted by a more sophisticated, flexible, reusable object oriented approach. This approach address rising demands in highly sophisticated software, technical Page 4

5 complexity and continuous evolution. It allows to create systems that are easy to develop, maintain and also easy to extend and reuse. Using Object orientation, it is possible to model systems in terms that match human thinking. One of the most important features of object orientation is that the whole development process is based around a single, central concept that of object (Figure 1.4). Object orientation promises a new approach to system development, which will produce software that is more maintainable, testable, reusable and able to cope with large complex systems. It treats data as a critical element in the program development and does not allow it to flow freely around the system. Some of the characteristics of object-oriented approach are: Data is more emphasized. Data and functions that operate on data are bind together as object. Real world things are directly mapped into objects in the model, which minimizes the semantic gap. Data structures are designed to characterize the objects. Data is hidden and cannot be accessed by external functions. Follows bottom-up goal driven approach (Requirements are analyzed in terms of users who use and affect the system). Seamless transition of software development is achieved by using same Meta language for various phases. Communication of objects is achieved only through proper interfaces. Object Object Object Object Figure 1.4 An object Application OO development requires working with more users, offers benefits throughout the entire development life cycle. It insists a new mindset on the part of developers. Object orientation is appropriate: To develop complex systems Systems that are prone to change System with User Interfaces Systems that are based on client/server model To build E-commerce/web based applications For Enterprise Application Integration (EAI) Page 5

6 4. Describe Object Oriented Concepts Object orientation has its own specialized vocabulary, which must be mastered if the technology is to be understood. The principle terms are introduced in the Table 1.1. The underlying concepts are explained in detail. Term Object Class Attribute Method Message State Encapsulation Data Abstraction Data hiding Inheritance Polymorphism Overloading Strong and weak typing Overriding Table 1.1 Principle terms of Object Oriented Technology Definition A person, place, thing, concept, event, screen, or report. Object is a software unit packaging together data and methods to manipulate the data. Defines the general structure of the similar kind of objects. Objects that share the same operations / method and common characteristics are grouped into a class. So it is template for creating objects. Data item defined as part of a class or object. Procedure or function defined as part of a class; refers the implementation. An instruction to invoke some action on object. It is a request sent to an object to execute one of its methods. Represents a period of time during which the object satisfies some condition. Packaging data and operations into an object. Allows essential operations and data to be public without including their background details. Making the encapsulated data of an object inaccessible and invisible to other objects. Mechanism for defining a new class in terms of an existing class. Capability of a method to be applied to objects of different types; Ability to hide different implementations behind a common interface. kind of polymorphism (compile time), which allows two, or more methods use the same name with different parameter list. In strong typing, exact data type of arguments must be defined in the program itself. Weak typing permits to mention the data type of arguments at run time. Kind of polymorphism (run time), capability of sub class to override the characteristics of the super class. It occurs when a sub and super class methods use the same name with identical signatures, such that subclass hides the super class method. (i) Object Object is a software unit packaging together data and methods to manipulate the data Consider one of the objects identified - that is Santro Car # It is characterized by the data items such as name, number, brand, color, owner, price, mileage, fuel capacity and speed. Operations performed on the car are start, drive, stop, service the car, and fill the fuel etc., Figure 1.4 shows how the car would be represented as a software object, which is made up of the data and operations. Page 6

7 (ii) Class Objects that are defined by the same set of attributes and methods are grouped into a class. Once the general structure is defined in terms of class, then any number of objects can be created from it. So object is defined as an instance of particular class. A class can be thought of higher-level user defined data type. The class for the car object is shown in Figure 1.5. Diagrammatically, classes are represented as rectangle with three compartments: one for the name of the class, one for the class attributes and one for the operations. Figure 1.6 shows the objects created for the defined class. Note that the third compartment that defines the method is omitted in object. Since the methods are same and not vary for each object, it is defined only in class and implemented through class definition when objects invoke. So, it minimizes the memory space. Page 7

8 (iii) Message Message is an instruction to invoke some action on object. It is a request sent to an object to execute one of its methods. Objects interact with each other in a system. The overall functionality is achieved by those interactive messages. A message will cause the receiving object to respond (behavior) by implementing the desired mechanism (method). Example: If Abdul wants Roshna to stop the car, he must send a message telling to stop the car (Figure 1.7). Roshna, Stop the Car Figure 1.7 Example of Message (iv) State of the Object A state is the value that an object has during a particular time interval or between the occurrences of two successive events. Objects can have more than one state. For example the identified Car object can be in a stand still position or moving state. Object changes from one state to another state by performing some operations, which in turn causes change of values in one or more attributes. In simple, state change of object occurs when object responds for the message received. (v) Static and Dynamic Attributes Objects are defined with the combination of static and dynamic attributes. The values of static attributes remain same in state change. But the values of dynamic attributes vary during the state change. Static and dynamic attributes of the Car object are shown in Figure 1.8. (vi) Different kinds of methods Methods are procedures, which implement the required behavior of a class. Methods are defined, as part of class and it cannot exist separately. All the objects in a class have the same set of methods, which are defined in a class. It is not instantiated for each object as like attributes. When the methods are public, they are termed as Operations. Operations can be made visible for other objects in the system. User can typically perform five kinds of operations upon an object: Page 8

9 Modifier: An operation that modifies the state of an object. Selector: An operation that accesses the state of an object, but does not modify the state. Iterator: An operation that permits all parts of an object to be accessed in some welldefined order. Constructor: An operation that creates an object and initializes its properties and state. Destructor: An operation that frees the state of an object and destroys the object itself. (vii) Inheritance Inheritance allows a class to inherit the attributes and methods of another. It promotes code reusability. The class, which transmits its property (attributes and methods), is called as super class (or) base class (or) parent class. The class, which derives property from another class, is called as sub class (or) derived class (or) child class. Simple Example of Inheritance is given in Figure 1.9. The different types of inheritance are listed in Table 1.2 as shown in Figure BankClient Regular NRI Figure 1.9. Example for Inheritance Figure 1.9 Types of Inheritance Page 9

10 Inheritance Type Single Inheritance Multiple Inheritance Hierarchical Inheritance Multilevel Inheritance Hybrid Inheritance Table 1.2 Types of Inheritance Definition It represents a sub class with only one super class It represents a sub class with more than one super class It represents a super class with more than one sub class. It represents a sub class (sub sub class) derived from another sub class It represents the combination of multiple and multilevel inheritance (viii) Polymorphism Polymorphism allows a single name to be used for more than and provides name reusability. Overloading is a kind of polymorphism, which allows two, or more methods use the same name with different parameter list. Note the sum() function applied in spreadsheet applications given in Figure Figure Example of Polymorphism Dynamic binding refers to the linking of a procedure call to the code to be executed in response to the call / at run time. This is also called as run time polymorphism. Polymorphism is classified as shown in Figure Figure 1.11 Types of polymorphism Page 10

11 5. Benefits of OOP OOP offers several benefits to both the program designer and user. The principle advantages are: Eliminate code redundancy through inheritance. Reusability of code and modules lead to saving of development time and higher productivity. Data hiding ensures security. Multiple instances of an object to co-exist without any interference. The data-centered design approach enables to capture more details of implementation. Both small and larger systems can be developed with ease. Easy to manage complexity. Easy to achieve interoperability through message passing. 6. Object oriented languages The languages should support several of the OOP concepts to claim that they are object-oriented. Depending upon the features they support, they can be classified into the following two categories with their OO concepts. Object based Programming Languages Data Encapsulation Data Hiding and access mechanisms Automatic initialization and clean-up of objects Operator overloading Object oriented Programming Languages Object based + Inheritance + Dynamic binding Some of the OOP languages are: C++, Ada, Java, SmallTalk 7. Describe Object Oriented Software Development Life Cycle OO system development is based on the principal stages of the traditional system life cycle. The three macro processes of object oriented system development life cycle are Object oriented Analysis (OOA), Object Oriented Design (OOD) and Object Oriented Programming (OOP). The development is viewed as a single, seamless process, with smoother transactions between different stages. Rapid prototyping may be used to develop a small part of the system, which is then validated by users and continuously improved in an iterative and incremental development life cycle. Use Case driven OOSDLC approach, given by Jacboson is shown in Figure A Use Case is defined as the activities initiated by actor. An actor is who affects or make use of the system. The concept of use will be dealt more in the rest of the chapters. Transformation 1 (OOA): Examines the requirements (Use Cases) from the perspective of actors and identify classes and objects. It develops an OO model of the application domain. This phase is independent of an implementation technique (OOP) that might be applied later. Page 11

12 Transformation 2 (OOD): Refine class and object diagram with relationship among them, design user interface screen, business transactions and database design. It develops an OO model of the software system. This phase is no longer carried out independently of the later implementation. Transformation 3 (OOP): Implement the detailed design as software product in Object oriented programming language and do a necessary quality assurance, user satisfaction, usability testing. It realizes the software design with OOP language that supports direct implementations of objects, classes, inheritance and etc., since the design and implementation phases become more closely associated; the duration of the implementation is reduced. Figure OO Programming Development Life Cycle Assignment: 1. Apply Object Oriented Concepts for Student Information System 2. Apply Object Oriented Concepts for Library Information System Self-Check Exercises: 1. In Structured methodology, software is made up of and. 2. Can method be instantiated for each object (Yes / No) 3. The values of attributes vary during the state change of the object. 4. Packaging data and operations into object is called as. 5. An operation that creates an object and initializes its properties and state is Staff Signature Page 12

13 Session 2: C++ Fundamentals Checklist Sl.No. Exercise / Program Date of Completion 1. First program in C++ 2. Using Input and Output streams 3. Program using input of more than one item and endl 4. Implement enumerated data type 5. Give valid and invalid examples for constants 6. C and C++ program using char constant 7. Dynamic initialization of variables 8. Reference variable 9. Scope resolution operator 10. Memory management operators new and delete 11. Use of manipulators 12. Suitable example for various operators 13. Type cast operator 14. Access one and two dimensional array 15. Simple if statement 16. If else statement 17. Nested if statement 18. Logical operators 19. while statement 20. do..while statement 21. for loop statement 22. Nested for loop statement 23. switch case statement 24. bool data type 25. break and continue statement 26. goto statement Staff Signature: Page 13

14 6. Simple Program in C++ //Program 1- First program in C++ using namespace std; int main () { cout << "Hello World!"; return 0; Explanation: // my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. We cannot insert a comment within the text program line. #include <iostream.h> Lines beginning with a pound sign (#) are directives for the preprocessor. In this case the directive #include <iostream.h> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard inputoutput library in C++, and it is included because its functionality is going to be used later in the program. cout << "Hello World!"; This line is a C++ statement. cout represents the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello World sequence of characters) into the standard output stream (which usually is the screen). cout is declared in the iostream standard file. using namespace std; Namespace is a new concept introduced by the ANSI C++ standards committee. Here, std is the namespace where ANSI C++ standard class libraries are defined. All ANSI C++ programs must include this directive. This will bring all the identifiers defined in std to be the current global scope. using and namespace are new keywords of C++. Page 14

15 7. Programs using Input and Output streams The standard input device is usually the keyboard. Handling the standard input in C++ is done by applying the overloaded operator of extraction (>>) on the cin stream. The operator must be followed by the variable that will store the data that is going to be extracted from the stream. // Program 2 using input output stream #include <iostream.h> int main () { int i; cout << "Please enter an integer value: "; cin >> i; cout << "The value you entered is " << i; return 0; Input of more than one item can also be performed using cin input stream object. Such input operations are called cascaded input operations. endl indicates end of line termination. After //, the entire line is considered as comment. // Program 3 - program using input of more than one item and endl #include <iostream.h> int main () { int i,j; cout << "Please enter two integer values: "; cin >> i>>j; // input of more than one item cout<<"the values you entered are " << i<< <<j<<endl; return 0; Page 15

16 8. C++ Character set The characters in C++ are grouped into the following categories: Letters: Upper case A Z, Lowercase a Z Digits: 0 9 Special characters:,. : ;?! ~ \ / < > # $ % ^ & * ( ) { [ ] + - _ = White spaces: Blank space, Horizontal tab, Carriage return, New line, Formfeed 9. Tokens in C++ In C++ program the smallest individual units are known as C++ tokens. They are: Identifiers, Keywords, Constants, Strings, Special Symbols and Operators. Tokens Meaning Example: Identifiers assigns names to files, functions, variables etc., Valid Identifiers: name, street, mark1, test1, product123, emp_name Invalid Identifiers: 1Prg, 2.4, A.B, A$B Keywords Reserved words that have standard, predefined meanings in C++ asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while, and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq Valid Identifier Rule: Only alphabetic characters, digits and underscores are permitted. The name cannot start with a digit Uppercase and lowercase letters are case sensitive A declared keyword cannot be used as a variable name There is no limit on length of the name in ANSI C Data Types in C++ (A) Data types in C++ can be classified under various categories (i) (ii) (iii) Built-in type *Integral type (int, char) *Void *Floating type (float, double) Derived data type *array * function * pointer * reference User-defined type *structure * union * class * enumeration Page 16

17 (B) Qualifiers / Modifiers: The four basic data types in C++ (int, char, float, double) are further qualified with the qualifiers such as signed, unsigned, long, short Example: signed int, unsigned long int (C) Use of void: void implies no value. Two normal uses of void are: (i) When it is prefixed to any function, it implies that the function does not return any value. void sum(void); // no return type and empty parameter list (ii) void is used for generic pointers void *gp; int * ip; gp = ip; // gp becomes generic pointer // int pointer // assign int pointer to void pointer Note: *ip = *gp // illegal statement (C) wchar_t A void pointer to be assigned to other type only with type casting ip = (int *) gp // permitted The wchar_t type is a wide character literal introduced by ANSCI C++ and is intended for character sets that cannot fit into a single byte. Wide-character literals begin with the letter L. (D) type def typedef: It takes the general form: typedef type identifer; where type refers to an existing data type and identifier refers to the new name given to the data type. Example: typedef unsigned int units; They can be later used to declare variables as follows: units u1,u2; where u1 and u2 are declared as unsigned integers indirectly. Page 17

18 (E) enumerated data types An enumerated data type is a kind of user defined data type, which provides a way for attaching names to numbers, thereby increasing comprehensibility of the code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2 and so on. Example enum day {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday enum day week_day; week_day=monday; Write a C++ program to define enum data type and find whether the following statements are valid. day week_day = 7; day week_day = (day) 4; int day_of_birth = Friday; // Program 4 Implement enumerated data type Page 18

19 11. Constants / Literals in C++ Constants are fixed values that do not change during the execution of a program. Recollect from C programming. Give valid and invalid examples for each constant types. Constants Valid Example Invalid Example Decimal integer Octal integer Hexadecimal integer Unsigned integer Long integer Unsigned long integer Floating point number Exponential form Long double Single character String 12. Symbolic constants There are two ways of creating symbolic constants in C++ (a) Using the qualifier constant: The value declared as const cannot be modified by the program. const int i = 10; int a[i]; i = 45; // illegal statement (b) Volatile The modifier volatile tells the compiler that a variable value may be changed in ways not explicitly specified by the program. In few cases, it may be changed through OS routine. The declaration of such variables are: const volatile char *port = (const volatile char *) 0X30; (c) Defining a set of integer constants using enum keyword Page 19

20 13. Char constant in C++ In C, the char constants are stored as int. Therefore sizeof( X ) is equivalent to sizeof(int). In C++, the char is not promoted to the size of int and therefore sizeof( X ) is equivalent to sizeof(char). Write both C and C++ program to ensure the validity of above statement C Program C++ Program // Program 5a char constant in C // Program 5b - char constant in C Dynamic initialization of variables In C, a variable must be initialized using a constant expression and to be declared before any execution statements in the main() function. In C++ however, permits initialization of the variables at run time. This is called dynamic initialization. // Program 6 Dynamic initialization of variable #include <iostream.h> int main () { int i,j; cout << "Please enter two integer values: "; cin >> i>>j; int k = i + j; //dynamic initialization at run time cout<<"the values you entered are " << i<< <<j<<endl; cout<< The value of k <<k; return 0; Page 20

21 15. Reference variable C++ introduces a new kind of variable known as reference variable. A reference variable provides alternate name to the previously defined variable. A reference variable must be initialized at the time of declaration. This establishes the correspondence between the reference and the data object which it names. It is important to note that the initialization of a reference variable is completely different from assignment to it. C++ assigns additional meaning to the symbol &. It is not an address operator. // Program 7 Impact of Reference Variable #include <iostream.h> int main () { int rv1 = 100; int & rv2 = rv1; // rv2 refers rv1 cout << Value of rv1 = <<rv1<< rv1 +=200; cout << Value of rv1 = <<rv1<< rv2 = 5; cout << Value of rv1 = <<rv1<< return 0; value of rv2 = <<rv2<<endl; value of rv2 = <<rv2<<endl; value of rv2 = <<rv2<<endl; 16. New operators in C++ C++ has rich set of operators. All C operators are valid in C++ also. Other new operator are listed. Operator Meaning :: Scope resolution operator ::* Pointer-to-member declaratory * Pointer-to-member operator.* Pointer-to-member operator delete Memory release operator endl Line feed operator new Memory allocation operator setw Field width operator Page 21

22 17. Scope resolution operator in C++ When the same variable name is declared in both global and inside block, C program does not allow the global version of a variable to be accessed from within the inner block. C++ resolves this problem by introducing a new operator :: called the scope resolution operator. // Program 8 Impact of Scope resolution operator #include <iostream.h> Int a=5; // scope global int main () { int a = 45; // scope to main block cout << variable a value in mainr block = <<a<<endl; cout<< variable a value of global in inner block with :: operator = << ::a <<endl; ; return 0; 18. Memory management operators C programming makes use malloc(), calloc() functions to allocate memory dynamically at run time. Similarly, it uses the function free() to free dynamically allocated memory. Although C++ supports these functions, it also defines two unary operators new and delete that perform the task of allocating and freeing the memory in a better and easier way. The new operator can be used to create objects of any type. When sufficient memory is not available for allocation, new returns a null pointer. The advantages of new operator over malloc(): It automatically computes the size of the data object. We need not use the sizeof operator It automatically returns the correct pointer type, so that there is no need to use a type cast. It is possible to initialize the object while creating the memory space. Like any other operator, new and delete can be overloaded. Page 22

23 // Program 9 Use of new and delete operators #include <iostream.h> int main () { // Simple example for new operator int *p = new int; q = new int; // note both p and q are pointer variables *p = 25; *q = 45; int *r = new int(34); // initializes value 34 to the pointer variable r cout<< Printing the values of pointer variables declared through new operator <<endl; cout<< *p = <<*p<< *q = <<*q<< *r= <<*r<<endl; // delete the variables using delete operator delete p; cout<< Try to print after delete <<endl; cout<< *p = <<*p<<endl; // Array initialization using new int *a = new int[3]; a = {1,2,3; cout << The value of a[1] << a[1]<<endl; // To remove array delete []a; return 0; Note: In standard C++, it is possible to have new return null values instead of throwing an exception, when an allocation error occurs. Therefore to avoid such a problem nothrow exception can be added as follows. # include <new> // in header p = new(nothrow) int; Page 23

24 19. Manipulators Manipulators are operators that are used to format the data display. The most commonly used manipulators are endl and setw. Manipulato functions require iomanip.h header file. The endl manipulator, when used in an output statement, causes a linefeed to be inserted. It has the same effect as using the new line character \n. The setw manipulator specifies a field width for printing the value of the variable with right justified. // Program 10 Use of Manipulators #include <iostream.h> # include<iomanip.h> int main () { float a = 1500, b=200, c=45; cout<<setw(6)<< a= <<setw(3)<<a<<endl; cout<<setw(6)<< b= <<setw(3)<<b<<endl; cout<<setw(6)<< c= <<setw(3)<<c<<endl; return 0; Page 24

25 20. Operators and Expressions An operator is a symbol that is used for mathematical or logical manipulations. Operators can be classified into a) Arithmetic b) Relational c) Logical d) Assignment. Recollect from C programming. Give simple expression with suitable example. Operators type Operators Example Result Binary Arithmetic + - * / % Unary arithmetic Relational == < <= > >=!= Logical Compound assignment Chained or multiple assignment Embedded assignment Conditional or ternary operator Bitwise operator Comma operator sizeof &&!? : & << >> ~ ^ Page 25

26 21. Type conversion (a) Mixed mode with automatic/ implicit type conversion: short (or) char int unsigned long int unsigned long int float double long double (b) Explicit type conversion C++ permits explicit type conversion of variables and expressions using the type cast operator. // Program 11 Type cast operator #include <iostream.h> int main () { float average1, average2, average3; int sum=5045, i=5; average1 = sum/i; average2 = sum / (float) i; average3 = sum / float (i); // without type casting // C notation // C++ notation cout<< average without typecasting = <<average1<<endl; cout<< average with typecasting in C= <<average2<<endl; cout<< average with typecasting in C++= <<average2<<endl; return 0; A type-name behaves as if it is a function for converting values to a designated type. The function-call notation usually leads to simplest expressions. However, it can be used only if type is an identifier. For example, p = int * (q); // illegal p = (int *) q; // valid Page 26

27 22. Operator precedence Operator Description Associativity :: Scope resolution. () [] Memory referencing Function call / parenthesis Array element reference Left to right ! ~ * & (type) sizeof new delete.* * / % + - << >> < <= > >= Unary plus Unary minus Increment Decrement Logical negation Ones complement Pointer reference (indirection) Address Type cast (conversion) Size of an object Memory allocation and deallocation Member dereference Multiplication Division Modulus Addition Subtraction Left shift Right shift Less than Less than or equal to Greater than Greater than or equal to Equal to Right to left Left to right Left to right Left to right Left to right Left to right == Left to right!= Not equal to & Bitwise AND Left to right ^ Bitwise XOR Left to right Bitwise OR Left to right && Logical AND Left to right Logical OR Left to right?: Conditional operator Right to left = *= /= %= += -= &= ^= = <<= >>= Assignment operators Right to left Throw Exception Right to left, Comma operator Left to right Page 27

28 23. Arrays An array is a group of data items of the same type that share a common name and differentiated from one another by their positions within the array. The position of each of these numbers is indicated by subscripts, which are integers and enclosed in square brackets. Such variables are called subscripted variables. Arrays can be one, two, three and even multidimensional. A one dimensional array of say 10 integers by name x is declared as int x[10]; The above declaration reserves 10 locations in the memory with names x[0], x[1], x[2] x[9] placed continuously. The first elements always start from the subscript 0. The data type can be any of the predefined or even user defined data types. In a two dimensional array, the data items are visualized to be arranged in a matrix form. A two dimensional array of integers by name a with 5 rows and 6 columns is declared as int a[5][6]; This declaration will reserve 30 locations in the main memory continuously with names a[0][0].a[0][5], a[1][0] a[1][5],.a[4][0]..a[4][5]. The first subscript refers to the row and the second subscript refers to the column. A one dimensional array can be initialized by putting the values inside the curly brackets. For example an integer array of 5 elements can be initialized as int y[5] = { 10,5,5,6,25 A two dimensional array is initialized as int b[2][3] = {{20,40,12,{12,56,23 It must be noted that arrays can be initialized only at the time of declarations and cannot be initialized within the body of the program. For example, you declare an array int z[4]; Then in the body of the program you cannot assign values to the z array as Z[4] = {4,6,1,30; /* WRONG initialization */ Page 28

29 Write a simple C++ program to access one and two dimensional array with the designed output. // Program 12 To access one and two dimensional array Page 29

30 24. Control statements Real life application programs do not merely consist of simple multiplication or addition. They are written for solving complex problems. Depending on the occurrence of a particular situation, the program follows different paths of execution. The control statements available in C++ are: Branching statements Simple If statement If-Else statement Switch statement Jump statements (goto, break, continue, return, exit) Looping statements While statement Do-while statement For statement a) Simple if statement The if statement allows decision to be made by evaluating a given expression is true or false. The general form is as follows: if (expression) statement 1; expression True Statement 1 statement 2; False Statement 2 The if statement first evaluates the expression. If the result is true (a non-zero value), then the body of C++ statement 1 that immediately follow the if is executed, followed by statement 2. If the result is false (zero value) the statement 2 is executed. When several statements are to be executed, they are grouped into a block within curly brackets {. Write a simple C++ program using simple if statement // Program 13 Simple If statement Page 30

31 b) If-else statement The general form is as follows: if (expression) statement 1; else statement 2; Statement 2 False expression True Statement 1 statement 3; Statement 3 The if statement first evaluates the expression. If the result is true (a non-zero value), then the body of C statement 1 that immediately follow the if is executed, followed by statement 3. If the result is false (zero value) the statement 2 is executed, followed by statement 3. Write a simple C++ program using else if statement // Program 14 else if statement Page 31

32 c) Nested if statement The statement following if or else can be another if-else series of statements. Since the else clause is optional, the number of if and the else statements need not be equal. An else statement is paired with the most recent if statement which lacks an else. if (expression1) if (expression2) else statement 1; else statement 2; statement 3; Write a simple C++ program using nested if statement // Program 15 Nested If statement Page 32

33 d) Use of logical operators in if statement Expressions in the if condition can be compound by using one or more logical operators. Write a simple C++ program using logical operators and nested if condition // Program 16 logical operators Page 33

34 e) while statement The while statement is a loop statement that allow its body of its instruction to be executed as long as the expression returns non-zero value. Prior to each execution of the loop body, expression will be checked. If the loop body contains only one statement the curly bracket is not required. The general form is while (expression) { /* looping statements; */ Write a simple C++ program using while loop // Program 17 while loop Page 34

35 f) do..while statement The do..while statement is a loop statement that allows its body of instructions in a do..while loop always execute atleast once. The expressions are checked only after executing the loop body. The loop body continues to be executed repeatedly as long as the expression is non-zero. The general form is: do { /* looping statements; */ while (expression); Note: the semicolon is used at the end of while(expression) to terminate the do while statement. Write a simple C++ program using do while statement // Program 18 do while statement Page 35

36 g) for loop statement The for statement is a loop statement that provides an initialization part, an expression evaluation for terminating the loop and apart to prepare for the next iteration of the loop. The general form is for( initial counter; test counter; increment counter) { /* looping statements */ Example: To evaluate sum =0; for(i=1;i<=10;i++) { sum += i; Cout<< sum of the series = <<sum<<endl; Options in for loop: (i) increment done within the body of the loop: for(i=1;i<=10;) { sum += i; i++; (ii) initialization is done before the for loop: i=1; for(;i<=10;i++) { sum += i; (iii)neither the initialization, nor the increment is done in the for statement, but still the two semicolons are necessary: i=1; for(;i<=10;) { sum += i; i++; (iv) Both comparison and increment done in same statement (v) comma operator for(i=1;i++<=10;) { sum += i; Comma operator is used to have two different expressions in the situations. Notice the multiple initializations & multiple statement in the third part (increment or decrement) of for loop. Page 36

37 for(i=1, j = 10;i<=10;i++,j--) { cout<<i<< X <<j<< = <<i*j<<endl; (vi) All the three expressions omitted in for loop for(;;) (vii) Dynamic initialization of loop variable for(int i=0; i=10; i++) { cout<<i; The loop will never terminate because the conditional statement is absent. It is assumed that the condition is true always and the loop executes infinitely. Such a statement should not be used. Write a simple C++ program using for loop // Program 19 for loop statement Page 37

38 h) Nested for The for loops can be nested. It is essential that one loop completely embedded within the other there can be no overlap. Also each loop must be controlled by a different index. The inner and outer loop need not be generated by the same type of control structure. Write a simple C++ program using Nested for // Program 20 Nested for Page 38

39 i) Switch case statement The switch statement is used to check a single variable against multiple discrete values. The general form of switch statement is: switch(expression) { case value1: statement1; break; case value2: case valuen: default: statement2: break; statementn; break; statementn1; The switch statement evaluates the expression that follows it and then transfers control to the statement following the case statement whose value equals the result of the switch expression, if no match is found and a default statement is present in the statement body, the control transfers to the statement following the default statement. If no match is found and there is no default statement, then the control transfers to the next statement following the switch statement body. Suppose the control finds a match with case value2, after executing the statements in the case value2, the control will go to the next case body unless there is a transfer of control. So it is necessary to put a break statement at the end of every case body to prevent this running on. The break statement will take the control out of the switch body. Write a simple C++ program using switch case // Program 21 switch case Page 39

40 j) Using bool data type C++ defines a buil-in Boolean type called bool. Objects of type bool can store only the values true or false. For automatic type conversions, bool values to be converted into integers true is converted to 1 and false is converted to 0. Also, any non-zero value is converted to true and zero is converted to false. // Program 22 bool data type # include<iostream.h> { int i; bool x; x=false; i = x; cout<< i value <<i<<endl; cout<< x value <<x<<endl; Page 40

41 k) Impact of break and continue The break statement causes an immediate termination from the do, for, swtich, or while statement in which it appears. It is used to jumping out of a loop. The program continues executing the next statement following the do, for, switch or while statement. When the loops are nested, the break would only exit from the loop containing it. That is, the break will exit only a single loop. The continue statement is used to bypass the remainder of the current pass through a loop. The loop does not terminate when a continue statement is encountered. Rather, the remaining loop statements skipped and the computation proceeds directly to the next pass through the loop. The continue statement can be included within a while, a do.. while or a for statement. Write a simple C++ program using break and continue // Program 23 break and continue Page 41

42 l) goto statement The goto statement is used to transfer control to some other statement or statement block within a function. It is called as unconditional control statement / jumping statement and usage of goto in a program is not entertained. It is not a good programming practice to use goto statement in the program. The label name is programmer coined. The general form is goto label;. label: statement; Write a simple C++ program using goto statement // Program 24 goto statement Page 42

43 25. Compare looping statements Do while While For 1. Loop will be executed atleast once do { statement; while(expression); 1. Loop will be executed only if the expression evaluates nonzero value while (expression) { statement; 1. Loop will be executed only if the expression evaluates non-zero value for(initial counter; test counter; increment counter) { statement; Initialisation of the index variable is done before the looping statement Increment the index value is done inside the looping Testing the expression is done at the end of the loop Testing the expression is done at the beginning of the loop Initailisation, increment and testing the expression is done in a single line 26. return and exit() function return(): The return statement is used to return from a function. It is categorized as a jump statement. A return may or may not have a value associated with it. If return has a value associated with it, that value becomes the return value of the function. A non-void function in C++ must return a value. A function declared as void may not contain a return statement that specifies a value. exit(): This function causes immediate termination of the entire program, forcing a return to the OS. The general form of the function is: void exit(int return_code); The value of return_code is returned to the calling process, which is usually the OS system. exit(0) Zero is generally used as a return code to indicate the normal program termination. Other arugments are used to indicate some sort of error. Also, one can make use EXIT_SUCCESS and EXIT_FAILURE for the return code. The exit() function requires the header stdlib.h. Page 43

44 Session 3: C++ Functions Checklist Sl.No. Exercise / Program Date of Completion 1. Function with no arguments and no return type 2. Function with arguments and no return types 3. Function with arguments and return types 4. Recursive function 5. Function with call by value 6. Function with call by reference 7. Function with return by reference 8. auto storage class 9. static storage class 10. extern storage class 11. Inline function 12. Default arguments 13. Function overloading 14. Passing one dimensional array to a function Staff Signature: Page 44

45 27. Functions A function is a collection of statements grouped into a single unit which is given a name. This unit can be invoked from other parts of the program. The most important reason to use the function is to modularize the program with smaller reusable components. It reduces the program size. The function code appears only in one place in memory, but the function is executed many times in a course of the program. There are basically two types of functions: Library functions and User defined functions. 28. main() function C does not specify any return type for the main() function, which is the starting point for the execution of a program. However, in C++, the main() function returns a value of type int to the OS. C++ therefore explicitly defines main() as matching one of the following prototypes. int main(); int main(int argc, char * argv[]); Most C++ compilers will generate an error or warning if there is no return statement. Therefore, in all our programs we attach return 0 statements. 29. Function prototyping Function prototyping is one of the improvements added to C++. The prototype describes the function interface to the compiler by giving details such as the number and arguments and the type of return values. With function prototyping, a template is always used when declaring and defining a function. Any violation in matching the arguments or the return types will be caught by the compiler at the time of compilation itself. These checks and controls did not exist in the conventional C functions. Function prototype is a declaration statement in the calling program and is of the following form: type function-name (argument-list); Example: Note: int sum( int a, int b); int sum(int a,b); // illegal In a function declaration, the names of the arguments are dummy variables and therefore, they are optional. The acceptable form is int sum(int, int); In the function definition the names are required, because the arguments must be referenced inside the function. Example: int sum(int a, int b) { return a+b; Page 45

46 In C++, the empty argument list means void. But in C, it implies any number of arguments. In C++, void display() means void display(void). A C++ function can also have an open parameter list by use of ellipses void display( ); 30. Categories of functions A function depending on whether arguments or present or not and whether a value is returned or not, may belong to one of the following categories No arguments and no return type // program 25 void sum() { int a=4,b=5,c; c=a+b; cout<<c; { sum(); With arguments and no return type // program 26 void sum(int a, int b) { int c; c = a+b; { sum(4,5); With arguments and Return values // program 27 int sum(int a, int b) {return a+b; { cout<<sum(4,5); 31. Recursive function Recursion is a process by which a function calls itself repeatedly, until a specified condition has been satisfied. The process is used for repetitive computations in which action is stated in terms of previous result. For example, the factorial of a number is expression by a recursive formula: n! = n * (n-1)! // Program 28 Recursive function # include<iostream.h> long int fact(int x) { if x(==1) return 1; else return (x *fact(x-1)); { long int factorial; factorial = fact(10); cout<< factorial of 10 is << factorial; Page 46

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology) ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology) Subject Description: This subject deals with discrete structures like set theory, mathematical

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

Curriculum Map. Discipline: Computer Science Course: C++

Curriculum Map. Discipline: Computer Science Course: C++ Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

Objective-C Tutorial

Objective-C Tutorial Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Syllabus OBJECT ORIENTED PROGRAMMING C++

Syllabus OBJECT ORIENTED PROGRAMMING C++ 1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

MISRA-C:2012 Standards Model Summary for C / C++

MISRA-C:2012 Standards Model Summary for C / C++ MISRA-C:2012 Standards Model Summary for C / C++ The LDRA tool suite is developed and certified to BS EN ISO 9001:2000. This information is applicable to version 9.4.2 of the LDRA tool suite. It is correct

More information

A brief introduction to C++ and Interfacing with Excel

A brief introduction to C++ and Interfacing with Excel A brief introduction to C++ and Interfacing with Excel ANDREW L. HAZEL School of Mathematics, The University of Manchester Oxford Road, Manchester, M13 9PL, UK CONTENTS 1 Contents 1 Introduction 3 1.1

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

More information

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

BCS2B02: OOP Concepts and Data Structures Using C++

BCS2B02: OOP Concepts and Data Structures Using C++ SECOND SEMESTER BCS2B02: OOP Concepts and Data Structures Using C++ Course Number: 10 Contact Hours per Week: 4 (2T + 2P) Number of Credits: 2 Number of Contact Hours: 30 Hrs. Course Evaluation: Internal

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

Basic Programming and PC Skills: Basic Programming and PC Skills:

Basic Programming and PC Skills: Basic Programming and PC Skills: Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

UML for C# Modeling Basics

UML for C# Modeling Basics UML for C# C# is a modern object-oriented language for application development. In addition to object-oriented constructs, C# supports component-oriented programming with properties, methods and events.

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Algorithms, Flowcharts & Program Design. ComPro

Algorithms, Flowcharts & Program Design. ComPro Algorithms, Flowcharts & Program Design ComPro Definition Algorithm: o sequence of steps to be performed in order to solve a problem by the computer. Flowchart: o graphical or symbolic representation of

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List

MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List This is a list of the error/warning messages generated by the Texas Instruments C/C++ parser (which we license

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science I. Basic Course Information RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE CISY 105 Foundations of Computer Science A. Course Number and Title: CISY-105, Foundations of Computer Science B. New

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

Binary storage of graphs and related data

Binary storage of graphs and related data EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics

More information

Syllabus for CS 134 Java Programming

Syllabus for CS 134 Java Programming - Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.

More information

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint) TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

Two-way selection. Branching and Looping

Two-way selection. Branching and Looping Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.

More information

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com C++ Essentials Sharam Hekmat PragSoft Corporation www.pragsoft.com Contents Contents Preface 1. Preliminaries 1 A Simple C++ Program 2 Compiling a Simple C++ Program 3 How C++ Compilation Works 4 Variables

More information

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT, 15.1200.40

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT, 15.1200.40 SOFTWARE DEVELOPMENT, 15.1200.40 1.0 APPLY PROBLEM-SOLVING AND CRITICAL THINKING SKILLS TO INFORMATION TECHNOLOGY 1.1 Describe methods and considerations for prioritizing and scheduling software development

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Fourth generation techniques (4GT)

Fourth generation techniques (4GT) Fourth generation techniques (4GT) The term fourth generation techniques (4GT) encompasses a broad array of software tools that have one thing in common. Each enables the software engineer to specify some

More information

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

More information

Chapter 1: Key Concepts of Programming and Software Engineering

Chapter 1: Key Concepts of Programming and Software Engineering Chapter 1: Key Concepts of Programming and Software Engineering Software Engineering Coding without a solution design increases debugging time - known fact! A team of programmers for a large software development

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11. The C++11 CORBA Implementation CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection

More information

Computer Programming Tutorial

Computer Programming Tutorial Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer

More information

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) Instruction Set Architecture (ISA) * Instruction set architecture of a machine fills the semantic gap between the user and the machine. * ISA serves as the starting point for the design of a new machine

More information

C++FA 3.1 OPTIMIZING C++

C++FA 3.1 OPTIMIZING C++ C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have

More information

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Lumousoft Visual Programming Language and its IDE

Lumousoft Visual Programming Language and its IDE Lumousoft Visual Programming Language and its IDE Xianliang Lu Lumousoft Inc. Waterloo Ontario Canada Abstract - This paper presents a new high-level graphical programming language and its IDE (Integration

More information

Programming and Software Development (PSD)

Programming and Software Development (PSD) Programming and Software Development (PSD) Course Descriptions Fundamentals of Information Systems Technology This course is a survey of computer technologies. This course may include computer history,

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information