Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: C++ Complete reference Quick Start for begineers
Description: This document consists of usefull c++ resources for beginners.
Description: This document consists of usefull c++ resources for beginners.
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
1|P ag e
C Plus Plus Complete Reference Guide Quick Notes
// I am single line comments
/* I am multi line comment */
Points to be noted:
1
...
All keyword starting from small letters
3
...
Whole Number:
int
4 bytes
short
2 bytes
long
8 bytes
Real Number:
float
4 bytes
double 8 bytes
char/ string :
char 1 byte
string “Ali” 3+1 // 3 character bytes + 1 null byte
bool 1 bit true/ false
Hafiz Muhammad Umar Hayat
Page 1
2|P ag e
Variable: A thing which holds the data is called variable
...
Data type
2
...
Name
4
...
50;
char c='a';
string s="Umar";
Operator: 3 types
1
...
Relational Operators: returns true or false only
<,>,<=,>=,==
3
...
If /else
if( //condition)
{
}
else{
}
//2 switch statement
Switch(//variable or expression)
{
case 1:
break;
case 2:
break;
case 3:
break;
default:
}
Hafiz Muhammad Umar Hayat
Page 3
4|P ag e
Loop: loops structures are used for repetition
Types:
//1
...
Do while
do{
} while(//condition);
//for loop
For(int i=0; i<=10;i++)
{
}
Array: A collection of elements which has same data type is called an array
...
The name of an array is a constant pointer which always points to the first element of that array
...
Declaration: declare name of function
//2
...
Calling a function: use a function
Types: 2 types
1
...
A function returns nothing use void as return type
Hafiz Muhammad Umar Hayat
Page 5
6|P ag e
Example:
//creating a function to add two numbers
//declare a function
int add(int a,int b);
//define an add function
int add(int a,int b)
{
return a+b; //returning the value
}
//calling
add(4,5);
Example 2: setting the value from void function
//declare a function
void setValue(int );
void setValue(int t )
{
total=t;
}
Hafiz Muhammad Umar Hayat
Page 6
7|P ag e
Function overloading:
Ability of a function to perform more than one functionality
To do that we have 2 options
1
...
change number of parameters
int myFunction(int a,int b)
{
return a+b;//add 2 numbers
}
float myFunction(float a,float b)
{
return a*b;//multiply 2 numbers
}
int myFunction(int a)
{
return -a;//return negation of a
}
int main(){
int a=10;int b=20;
flaot f=2
...
45;
cout<
}
Hafiz Muhammad Umar Hayat
Page 7
8|P ag e
Templates:
Templates are used to provide the same functionality on different data types
...
50; float d=34
...
";
} else {
throw (age);
}
}
catch (int myNum) {
cout << "Access denied - You must be at least 18 years old
...
name = "umar";
p
...
name << endl;
cout << "Person age: " << p
...
setSalary(50000);
cout << myObj
...
honk();
cout << myCar
...
model;
return 0;
}
Hafiz Muhammad Umar Hayat
Page 12
13 | P a g e
Polymorphism:
//create a parent or Base class
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound \n" ;
}
};
// Derived class
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow \n" ;
}
};
// Derived class
class Cat : public Animal {
public:
void animalSound() {
cout << "The cat says: miaoon miaoon \n" ;
}
};
Hafiz Muhammad Umar Hayat
Page 13
14 | P a g e
int main()
{
Animal myAnimal;
Cat cat;
Dog dog;
myAnimal
...
animalSound();
dog
...
txt");
// Write to the file
MyFile << "Hi! I am creating a file using c++";
// Close the file
MyFile
...
txt");
Hafiz Muhammad Umar Hayat
Page 15
16 | P a g e
// Use a while loop together with the getline() function to read the file line by line
while (getline (MyReadFile, myText))
{
// Output the text from the file
cout << myText;
}
// Close the file
MyReadFile
...
enum enum_name{const1, const2,
Title: C++ Complete reference Quick Start for begineers
Description: This document consists of usefull c++ resources for beginners.
Description: This document consists of usefull c++ resources for beginners.