Class Session 1 Introduction
Class Session 1 Introduction
By: Girish Kumar N G Assistant Professor Bangalore Institute of Technology V.V.Puram, K.R.Road, Bangalore-560004
Syllabus
UNIT - 1 C++, AN OVERVIEW: Getting started, the C++ program, Preprocessor Directives, The Built-In Array Data Type, Dynamic Memory Allocation and Pointers, An Object based Design, An Object-Oriented Design, An Exception based Design. 6 Hours UNIT - 2 THE BASIC LANGUAGE: Literal Constant, Variables, Pointer Type, String Types, const Qualifier, Reference Types, the bool type, Enumeration types, Array types. The vector container type. 6 Hours
UNIT - 3 OPERATORS: Arithmetic Operators, Equality, Relational and Logical operators, Assignment operators, Increment and Decrement operator, The conditional Operator, Bitwise operator, bit-set operations. Statements: if, switch, for Loop, while, break, goto, continue statements. 7 Hours UNIT - 4 FUNCTIONS: Prototype, Argument passing, Recursion and linear function. 6 Hours UNIT - 5 EXCEPTION HANDLING: Throwing an Exception, Catching an exception, Exception Specification and Exceptions and Design Issues. 6 Hours
UNIT - 6 CLASSES: Definition, Class Objects, Class Initialization, Class constructor, The class destructor, Class Object Arrays and Vectors. 7 Hours UNIT - 7 Overload Operators, Operators ++ and --, Operators new and delete. 7 Hours UNIT 8 Multiple Inheritance, public, private & protected inheritance, Class scope under Inheritance. 6 Hours
Textbooks
Prescribed: C++ Primer S. B. Lippmann & J. Lajoie, 3rd Edition, Addison Wesley, 2000. Advice: Let us C++ by Yeshwanth Kanitkar and Programming using C++ by Balaguru Swamy
Topics
1.1 Why Program? 1.2 Computer Systems: Hardware and Software 1.3 Programs and Programming Languages 1.4 What Is a Program Made of? 1.5 Input, Processing, and Output 1.6 The Programming Process
1-6
1-7
1-8
1-9
1-10
1-11
Main Memory
Holds both program instructions and data
1-12
Byte
Is 8 consecutive bits
Word
Usually 4 consecutive bytes Has an address
1-13
1 byte
Secondary Storage
Non-volatile - data retained when program is not running or computer is turned off Comes in a variety of media
magnetic: floppy or hard disk drive, internal or external optical: CD or DVD drive flash: USB flash drive
1-14
Input Devices
Used to send information to the computer from outside
Many devices can provide input
keyboard, mouse, microphone, scanner, digital camera, disk drive, CD/DVD drive, USB flash drive
1-15
Output Devices
Used to send information from the computer to the outside Many devices can be used for output
Computer screen, printer, speakers, disk drive, CD/DVD recorder, USB flash drive
1-16
Application software
1-17
Program
Programming Language
a language used to write programs
1-18
1-19
1-22
1-23
Example Program
#include <iostream> using namespace std; int main() { double num1 = 5, num2, sum; num2 = 12;
sum = num1 + num2; cout << "The sum is " << sum; return 0;
}
1-24
Key Words
Also known as reserved words
Programmer-Defined Identifiers
Names made up by the programmer
1-26
Operators
Used to perform operations on data
1-27
Punctuation
Characters that mark the end of a statement, or that separate items in a list Example in program (shown in green): double num1 = 5, num2, sum; num2 = 12;
1-28
1-29
1-30
Variables
A variable is a named location in computer memory (in RAM) It holds a piece of data It must be defined before it can be used Example variable definition:
- double num1;
1-31
1-32
1-33
1-34
What is C++?
To understand let us consider an example: i=2; j=i++; So what will be the j value? j= 2,3. So i++ can be said as post increment operation means the output first displays the initial value and then it displays the incremented value.
In a similar way here C++ is first the output takes initial value of C means all the concepts of C what you have read previously is there in C++, and then the next output which is an incremented value is compared with the new concepts that are introduced in C++ which are not present in simple C language like inheritance, polymorphism and so on
#include<stdio.h> int main(){ int num,r,sum=0,temp; printf("Enter a number: "); scanf("%d",&num); temp=num; while(num){ r=num%10; num=num/10; sum=sum*10+r; } if(temp==sum) printf("%d is a palindrome",temp); else printf("%d is not a palindrome",temp); return 0; }
Reverse a string in c
#include<iostream.h> #include<string.h> int main(){ char str[50]; char *rev; cout<<Enter any string:; cin>>s; rev = strrev(str); cout<<"Reverse string is : %s<<rev; return 0; }
#include<stdio.h> #include<string.h> int main(){ char str[20]; int i; printf("Enter any string->"); scanf("%s",str); printf("The string is->%s",str); for(i=0;i<=strlen(str);i++){ if(str[i]>=65&&str[i]<=90) str[i]=str[i]+32; } printf("\nThe string in lower case is->%s",str); return 0; }
C++ Program
So let us now learn what is all about a language C++ What are the applications of C++ What are advantages of using C++ over C and comparison of C++ with other languages