0% found this document useful (0 votes)
116 views

C Plus Plus

C++ is an object-oriented programming language that was developed as an enhancement to the C programming language and introduced object-oriented programming capabilities to C. Some key aspects of C++ include: - It supports concepts like encapsulation, inheritance, and polymorphism which are important aspects of object-oriented programming. - C++ was created by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill. It adds object-oriented programming capabilities to the C language by enhancing C with classes, inheritance, strong typing, and other features. - C++ can be used to write both object-oriented and procedural code and is a middle-level language, meaning it can be compiled down to

Uploaded by

Sarah Khaleel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views

C Plus Plus

C++ is an object-oriented programming language that was developed as an enhancement to the C programming language and introduced object-oriented programming capabilities to C. Some key aspects of C++ include: - It supports concepts like encapsulation, inheritance, and polymorphism which are important aspects of object-oriented programming. - C++ was created by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill. It adds object-oriented programming capabilities to the C language by enhancing C with classes, inheritance, strong typing, and other features. - C++ can be used to write both object-oriented and procedural code and is a middle-level language, meaning it can be compiled down to

Uploaded by

Sarah Khaleel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

C ++ , C plus plus : programming languages:

Definition of ++ programming language


 Such programing language that was build full c language is known as C
Plus Plus.
 Some precaution for plus plus
C++ is contumely name.
CPP Stand for C plus plus

Some other definition of C plus plus:


C++ is a mother of all programming language.
C++ like a increment mean more languages add ke jate hen
Like a increment operator
C++ consider a middle level language
C++ developed by Bjarne Stroustrup started in 1979 at Bell Labs in Murry Hill.
C++ is a one dimensional language.
C++ consists of three important parts.
Building blocks, including data type and literals etc.
The C++ standard library giving us set of function manipulating files and Strings
etc.
The standard template Standard library (STL) Giving a loaded set of method
manipulating structure etc.

C++ support object oriented programming


language depend on four points.
Encapsulation
Data hiding
Inheritance
Polymorphism
Owner of plus plus:
Cpp developed by Bjrae Stroustrup in 1979 at Bell lab (PHD thesis)

History of c++:

C language chaged the name ccpp in


1st 1985
2nd 1989
2.1 1991
The Standart Tmeplate libarar 1998
Sir umer still now in bell lab.
3rd 2003 start
3rd releas 2005
4rh 2011 =132 books and 27 lac sale out.
5th 2014= 36 books and 56 lac slae out.
6th 1 dec 2017 -10 book and sale in 56 lac
7th2020

72 lange ARfa company ka Ceo… Timly

#include <iostream>
Include mean add kro.
Iostream.
.Input output stream

Using namespace.
Its use the name of file for exude the program.
Cout mean console output
Cin.. mean console input

Main is a function which is entry point of the program or stomach of the program.
Which gives data to the io stream etc.
Semi colon error btaata he.
Int 0 == 0 to 999

If , else statement in c++

#include<iostream>
using namespace std;
main()
{
int x = 20;
int y = 30;
if ( x==20)
{
cout << "Naveed ";
}else
{
cout << "pakistan ";
}
}

Do while loop

#include<iostream>
using namespace std;
int main(){
int y;
y = 1;
do
{
cout<<"value is of loop is" <<y<<endl;
y = y+1;
}
while(y < 10);
}

Value enter by user and float value:


#include<iostream>
#include<cmath>
using namespace std;
int main(){
double number;
double squareRoot;
cout<<"Enter the value";
cin>>number;
squareRoot = sqrt(number);
cout<<"Value of Sqauroot is";
cout<<number<<squareRoot<<endl;

Calulatore code in C++

#include<iostream>
using namespace std;
int main(){
int num1;
int num2;
char x;
while(true){
cout<<"Enter the 1st value for arithmetition"<<endl;
cin>>num1;
cout<<"Enter the 2nd value for arithmetition"<<endl;
cin>>num2;
cout<<"Enter Minus(-)for substraction"<<endl;
cout<<"Enter Plus(+)for Addition"<<endl;
cout<<"Enter Multiple(*)for Multiplication"<<endl;
cout<<"Enter divide(/)for divion"<<endl;
cout<<"Enter Now"<<endl;
cin>>x;

if(x=='-')//will use nested loop because we want multiple taske


{
cout<<" You have entered Minus(-) for substraction "<<endl;
cout<<" Your entered value is (" <<num1<<"-"<<num2<<")"<<endl;
cout<<" Result of Minus value is (";
cout<<num1 - num2<<")"<<endl;

}
else if(x=='+')
{

cout<<" You have entered Plus(+) for substraction "<<endl;


cout<<" Your entered value is("<<num1<<"+"<<num2<<")"<<endl;
cout<<" Result of Plus value is ("<<endl;
cout<<num1 + num2<<endl;
}
else if(x=='*')
{
cout<<" You have entered Plus(*) for multiplication "<<endl;
cout<<" Your entered value is ("<<num1<<"*"<<num2<<")"<<endl;
cout<<" Result of Multiple value is"<<endl;
cout<<num1 * num2<<endl;

}
else if(x=='/')
{
cout<<" You have entered Plus(/) for divion "<<endl;
cout<<" Your entered value is("<<num1<<"/"<<num2<<")"<<endl;
cout<<" Result of Divide value is"<<endl;
cout<<num1 / num2<<endl;

}
else
{
cout<<"Invalid input"<<endl;
}

}
return 0;

OOp start krde in C++

#include<iostream>
using namespace std;
class sara{
//privang name = "sara1";// ye mistake theee
//sting and pvt check krne apni
private:
string name = "sara1";
string address = "rawalpindi";
int age = 15;
public:
string talk = "talks too much";
void setName(string n){
name = n;
}
void setAddress(string a){
address = a;

}
void setAge(int a){
age = a;

}
string getName(){
return name;
}
string getAddress(){
return address;

}
int getAge(){
return age;
}
};
int main(){
sara A1;
//cout<<A1.getName();
//cout<<A1.getAddress();
//cout<<A1.talk;
//cout<<A1.getAge();
cout<<A1.getName()<<endl;
cout<<A1.getAddress()<<endl;
cout<<A1.talk<<endl;
cout<<A1.getAge()<<endl;
}
Function

A function is a group of statement that together perform a task.


Which work a man cannot perfume .but a machine. Like A heavy multiplication
Like a billion words of multiplication.
.. We can save also time.
We can make more accuracy with function then a man.
C++ is mother of all languages .
All language children of c++.
C++ function are using mostly machine .like A radar earoplane etc.

Rules function
1.Agr ksi cheez ka tarteeb se increase ya decrease hona there will use function.
2.Calculater. Main be function use hoga.
3. argument ko call krwaney ke liye.
4.error door krney ke liye.
5.eroplane function.. door krey ga.

Example and code of Function by passing value :


#include<iostream>
#include<string>
using namespace std;
void printarray (int arg[],int length){
for(int n = 0;n < length; n++){
cout<<arg[n]<<endl;
}
}
main(){
int firstarray[]={1,2,3,4,};
int secondarray[]={5,6,7,8};
printarray(firstarray,2);
printarray(secondarray,2);
}

Array Definition:
Array is big size collection of similar data type items.

Used of Array:
Array can used to store access group data of same data type data type.

Types of the Array:


There are three types of array:
1- One dimensional array
2- Two dimensional array
 Three dimensional array or multidimensional array.
 Methods of using array or Calling Array:

Passing array to a function


Return array from the function
 Size of Array and use.
There will be size of fix. Of array
Will be used similar type of data type
Array is used to store lengthy value.

 For example.
Int array = 120;
Int array = 200;
Int array = 120;
Int array = 130;

 In other Data type.


1 to lac.
Int array = 100;
Int array = 100;
Int array = 100;
Int array = 100;
Other in float double will be change of size of array.
Likewise shop. We have save one to lac digits...
Int a = 1;

 Pointer definitions
 A pointer is a variable that holds a memory address
where a value lives. A pointer is declared using the *
operator before an identifier. As C++ is a statically
typed language, the type is required to declare a
pointer.
1. Pointer is a variable that stores the address and other variable.:
2. Pointer much more easier and improve your efficiency of the program
3. Pointer store and allow unlimited amount of data :
4. Pointer is used to locate memory dynamically.
5. All operater is working in. int float char..
6. Any variable are constant u must declare a pointer for u can work with it.We
can declare constanct value..
 For example and code of Pointer

#include <iostream>
using namespace std;

main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;

function parameter

 Another example:
//introduction pointer
#include<iostream>
using namespace std;
main(){
int*ptr;
int a;
cout<<"Enter a integer:";
cin>>a;
ptr=&a;
cout<<"The value of a:"<<a<<endl;
cout<<"The Adress of a:"<<ptr<<endl;
}

 Third example of pointer:

#include<iostream>
using namespace std;
main()
{
int *ptr a = 10;
cout << "first value is " << ptr a << endl;
}

&array ke sath hm array ke data type dekh sktyn he.. ke int main valule store ke
hey kke ..
Return 0 . data structure ke property hen..

#include<iostream>
using namespace std;
main()
{

int array[5]={ 51 ,49 ,3,2 ,1} ;


std::cout << " the array has address:" << array << '\n';
std:: cout << "element has addres:" << &array[0] << '\n';
}

 Array with pointer


#include<iostream>
using namespace std;
int main()
{
char arr[4];
cout<<"please enter the no";
for(int i=0; i < 4; i++){
cin>> *(arr + i);
}
cout<<"display the data:"<<endl;
for(int i=0; i < 4; i++){
cout<< * (arr + i) <<endl;
}
}

Dynamic support the two types of memory location.


First is
Ststic momoy location.. surpoort the global variable
Static and automatic.

Memory for this types of variable is located once. When your program is run and
persists form life the life of your program.
Automatic memory location.
Supports the locate variable and parameter memory for this types of variable
Is located relevant block is enter and … when the block is existed as many time is
as necessary.
Dynamic memory location::
Dynamic memory location is a way for running the program to request the memory
from the operating system. This memory dost not come from the program. Limited
stock memory. Instead it is located from a much large.
Pol of memory managed. By the operating system. Called the heap.
Local variable..
We can give is as much as relevant value.

OOP (OBJEC ORIANTED PROGRAMMING)


Class Object oriented language

 What is class:
 Class is a user defined data type which defined by user. Class is
complete opp based data structure in it we make oriation of the object.
Definition of the Class.

 C++ Classes and Objects. Class: The building block of C++ that leads to


Object Oriented programming is a Class. It is a user defined data type,
which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class. A class is like a
blueprint for an object.
 Parts of the Class.
 Class has two modifier public and private there some public attributes
or method of the class.
 Class has also data member and member funtions like a getter and
setter.
 We can also call constructor in the class.

Example and code of the class.

#include<iostream>
using namespace std;
class Student{// class name
public:
int rollno;
string name;
double GPA;
void print(){
cout<<rollno<<"/ "<<name<<"/ "<<GPA;
}
};
main(){
Student a{85 , "AMNA" , 2.5};
a.print();
}

2nd Example and code of the class.

#include<iostream>
using namespace std;
class Student{// class name
public:
int rollno;
int id;
int year;
void print(){
cout<<rollno<<"/ "<<id<<"/ "<<year;
}
};
main(){
Student a{85 , 6 , 2018};
a.print();
}

#include<iostream>
using namespace std;
class Student{// class name
public:
int rollno;
string name;
double GPA;
char gender;
void print(){
cout<<rollno<<"/ "<<name<<"/ "<<GPA<<"/"<<gender;
}
};
main(){
Student a{85 , "AMNA" , 2.5 ,'female'};
a.print();
}

Conceptual Apprach..
Conceptual mean think and approach mean .. last step taak reach and finish.
5 things oop ke sath call hote..encapsulaiotn.Abstraction. polymorphisam.,
inheritance
Reusability.
Encapsulation:
Encapsulation: is a most important of the programing language.
This is used for data hiding ,

#include<iostream>
class somethings {
public :
int a_value1 ;
int a_value2 ;
int a_value3 ;

};
int main()
{
somethings example;
example.a_value1 = 5;
std::cout << "example.a_value1 ";
}

Abstraction class::

PRIVATE AND PUBLIC IS A FEATURE OF THE FUNTION.


Public.
Private:
#include <iostrdam>
Then only
Class:

Inheritace takes place ..


One class inherited from another drive class the member both variable and function
of the base class.

Multiclass ko ran krney ke liye inheritance call krte hen!!

Add a new operator for function is used for the this operator.
Void data ko screen pr how krwaney ke liye use hota hye.

Class ya sturend use krty hne wo jeneric hotey hen!!

What is Template?
Templates are powerful features of C++ which allows you to write generic
programs. In simple terms, you can create a single function or a class to work with
different data types using templates.

Second definition:
Templates are of great utility to programmers in C++, especially when combined
with multiple inheritance and operator overloading. The C++ Standard
Library provides many useful functions within a framework of connected
templates

The concept of templates can be used in two different


ways:
 Function Templates
 Class Templates

A function template works in a similar to a normal function, with one key


difference.
A single function template can work with different data types at once but, a single
normal function can only work with one set of data types.
A class template use with class key word:

 Example or code of Template:


Program to add, subtract, multiply and divide two numbers using class template

#include <iostream>
using namespace std;

template <class T>


class Calculator
{
private:
T num1, num2;

public:
Calculator(T n1, T n2)
{
num1 = n1;
num2 = n2;
}

void displayResult()
{
cout << "Numbers are: " << num1 << " and " << num2 << "." << endl;
cout << "Addition is: " << add() << endl;
cout << "Subtraction is: " << subtract() << endl;
cout << "Product is: " << multiply() << endl;
cout << "Division is: " << divide() << endl;
}

T add() { return num1 + num2; }

T subtract() { return num1 - num2; }

T multiply() { return num1 * num2; }

T divide() { return num1 / num2; }


};

int main()
{
Calculator<int> intCalc(2, 1);
Calculator<float> floatCalc(2.4, 1.2);

cout << "Int results:" << endl;


intCalc.displayResult();

cout << endl << "Float results:" << endl;


floatCalc.displayResult();

return 0;

In the above program, a class template Calculator is declared.


The class contains two private members of type T: num1 & num2, and a constructor to initalize the
members.
It also contains public member functions to calculate the addition, subtraction, multiplication and division
of the numbers which return the value of data type defined by the user. Likewise, a
function displayResult() to display the final output to the screen.
In the main() function, two different Calculator objects intCalc and floatCalc are created for data
types: int and float respectively. The values are initialized using the constructor.
Notice we use <int> and <float> while creating the objects. These tell the compiler the data type used for
the class creation.
This creates a class definition each for int and float, which are then used accordingly.
Then, displayResult() of both objects is called which performs the Calculator operations and displays the
output.

Structure

Structure is user for the software development.


In Structure available no of data type.
An object where we need used to different data type that is called structure..

Software .. one person use.


Application ..multiple perso use.
#include<iostream>
using namespace std;
struct Patient
{
char name;
char disease;
float fee;
};
int main()
{
Patient p1;
cout << "Enter patient name: ";
cin >> p1.name;
cout << "Enter diease name: ";
cin >> p1.disease;
cout << "Enter Fee: ";
cin >> p1.fee;

cout << "\nDisplaying Information." << endl;


cout << "Name: " << p1.name << endl;
cout <<"Diease: " << p1.disease << endl;
cout << "Fee: " << p1.fee;
}

You might also like