Computer science bsc 2nd yr, Summaries of Computer Science

Studying in Madras university of tamilnadu

Typology: Summaries

2018/2019

Uploaded on 10/23/2019

Kamaliguna
Kamaliguna 🇮🇳

3 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
INTRODUCTION OF C++
VARIABLE:
Variable is a quantity which changes during a execution of the
program.
Declaration does three things:
It gives name to memory location.
It species the type of data.
It allocates memory space.
Rules for naming variable:
The rst character in a variable must be an alphabet A,B,C,
Underscore -, dollar
$. Commas or blankspace are not allowed within a variable name.
Variable names are case sensitive.
Declaration of variable:
All the variable to be dened anywhere in the space.
The general format is
Data type variable _ name;
Example:
int count;
Float(x,y);
Double p;
Intiliazation of variable:
The general format is
Data type variable _name=value or expression;
Example:
int A=10;
char c=”m”;
string “MAN”;
Dynamic intilization:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Computer science bsc 2nd yr and more Summaries Computer Science in PDF only on Docsity!

INTRODUCTION OF C++

VARIABLE:

Variable is a quantity which changes during a execution of the program. Declaration does three things: It gives name to memory location. It specifies the type of data. It allocates memory space. Rules for naming variable: The first character in a variable must be an alphabet A,B,C, Underscore -, dollar $. Commas or blankspace are not allowed within a variable name. Variable names are case sensitive. Declaration of variable: All the variable to be defined anywhere in the space. The general format is Data type variable _ name; Example: int count; Float(x,y); Double p;

Intiliazation of variable: The general format is Data type variable _name=value or expression; Example: int A=10; char c=”m”; string “MAN”; Dynamic intilization:

The variable can be intiliazed at run time using expression at a place of declaration. This is referred to as dynamic intilization. Example: int m=10; OPERATORS: An operator is a symbol which helps the user to command the complier to do Certain mathematical or logical manipulations .Operators are used in c language program to operate on data and variable. TYPES OF DATA: Arithmetic operators. Relational operators. Logical operators. Assignment operators. Increment and decrement operators. Bitwise operators. Conditional operators. Special operators. ARITHMETIC OPERATORS: Arithmetic operators are used to perform arithmetic calculations. C provides basic arithmetic operators.

Operators Example Meaning

  • a+b Addition or Unary

LOGICAL OPERATORS:

Logical operators is used to find out thr relationship between two or more Relationship expression.

Operators meaning && logical AND || logical OR ! logical NOT

The logical operators && and || are used when we want to form compound Conditions by combining two or more relation.

ASSIGNMENT OPERATORS: Assignment operators are used to assign value of an expression is a Variable. The assignment operators evaluate an expression on the right of the Expression and substitutes it to the value or variable on the left of the expression. SYNTAX: V op=exp; Where, V=variable Exp=expression

Op=binary operators = is known as the assignment operators. V op =exp; is equal to v=v op(exp); That is, X+=y+1; is equal to x=x+(y+1)

INCREMENT AND DECREMENT OPERATORS: C++ has very useful operators. They are increment (++)and decremented(--)operators. The increment operators(++)adds to the operators value contained in the variable Increment has two types: Pre increment(variable++). Post increment(variable ++) Decrement has two types: Pre decrement(variable--) Post decrement(variable--).

BITWISE OPERATORS: Bitwise operators are used to perform bit by bit operations. A Bitwise operators operates on each bit of data. Those operators are used for testing complementing or shifting Bits to the right on left.

Operators meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR

Bitwise right shift << Bitwise left shift

MANIPULATORS:

Manipulators are operators are used to format the data display. The most commonly used manipulators are endl and setw. The endl operators used in an output statement. It has the same effect using the new line characters (“backslash”). The setw manipulators also used in an output. The form of output can specify a common field width for all the number And force them to be printer right justified. Example: Cout<<setw(&)<<sum<<endl; Program: #include<iostream.h> #include<iomanip.h> int main() { int basic=950,allowance=95,total=1045;cout<<setw(10)<<”basic”<< Setw(10)<<basic<<endl<<setw(10)<<”allowance”<<setw(10)<< Allowance<<endl<<setw(10)<<”total”<<setw(10)<<total<<endl; Return0; }

CONTROL STRUCTURES: The combination of control structure are Sequence structure(straight line) Selection structure(branching) Loop structure(iteration and repeatition). The if statement:

The if statement is implemented into tow forms Simple if statement If else statement. Simple if statement: This statement is only used for ture condition. Syntax: If(expression) { action1; } action2: When this statement is executed, evaluates the value of the test condition. If the value is true then the statement block and the next statement gets Executed sequentically. If the value is false the statement block is skipped and execution starts the next statement. If else statment: The if else statement is used to execute one group of statement. If the test condition is true and other group of statement if the test Condition is false. Syntax: If(test condition) { Statement1; } Else

action 1; } action2;

FOR LOOP STATEMENT: The for is an entrolled loop and is used when an action is to be repeated for a Three determine number of time. Syntax: For(initialize;condition;increment/decrement) { Action1; } MAIN FUNCTION: C++ does not specific any written type of main()function which is the starting point of the execution of the program. The definition of main function Main ()function { Main pro } In c++ the main function returns the value of type int to the Operator system. In c++ therefore explicity defines main function as matching One of the following protype. int main() int main(int arg,char*arg v[]; The function that have a return value should use the return Statement for termination.

The main function in c++is therefore defined as follows: int main() { Return0; }

FUNCTION PROTYPING:

Function protyping is one of the major improvement added to c++ Function. The protype describes a the function interface to the complier by giving details such as the number and type of argument and type of return type. In function protype a template this always used when declaring and defining a function.

Syntax: Type function _name(argument list) Example: Double volume (doubler int h) In general we can either include or exclude the variable names in the argument list of protype. The variable names in the argument just act as place holders and therefore if names are used,they do not have the match the names

used in the function call or function definition. In function definition names required because the arguments, must be referred inside the function.

When a class contains a constructor like the one defined above it is guaranted that an object created by the class will be initialized automatically. For example: The declaration Integer int1; PARAMETERIZED CONSTRUCTORS: The constructor integer( ),initialize the data members of all Object to zero. The initialize the various data elements of different objects With different values when they are created to achieve this objective by Passing arugments to the constructor f unction when the object are created. The constructor that can take arguments are called Parameterized constructors. The constructor integer( ) may be modified to take argument as shown below class integer { int m,n;e public: integer(int x,int y); }; Integer::integer(int x,int y); { m=x;n=y; } When a constructor has been parameterized the object declaration Statement such as integer int 1; CLASS WITH CONSTRUCTOR #include <iostream.h> Using namespace std; Class integer {

int m,n; public: integer(int ,int); void display(void) { cout<<”m=”<<m<<”\n”; cout<<”n=”<<n<<”\n”; }; integer::integer(int x,int y) { m=x;n=y; } int main() { Integer int(10,100); integer int 2=integer(25,75); cout<<”\n OBJECT 1”<<”\n”; int 1 .display( ); cout<<”\n OBJECT 2”<<\n”; int 2.display( ); return 0; } Multiple constructor in a class: Two kinds of constructor They are Integer( ); Integer (int,int); The constructor itself supplies the data values and no values are passed the appropriate values from main( ) class integer { int m,n; public:

Cout<<id; } }; int main( ) { code A(100); code B(A); code C=A; code D; D=A; Cout<<”\n id of A:”;A.display( ); Cout<<”\n id of B:”;B.display( ); Cout<<”\n id of C:”;c.display( ); Cout<<”n id of D:”;D.display( ) return 0; } DYNAMIC CONSTUCTOR: The constructor can also be used to allocate memory while creating object