#include<iostream>
#include<conio.h>
using namespace std;
class point{
float a;
int sum;
public:
float setnumber(int n){
a=n;
for(int x=a;x<=5;x++){
cout<<"\t"<<x<<endl;
sum=sum+x;
}
}
void display(){
cout<<" ------\n";
cout<<"Sum is "<<sum<<endl;
}
};
int main(){
point p;
point *p1;
p1=&p;
cout<<"Sum of Series : "<<endl;
p1->setnumber(1);
p1->display();
cout<<"Adress of Sum is : "<<p1;
getch();
return 0;
}
Programming in C++ using pointer
program 1:
#include<iostream>
using namespace std;
class pointer{
float a,b;
public:
float setnumber(int n,int n1){
a=n;
b=n1;
}
void display(){
cout<<a<<endl;
cout<<b<<endl;
}
};
int main(){
pointer p;
pointer *p1;
pointer **p2;
p1=&p;
p2=&p1;
p1->setnumber(12,54);
p1->display();
return 0;
}
Program 2:
#include<iostream>
using namespace std;
void add(int *a,int *b)
{
int sum=0;
sum=*a+*b;
cout <<"sum "<<sum;
}
int main()
{
int x,y;
cout<<"Enter value of x and y";
cin>>x>>y;
int *q,*w;
add(&x,&y);
}
#include<iostream>
using namespace std;
class pointer{
float a,b;
public:
float setnumber(int n,int n1){
a=n;
b=n1;
}
void display(){
cout<<a<<endl;
cout<<b<<endl;
}
};
int main(){
pointer p;
pointer *p1;
pointer **p2;
p1=&p;
p2=&p1;
p1->setnumber(12,54);
p1->display();
return 0;
}
Program 2:
#include<iostream>
using namespace std;
void add(int *a,int *b)
{
int sum=0;
sum=*a+*b;
cout <<"sum "<<sum;
}
int main()
{
int x,y;
cout<<"Enter value of x and y";
cin>>x>>y;
int *q,*w;
add(&x,&y);
}
Computer Programing
Q1: What are different types of variable?
Answer:
A predefined word which have a specific meaning in compiler. These are types of variable.
1. Integer:
It used to store integer value. Keyword use for integer is 'int'. It requires 4 bytes of memory.
2. Character:
It used to storing characters. Keyword use for character is 'char'. It requires 1 byte of memory space.
3. Boolean:
It used for storing logical values. It stores either true or false. Keyword use for Boolean is 'bool'.
4. Floating:
It used for storing decimal value. Keyword used for floating point is 'float'. It requires 4 byte of memory space.
5. Double:
It used for storing double precision floating point values. Keyword used for double floating point is 'double'. It requires 8 byte of memory space.
Q2: What are relation, arithmetic, & logical operators?
Answer:
Relational operators:
The relational operators are used to test a relation between two expressions.
1. Greater then >
2. Greater than or equal to >=
3. Less then <
4. Less then or equal <=
5. Equal to ==
6. Not equal to !
Arithmetic Operators:
1. Addition +
2. Subtracts -
3. Multiplies *
4. Divide \
5. Modulus %
Logical operators:
1. AND (&&):
When "And" is used it give answer is true only when both conditions is true. If one is false then it gives answer false.
2. OR (| |):
When "Or" is used it give answer is false only when both conditions is false. If anyone is true it give answer is true.
3. NOT (!):
When "Not" is used it reverse its answer. If answer is false it changes in true. If answer is true it changes in false.
Q3: What is precedence of arithmetic operations?
Answer:
Precedence:
Precedence of arithmetic operations in c++ is same as in mathematics.
Bracket ( )
Division /
Modulus %
Multiply *
Addition +
Subtract -



