Research Area

Ashutosh Dubey

Monday, June 7, 2010

Assignment C++

                    Assignment C++
Ques 1. What is C++?



Ques 2. Explain the structure of an Object Oriented C++ program.


Ques 3. What are the similarities and differences between structure of C and C++?


Ques 4. How does a main() function in C++ differ from main() in c? Why it is necessary to include header file in C++ program?


Ques 5. Define control statement in C++ with example.


Ques 6. Explain Default arguement with example.


Ques 7. Explain Scope Resolution operator with Example.


Ques 8. Explain Inline function with example.


Ques 9. Explain object array with example.


Ques 10. Explain friend function with example.


Ques 11. Explain dynamic allocation in C++ with example.


Ques 12. What is object pointer? How to declare object pointer and access the object using it?


Ques 13. What is nested class. How does it differ from local class?


Ques 14. Illustrate the history of java.


Ques 15. Explain java and its components.


Ques 16. Explain compilation and execution of programs with example.


Ques 17. What are the difference between Java and C++?


Ques 18. Explain JVM with its block diagram.


Ques 19. What are packages in Java. Discuss different level of access protection used in Java.


Ques 20. Explain inheritance with example in Java.


Ques 21. Explain Interfaces with example in Java.


Ques 22.Explain Exception Handling in JAva.










Assignment submission date: 16-06-10(Hard deadline)


Soft copy submission date : 14-06-10


Practical Submission date : 15-06-10

Monday, May 17, 2010

Class and object

1: Write a program to create a class CIRCLE enter the radius of a circle and calculate the Area using two functions Input and Output.
#include<iostream.h>
#include<conio.h>
class circle


{
private:
float rad,area;
public:
void input(){
cout<<"Enter the radius: ";
cin>>rad;
}
void output()
{
area=2*(22.7*rad);
cout<<"Area of circle= "<<area;
}};
void main(){
clrscr();
circle o1;
o1.input();
o1.output();
getch();
}


2. Write a program to create a class STUDENT enter name, age and salary in Input function and print the output in output function.
#include<iostream.h>
#include<conio.h>
class student{
private:
char name[20];
int age,salary;
public:
void input()
{
cout<<"Enter Name,Age & Salary\n";
cin>>name;
cout<<endl;
cin>>age>>salary;
}
void output()
{
cout<<name<<"\n";
cout<<"Age:"<<age;
cout<<"\nSalary:"<<salary;
}};
void main(){
clrscr();
student o1;
o1.input();
o1.output();
getch();
}


3. Write a program to create a class STUDENT enter the name, age and phone no of 3 student in input function and print the output in output function.
#include<iostream.h>
#include<conio.h>
class student2
{private:
char name[20];
int age;
long phone;
public:
void input()
{
cout<<"Enter the Name,age&phone no.\n";
cin>>name;
cout<<endl;
cin>>age>>phone;
cout<<endl;
}
void output()
{
cout<<endl<<name;
cout<<"\nAge:"<<age;
cout<<"\nPhone No."<<phone;
}};


void main()
{
clrscr();
student2 o1[20];
int i;
for(i=0;i<3;i++)
{o1[i].input();
}
for(i=0;i<3;i++)
{
o1[i].output();
}
getch();
}


4. Write a program to create a class SUM enter 3 numbers in Input function, prints the sum in add function and print the average in avg function.


#include<iostream.h>
#include<conio.h>
class sum
{
private:
int a,b,c,total,average;
public:
void input()
{
cout<<"Enter the no's\n";
cin>>a>>b>>c;
}
void add(){
total=a+b+c;
cout<<"\nSum of no's:"<<total;
}
void avg()
{
average=total/3;
cout<<"\nAverage of no's:"<<average;
}};
void main()
{
clrscr();
sum o1;
o1.input();
o1.add();
o1.avg();
getch();
}


5. Write a program to create a class EMPLOYEE enters as many employee name and salary as user wants and print the values.


#include<iostream.h>
#include<conio.h>
class employee
{
private:
char name[20];
int sal;
public:
void input()
{
cout<<"\n\nEnter Employee Name:";
cin>>name;
cout<<"\nEnter the Salary:";
cin>>sal;
}
void output()
{cout<<"\n\nEmployee Name:"<<name;
cout<<"\nSalary ="<<sal;}};
void main()
{
clrscr();
int i,n;
employee o1[100];
cout<<"Enter the No. of Employee's:";
cin>>n;
for(i=0;i<n;i++)
{
o1[i].input();
}
for(i=0;i<n;i++)
{
o1[i].output();
}
getch();}

6. Write a program to create a class MAX input three values in Input function and print the output in output function.



#include<iostream.h>

#include<conio.h>

class max

{

private:
int a,b,c;
public:

void input()

{
cout<<"Enter the no's:\n";
cin>>a>>b>>c;
}
void compare()
{

if(a>b&&a>c)
cout<<"\nA is greater = "<<a;
else if(b>a&&b>c)

cout<<"\nB is greater = "<<b;
else
cout<<"\nC is greater = "<<c;
}};


void main()
{

clrscr();
max o1;

o1.input();
o1.compare();

getch();

}

7. Write a program to create a class FACT enter a number and print the factorial of the no.


#include<iostream.h>
#include<conio.h>

class fact

{
private:
int n,factorial,i;

public:
void input()

{
cout<<"Enter the no.:";
cin>>n;

}
void cal(){
factorial=1;
for(i=1;i<=n;i++)

factorial=factorial*i;

cout<<"Factorial of no. is="<<factorial;

}};

void main()

{

clrscr();

fact o1;

o1.input();
o1.cal();
getch();

}



8: Write a program to create a class FACTORIAL enter a number if the number is less than 5 print the factorial of the number if it is greater than 5 then print the value from 1 to that number(e.g1,2,3……..8).Use appropriate function required.


#include<iostream.h>
#include<conio.h>

class fact
{
private:

int n,factorial,i;

public:

void input()

{
cout<<"Enter the no.:";

cin>>n;
}

void cal()

{

if(n<=5)

{

factorial=1;

for(i=1;i<=n;i++)

factorial=factorial*i;

cout<<"Factorial of no. is="<<factorial;

}
else

{

for(i=1;i<=n;i++)

cout<<i;

}}};
void main()
{

clrscr();

fact o1;

o1.input();
o1.cal();
getch();
}

9: Write a program to create a class NUM enter a number, if the number is less than 10 print the table of the number otherwise check it is even or odd.
#include<iostream.h>

#include<conio.h>

class num

{
int no,tab ;
public:
void input()

{

cout<<"enter the number";
cin>>no;
}
void cal()
{

int i;
if(no<10)

{
for(i=1;i<=10;i++)
{
tab=no*i;
cout<<no<<"*"<<i<<"="<<tab<<"\n";

}
}
else

{
if(no%2==0)
{
cout<<"the no is even";

}
else
cout<<"no is odd";

}}

};
void main()

{
num o;
clrscr();

o.input();

o.cal();
getch();
}


10: Write a program to create a class SORTING ,create an integer Array accept 10 values in input function sort them and display in ascending order in output function.[use BUUBLE or SELECTION Sort].


#include<iostream.h>

#include<conio.h>

class sorting

{

int a[10],t,n;
public:
void input();
void output();
};

void sorting::input()
{cout<<"Enter the range of array:";
cin>>n;
cout<<"Enter the array\n";

for(int j=0;j<n;j++)

cin>>a[j];

}
void sorting::output()
{
for(int i=0;i<n-1;i++)

{for(int j=i;j<n-i;j++)

if(a[j]>a[j+1])
{

t=a[j];
a[j]= a[j+1];
a[j+1]=t;}}}
cout<<"Array in increasing order (using selection sort)\n";
for(int y=0;y<n;y++)
cout<<a[y]<<"\t";
}
void main()

{ clrscr();

cout<"\t\t\t vijay verma";

sorting s;
s.input();
s. output();
getch();
}


By
Vijay  Verma
CSE
TITR Bhopal

Tuesday, May 11, 2010

Array IIIrd Tutorial

11.WAP to accept a 2D array of 3*3 again accepts a number and prints its location in the array.


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[3][3],n,i,j,c=0;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>x[i][j];
}
cout<<"The matrix is"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<x[i][j]<<" ";
cout<<endl;
}
cout<<"Enter the element"<<endl;
cin>>n;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(x[i][j]==n)
cout<<"The location is"<<i<<j;
else
c++;}}
if(c==9)
cout<<"The element not found";
getch();
}
12.WAP to perform addition of two matrix.
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int x[3][3],n[3][3],i,j,c[3][3];
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the matrix 1 :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>x[i][j];
}
cout<<"Enter the matrix 2 :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>n[i][j];
}
cout<<"sum of matrix are"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=x[i][j]+n[i][j];
cout<<c[i][j]<<" ";
}
cout<<endl;}
getch();
}

13.WAP to perform transposing of a matrix.




#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

int x[2][2],n[2][2],i,j;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the elements"<<endl;

for(i=0;i<2;i++)

{

for(j=0;j<2;j++)

{

cin>>x[i][j];

n[j][i]=x[i][j];

}

}

cout<<"The matrix is"<<endl;

for(i=0;i<2;i++)

{

for(j=0;j<2;j++)

cout<<x[i][j]<<" ";

cout<<endl;

}

cout<<"The elements after transpose"<<endl;

for(i=0;i<2;i++)

{

for(j=0;j<2;j++)

cout<<n[i][j]<<" ";

cout<<endl;

}

getch();

}

14.WAP to perform addition of diagonal element.



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int x[2][2],i,j,s=0;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the elements"<<endl;

for(i=0;i<2;i++)

{

for(j=0;j<2;j++)

{

cin>>x[i][j];

if(i==j)

s+=x[i][j];

}

}

cout<<"The matrix is"<<endl;

for(i=0;i<2;i++)

{

for(j=0;j<2;j++)

cout<<x[i][j]<<" ";

cout<<endl;

}



cout<<"The sum of diagonal elements is"<<s;

getch();

}

15. WAP to accept 5 names from the user and greet him with welcome message.



#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char a[5][10],i,j;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the names"<<endl;

for(i=0;i<5;i++)

gets(a[i]);

for(i=0;i<5;i++)

{

Cout<<endl<<endl<<endl;

cout<<"Welcome ";

puts(a[i]);

}

getch();

}

By
Laxman
CSE
TITR Bhopal

Array IInd Tutorial

6. WAP to implement BUBBLE SORT algorithm.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a[100],i,j,temp,n;
cout<<"Enter the no. of elements in the array"<<endl;
cin>>n;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"Sorted list is\n";
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
getch();
}

7. WAP to implement SELECTION SORT algorithm.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a[100],i,j,temp,n;
cout<<"Enter the no. of elements in the array"<<endl;
cin>>n;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{

if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}}}
cout<<"Sorted list is\n";
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
getch();
}
8. WAP to accept a string and print the character separately line by line.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char x[10],i,j,t;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the string :\n";
cin>>x;
cout<<"verticl string:\n";
for(i=0;x[i]!='\0';i++)
cout<<x[i]<<endl;
getch();
}
9.WAP   accept a string and convert uppercase to lowercase and lowercase to uppercase.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char x[10],i,j,t;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the string "<<endl;
cin>>x;
cout<<"After changing:"<<endl;
for(i=0;x[i]!='\0';i++)
{
if(x[i]>=65&&x[i]<=90)
x[i]+=32;
else if(x[i]>=97&&x[i]<=122)
x[i]-=32;
}
for(i=0;x[i]!='\0';i++)
cout<<x[i];
getch();
}

10. WAP to declare a 2D array of 3*4.accept the value from the user and print them on the screen.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[3][4],i,j;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the elements"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
cin>>x[i][j];
}
cout<<"the matrix is"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
cout<<x[i][j]<<" ";
cout<<endl;
}
getch();

}

Array Ist tutorial

1.WAP to accept rollno of 5 students and display them.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double a[5],i;
cout<<"\t\t\t\t\tLaxman"<<endl;
cout<<"Enter the Roll No4."<<endl;
for(i=0;i<=4;i++){
cin>>a[i];
}
for(i=0;i<=4;i++)
{
cout<<a[i]<<endl;
}
getch();}
2. WAP to accept 5 no and reverse them.
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int a[5],i;
cout<<"\t\t\t\tLaxman"<<endl;
cout<<"Enter the No."<<endl;
for(i=0;i<=4;i++)
{
cin>>a[i];
}
cout<<"Reverse of No."<<endl;
for(i=4;i>=0;i--)
{
cout<<a[i]<<endl;
}
getch();
}

3. WAP to accept 10 integer and find the sum of all even and odd numbers separately.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a[10],i,sume=0,sumo=0;
cout<<"Enter the no."<<endl;
for(i=0;i<=9;i++)
{
cin>>a[i];
}
for(i=0;i<=9;i++)
{
if(a[i]%2==0)
sume=sume+a[i];
else
sumo=sumo+a[i];
}
cout<<"Sum of Even No."<<sume<<endl;
cout<<"Sum of Odd No."<<sumo;
getch();
}
4.WAP to accept 10 element and identify the max and min no in the array also identify the position as well.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a[10],i,max=0,min=0,m,n;
cout<<"Enter the no."<<endl;
for(i=0;i<=9;i++)
{
cin>>a[i];
}
for(i=0;i<=9;i++)
{
if(max<a[i])
{
max=a[i];
m=i;
}
else if(min>a[i])
{
min=a[i];
n=i;
}}
cout<<"Maximum no.is"<<max;
cout<<"\t& Position of max.is"<<m+1<<endl;
cout<<"Minimum no.is"<<min;
cout<<"\t& Position of min.is"<<n+1;
getch();
}
5. WAP to accept the amount of sale made for each day in a week and calculate the average of these values.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" \t\t\t\tLaxman"<<endl;
int a[7],i,j=0;
cout<<"Enter the sales"<<endl;
for(i=0;i<7;i++)
{
cout<<"Day "<<i+1<<"\t\t";
cin>>a[i];
j+=a[i];
}
cout<<"The sales for week"<<j;

getch();

}

By
Laxman
CSE
TITR Bhopal

Wednesday, May 5, 2010

Class and Object Assignment for Lab

Class and Object Assignment for Lab


1. Write a program to create a class CIRCLE enter the radius of a circle and calculate the Area using two functions Input and Output.


2. Write a program to create a class STUDENT enter name, age and salary in Input function and print the output in output function.


3. Write a program to create a class STUDENT enter the name, age and phone no of 3 student in input function and print the output in output function.


4. Write a program to create a class SUM enter 3 numbers in Input function, print the sum in add function and print the average in avg function.


5. Write a program to create a class EMPLOYEE enters as many employee name and salary as user wants and print the values.


6. Write a program to create a class MAX input three values in Input function and print the output in output function


7. Write a program to create a class FACT enter a number and print the factorial of the no.


8. Write a program to create a class FACTORIAL enter a number if the number is less than 5 print the factorial of the number if it is greater than 5 then print the value from 1 to that number(e.g1,2,3……..8).Use appropriate function required.


9. Write a program to create a class NUM enter a number, if the number is less than 10 print the table of the number otherwise check it is even or odd.


10. Write a program to create a class SORTING ,create an integer Array accept 10 values in input function sort them and display in ascending order in output function.[use BUUBLE or SELECTION Sort].

Saturday, April 17, 2010

Array Assignment

1.WAP to accept rollno of 5 students and display them.
2.WAP to accept 5 no and reverse them.
3.WAP to accep 10 integer and find the sum of all even and odd numbers separately.
4.WAP to accept 10 element and identify the max and min no in the array also identify the position as well.
5.WAP to accept the amount of sale made for each day in a week and calculate the average of these values.
6.WAP to implement BUBBLE SORT algorithm.
7.WAP to implement SELECTION SORTalgorithm.
8.WAP to accept a string and print the character separately line by line.
9.WAP to accept a string  and convert uppercase to lowercase and lowercase to uppercase.
10.WAP to declare a 2D array of 3*4.accept the value from the user and print them on the screen.
11.WAP to accept  a 2D array of 3*3 again accept a number and print its location in the array.
12.WAP to perform addition of two matrix.
13.WAP to perform multiplcation of two matrix.
14.WAP to perform transposing of a matrix.
15.WAP to perform addition of diagonal element.
16.WAP to perform sorting of a 3*3 matrix.
17.WAP to accept 5 names from the user and greet him with welcome message.

Java Assignment

1. In a company 10% of the salary is deducted for income tax and 8% for provident fund if the salary is greater than 6000 but if the salary is less than or equal to 6000 then 8% is deducted for income tax and 5% is deducted for provident fund. Write a program to accept the basic salary from the user and calculate the net salary.



2. Write a program to accept marks in three subjects from the user, calculate the percentage and print the grade accordingly.


3. WAP to check whether the number is even or odd.


4. WAP to accept two numbers from the user and check that the first no is divisible by the second number.


5. WAP to accept three numbers and print the maximum value.


6. WAP to check the type of character entered from the keyboard.


7. WAP to simulate the calculator to perform the following operation on two numbers.


8. WAP to find the area of a circle, area of rectangle and area of triangle according to the user choice by switch statement.


9. WAP to check whether the year is leap year or not.


10. WAP to enter base and index value and calculate the power of two no.


11. WAP to print the average of three no given by user till user wants.


12. WAP to accep a series of positive numbers terminated by 0 and then print the smallest and the largest no in sequence.
13. WAP to generate all prime from 1 to 300.


14. WAP to generate FLOYD’s triangle up to 5 rows.


15. WAP to check whether the number is prime or not.



Thursday, April 15, 2010

Conditional Statement and Loop

1.Write a program to enter a no. and check whether the no. is even or odd?


#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a;

cout<<" Laxman"<<endl;

cout<<"enter a"<<endl;

cin>>a;

if(a%2==0)

cout<<"even";

else

cout<<"odd";

getch();

}

2. Write a program that in a company 10% of salary is deducted for income tax and 8% forprovident fund if the salary is greater than 6000 but if the salary isless than or equal to 6000 then 8% is deducted for income tax and 5% isdeducted for provident fund. Write a program to accept the basic salaryfrom the user and calculate the net salary?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

float sal,tax=0;

cout<<"Enter salary"<<endl;

cin>>sal;

if(sal>6000)

{

tax=(sal*0.1)+(sal*0.08);

}

else

{

tax=(sal*0.08)+(sal*0.05);

}

cout<<sal-tax;

getch();

}

3.Write a program to accept marks in three subjects from the user, calculate the percentage and print the grade accordingly?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" Laxman"<<endl;

int cso,oops,ada,sum=0;

cout<<"enter the marks"<<endl;

cin>>cso>>oops>>ada;

sum=(cso+oops+ada)/3;

if(sum>90)

{

cout<<"Grade=A";

}

else if(sum>80)

{

cout<<"Grade=B";

}

else if(sum>70)

{

cout<<"Grade=C";

}

else

{

cout<<"Fail";

}

getch();

}

4.Write a program to accept three numbers and print the maximum value?



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" Laxman"<<endl;

int a,b,c;

cout<<"enter the no's";

cin>>a>>b>>c;

if(a>b&&a>c)

cout<<"a is greater";

else if(b>c&&b>a)

cout<<"b is greater";

else

cout<<"c is greater";

getch();

}

5.Write a program to simulate the calculator to perform the following operation on two numbers.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b;

char c;

cout<<" Laxman "<<endl;

cout<<"enter the no";

cin>>a>>b;

cout<<"enter the operation";

cin>>c;

switch(c)

{

case '+':

{

b=a+b;

break;

}

case '-':

{

b=a-b;

break;

}

case '*':

{

b=a*b;

break;

}

case '/':

{

b=a/b;

break;

}

default:

cout<<"wrong choice";

}

cout<<b;

getch();

}

6.Write a program to find the area of a circle, area of rectangle and area of triangle according to the user choice by switch statement.



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float a,b,d;

char c;

cout<<" Laxman "<<endl;

cout<<"enter the operation"<<endl;

cout<<”c=circle,r=rectangle,t=triangle”;

cin>>c;

switch(c)

{

case 'c':

{

cout<<"enter the radius";

cin>>a;

d=(2*3.14)*a;

cout<<d;

break;

}

case 'r':

{

cout<<"enter the length and breadth"<<endl;

cin>>a>>b;

d=a*b;

cout<<d;

break;

}

case 't':

{

cout<<"enter the breadth & height";

cin>>a>>b;

d=(a+b)/2;

cout<<d;

break;

}

default:

cout<<"wrong choice";

}

getch();

}

7.Write a progarm to accept a series of positive numbers terminated by 0 and then print the smallest and the largest no in sequence.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n=1,max=0,min=0;

cout<<" Laxman "<<endl;

for( ;n!=0; )

{

cout<<"enter the no.";

cin>>n;

if(n>max)

{

max=n;

}else if(n<min)

{

min=n;

}

}

cout<<max<<endl<<min;

getch();

}

8.Write a program to accept two numbers from the user and check that the first no is divisible by the second number.



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int a,b;

cout<<"enter no."<<endl;

cin>>a>>b;

if(a%b==0)

cout<<"No."<<a<<"is divisible by"<<b;

else

cout<<"No. is not divisible";

getch();

}

9.Write a program to check whether the year is leap year or not.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int y;

cout<<"Enter Year"<<endl;

cin>>y;

if(y%4==0)

cout<<"Leap Year";

else

cout<<"Not Leap Year";

getch();

}

10.Write a progarm to print the average of three no given by user till user wants.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int a,b,c,avg;

char d;

do

{

cout<<"Enter the no's"<<endl;

cin>>a>>b>>c;

avg=(a+b+c)/3;

cout<<"average is"<<avg;

cout<<"\nwant to continue";

cin>>d;

}

while(d=='y'

d=='Y');

getch();

}

11.Write a program to generate all prime from 1 to 300.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int p,i,j;

cout<<"prime no. are as follows"<<endl;

for(i=1;i<=300;i++)

{

p=1;

for(j=2;j<=i;j++)

{

if(i==j)

continue;

else if(i%j==0)

p=0;

}

if(p)

cout<<i<<"\t";

}

getch();

}

12.Write a program to generate FLOYD’s triangle up to 5 rows.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int a=1,i,j;

for(i=0;i<=5;i++)

{

for(j=0;j<i;j++)

{

cout<<a<<" ";

a=a+1;

}

cout<<"\n";

}

getch();

}



13.Write a program to enter base and index value and calculate the power of two no.

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int a,b,p=0;

cout<<"Enter the no."<<endl;

cin>>a>>b;

p=pow(a,b);

cout<<"Power ="<<p;

getch();



}

Without using math.h

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<" \t\t\t\tLaxman"<<endl;

int a,b,p,i;

cout<<"Enter the Base";

cin>>a;

cout<<"\nEnter the power";

cin>>b;

p=a;

for(i=1;i<b;i++)

{

p=p*a;

}

cout<<p;

getch();



}

14.Write a program to check whether the number is prime or not.

#include<iostream.h>

#include<conio.h>

void main()

{

int a,p=1,j;

cout<<"\t\t\t\tLaxman"<<endl;

cout<<"Enter the no.";

cin>>a;

for(j=2;j<a;j++)

{

if(a%j==0)

{

p=2;

}

}

if(p==1)

cout<<"No. is Prime";

else

cout<<"No. is not Prime";

getch();

}



15.Write a program to check the type of character entered from the keyboard.



#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<"\t\t\t\t\tLaxman"<<endl;

char c;

cout<<"Enter the character:\n";

cin>>c;

if(c>='a'&&c<='z')

cout<<"Lower Case Element";

else if(c>='A'&&c<='Z')

cout<<"Upper Case Element";

else if(c>='0'&&c<='9')

cout<<"Digit Character";

else

cout<<"Special Character";

getch();

}


By-Laxman
CSE
TITR Bhopal

Saturday, April 3, 2010

Basic Programs in C++

1. Write a program to print a welcome msg ": welcome in c++"?


#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"welcome in c++";

getch();

}

2. Write a program to enter three numbers to print the sum, multiplication, division?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,sum,div,pdt;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter two no.";

cin>>a>>b;

cout<<"sum"<<a+b;

cout<<"\ndiv"<<a/b;

cout<<"\nmul

"<<a*b;

getch();

}

3. Write a program to swap two numbers using third variable?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a &b";

cin>>a>>b;

c=a;

a=b;

b=c;

cout<<a<<"\n"<<b;

getch();

}

4. Write a program to swap two numbers without using third variable?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a &b";

cin>>a>>b;

a=a+b;

b=a-b;

a=a-b;

cout<<a<<"\n"<<b;

getch();

}



5. Write a program to enter the radius of the circle and find the area of the circle?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float r,area;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter radius";

cin>>r;

area=3.142*r*r;

cout<<"area"<<area;

getch();

}

6. Write a program enters the three sides of triangles and find area of triangle by hero’s formula?



#include<iostream.H>

#include<conio.h>

#include<math.h>

void main()

{

clrscr();

float a,b,c,s,t;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three sides of the triangle";

cin>>a>>b>>c;

s=(a+b+c)/2;

cout<<s;

t=sqrt(s*(s-a)*(s-b)*(s-c));

cout<<t;

getch();

}

7. Write a program for beggars’ associations where we have four cups first cup accept 50 rps 2nd cup accept 100 rs 3rd cup accept 500rps and 4rth cups accept 1000 rs enter the amount whatever the user wants print total number of rupees and the total amount?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int A,B,C,D,TOTAL,MONEY;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"ENTER THE NOTES IN A";

cin>>A;

cout<<"ENTER THE NOTES IN B";

cin>>B;

cout<<"ENTER THE NOTES IN C";

cin>>C;

cout<<"ENTER THE NOTES IN D";

cin>>D;

TOTAL=A+B+C+D;

MONEY=(A*50)+(B*100)+(C*500)+(D*1000);

cout<<"TOTAL NOTES IN CUPS ARE ="<<TOTAL<<endl;

cout<<"TOTAL MONEY IN CUPS ="<<MONEY;

getch();

}



8. Write a program to find the simple interest where p, r, t is given by the user?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int p,r,t,si;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the principle rate and time"<<endl;

cin>>p>>r>>t;

si=(p*r*t)/100;

cout<<"simple interest="<<si;

getch();

}



9. Write a program find the area of a triangle where base and height is input by the user?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int h,b,area;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the height and base"<<endl;

cin>>h>>b;

area=(h*b)/2 ;

cout<<area;

getch();

}

10. Write a program to enter three digit numbers and print the sum of those digits?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d,sum;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three digit number"<<endl;

cin>>a;

b=a/100;

c=(a%100)/10;

d=a%10;

sum=b+c+d;

cout<<sum;

getch();

}

11. Write a program to enter the three digit number and print its reverse order?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d,rev;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter the three digit number"<<endl;

cin>>a;

b=a/100;

c=(a%100)/10;

d=a%10;

rev=d*100+c*10+b;

cout<<rev;

getch();

}

12. Write a program to enter the three digit number and find the sum of first and last digit ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d;

cout<<"\t\t\t\t\tgaurav agarwal"<<endl;

cout<<"enter a three digit number"<<endl;

cin>>a;

b=a/100;

c=a%10;

d=c+b;

cout<<d;

getch();

}





Submitted By

Gaurav Agarwal

CSE Iv Sem.

TITR Bhopal