===========================================================
Question 1. Write a program to calculate the simple interest using the formula I = PNR/100.
===========================================================
#include<iostream.h>
void main()
{
float P,N,R,I;
cout<<”Enter principle amount : “;
cin>>P;
cout<<”Enter number of years : “;
cin>>N;
cout<<”Enter rate of interest : “;
cin>>R;
I=P*N*R;
Cout<<”Interest : “<<I;
}
===================================================================
Question 2. Input a character and check whether it is a Capital letter, Small letter, a Digit or a Special character.
==========================================================================
#include<iostream.h>
void main()
{
char ch;
ch=getchar();
if(ch >= ’A’ && ch <= ’Z’)
cout<<”Capital letter”;
else
if(ch >= ’a’ && ch <= ’z’)
cout<<”Small letter”;
else
if(ch >= ’0’ && ch <= ’9’)
cout<<”Digit”;
else
cout<<”Special character ”;
}
===========================================================================
Question 3.. Write a program to find the sum, difference, product and quotient of two numbers entered by the user.
The menu options have to follow the below given format:
|
1. Sum 2. Difference 3. Product 4. Quotient
|
|
Enter your choice : |
==========================================================================
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
float a,b,r;
clrscr();
cout<<”\n1. Sum”;
cout<<”\n2. Difference”;
cout<<”\n3. Product”;
cout<<”\n4. Quotient”;
cout<<”\n\nEnter your choice……”;
ch=getchar();
switch(ch)
{
case ‘1’:
cout<<”Enter two numbers : “;
cin>>a>>b;
r=a+b;
cout<<”Sum : “<<r;
break;
case ‘2’:
cout<<”Enter two numbers : “;
cin>>a>>b;
r=a-b;
cout<<”Difference : “<<r;
break;
case ‘3’:
cout<<”Enter two numbers : “;
cin>>a>>b;
r=a*b;
cout<<”Product : “<<r;
break;
case ‘4’:
cout<<”Enter two numbers : “;
cin>>a>>b;
r=a/b;
cout<<”Quotient : “<<r;
break;
default:
cout<<”Invalid choice “;
}
getch();
}
=================================
Question 4.Find the Fibonacci series up to the nth term.
=================================
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int i,n,a,b,s;
clrscr();
cout<<”Enter how many elements : “;
cin>>n;
a=0,b=1;
for(i=1;i<=n;i++)
{
s=a+b;
a=b;
b=s;
cout<<setw(4)<<a;
}
getch();
}
=============================================================
Question 5. . Write a program to print the following series for n rows.
a
a b
a b c
a b c d
. . . nth row. . .
==========================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,l,n;
char ch;
clrscr();
cout<<”Enter how many lines : “;
cin>>n;
l=40;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<” “;
for(j=1,ch=’a’;j<=I;j++,ch++)
cout<<” “<<ch;
l=l-1;
}
getch();
}
==========================================================
Question 6. Find the prime numbers between 1 and 100.
==========================================================
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int i,j,n,p;
clrscr();
int flag;
for(i=1;i<=100;i++)
{
p=i;
flag=1;
for(j=2;j<=p/2;j++)
if((p%j)= = 0)
{
flag=0;
break;
}
if(flag= = 1)
cout<<setw(4)<<p;
}
getch();
}
============================================================================================================
Question 7. Write a program to store n numbers into an array and find the biggest number along with its position.
============================================================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int ar[100],i,n,big;
cout<<”Enter how many elements : “;
cin>>n;
cout<<”Enter the elements \n”;
for(i=0;i<n;i++)
cin>>ar[i];
big=ar[0];
for(i=1;i<n;i++)
if(ar[i]>big)
big=ar[i];
cout<<”Biggest number is : “<<big<<”, and its position is “<<i+1;
getch();
}
======================================================================
Question 8. . Store names of n students into an array and then search for a particular name.
======================================================================
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
int i,n,big;
int flag;
char name[100][25];
char t[25];
cout<<”Enter how many elements : “;
cin>>n;
for(i=0;i<n;i++)
gets(name[i]);
cout<<”Enter a name for search : “;
gets(t);
flag=0;
for(i=0;i<n;i++)
if(strcmp(name[i],t==0)
{
flag=1;
break;
}
if(flag= =1)
cout<<”The given name is found in the position “<<i+1;
else
cout<<”The given name is not found”;
getch();
}
=============================================================================================================
Question 9. Write a program to input m numeric values into an array and n numeric values into another array. Pass these two arrays into a function where they are merged into a single array. The merged array is then returned back to the program and then printed as output. =============================================================================================================
#include<iostream.h>
#include<conio.h>
int* merge(int[],int[],int,int);
void main()
{
int ar1[100],ar2[100];
int i,n,m;
clrscr();
cout<<"Enter how many elements for first array : ";
cin>>n;
cout<<"Enter the elements : ";
for(i=0;i<n;i++)
cin>>ar1[i];
cout<<"Enter how many elements for second array : ";
cin>>m;
cout<<"Enter the elements : ";
for(i=0;i<m;i++)
cin>>ar2[i];
int *arm=merge(ar1,ar2,n,m);
cout<<"\n Merged elements \n";
for(i=0;i<n+m;i++)
cout<<arm[i]<<endl;
getch();
}
int* merge(int a1[],int a2[],int n,int m)
{
int *tr;
tr=new int[100];
for(int i=0;i<n;i++)
tr[i]=a1[i];
for(int j=0;j<m;j++,i++)
tr[i]=a2[j];
return(tr);
}
===================================================================================
Question 7. . Write a program to sort a set of numeric values (using an array) in
a) Ascending order b) Descending order
#include<iostream.h>
#include<conio.h>
void main()
{
int ar[100],i,j,t,n;
clrscr();
cout<<”enter how many elements : “;
cin>>n;
for(i=0;i<n;i++)
cin>>ar[i];
/*ascending order sorting*/
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(ar[i]>ar[j])
{
t=ar[i];
ar[i]=ar[j];
ar[j]=t;
}
Cout<<”Ascending order list \n”;
For(i=0;i<n;i++)
Cout<<ar[i]<<endl;
/*descending order sorting*/
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(ar[i]<ar[j])
{
t=ar[i];
ar[i]=ar[j];
ar[j]=t;
}
cout<<”descending order list \n”;
for(i=0;i<n;i++)
cout<<ar[i]<<endl;
getch();
}
================================================================================
Question 11.Write a program using function overloading to find the area of rectangle/square/ triangle.
area of square = a2 , where a is the side of the square
area of rectangle = l * b, where l is length and b is breadth of the rectangle
area of triangle = square root of {s(s-a)(s-b)(s-c)}where s = (a+b+c)/2 and a,b,c are sides of the triangle.
================================================================================
#include<iostream.h>
#include<conio.h>
#include<math.h>
float area(float a);
float area(float l,float b);
float area(float a,float b,float c);
void main()
{
float a,b,c,r;
clrscr();
cout<<”Enter the value for side of the square : “;
cin>>a;
r=area(a);
cout<<”\nArea of square is : “<<r;
cout<<”Enter the value for length of a rectangle : “;
cin>>l;
cout<<”Enter the value for breadth of a rectangle : “;
cin>>b;
r=area(l,b);
cout<<”\nArea of rectangle is : “<<r;
cout<<”Enter three values for the sides of a rectangle : “;
cin>>a>>b>>b;
r=area(a,b,c);
cout<<”\nArea of triangle is : “<<r;
getch();
}
float area(float a)
{
return(a*a);
}
float area(float l,float b)
{
return(l*b);
}
float area(float a,float b,float c)
{
float s;
s=(a+b+c)/2;
return(sqrt((s*(s-a)*(s-b)*(s-c))));
}
==========================================================================================================
Question 12. Define a structure named emp_rec having the following fields.
Field name Data type
name string of size 20
emp_no integer
salary float
Create an array of the defined structure type and input corresponding values for n records. Print a
tabulated pay slip for each employee along with bonus. Employees drawing salary of Rs 5000/- or more
avail a bonus of ¼ th of the salary and others ½ of the salary.
==========================================================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct emp_rec
{
char name[20];
int emp_no;
float salary;
};
void main()
{
struct emp_rec obj[100];
int i,n;
clrscr();
cout<<”Enter how many records : “;
cin>>n;
for(i=0;i<n;i++)
{
cout<<”Enter name : “;
gets(obj[i].name);
cout<<”Enter employee no : “;
cin>>obj[i].emp_no;
cout<<”Enter salary : “;
cin>>obj[i].salary;
}
cout<<”\nPay slip\n”;
for(i=0;i<n;i++)
{
cout<<endl;
cout<<”\tName : “<<obj[i].name;
cout<<”\Eemployee no : “<<obj[i].emp_no;
cout<<”\tSalary : “<<obj[i].salary;
if(obj[i].salary>=5000)
cout<<”\tBonus : “<<(obj[i].salary/4);
else
cout<<”\tBonus : “<<(obj[i].salary/2);
cout<<endl;
}
getch();
}
==============================================================================
Question 13. Define a class with following specifications:
Class name : Matrix
Purpose : Store member data values, process them and display sum of 2 matrixes
Member Data :
|
Visibility |
Data type |
|
|
private |
integer |
|
|
col |
private |
integer |
|
matrix1 |
private |
integer array |
|
matrix2 |
private |
integer array |
|
sum_matrix |
private |
integer array |
Member functions :
Constructor function (public visibility) - Gets the row and column values
get_matrix (public visibility with return type void) – inputs values into both the matrixes
calc_matrix (public visibility with return type void) – finds sum of 2 matrixes
print_matrix (public visibility with return type void) – displays the sum matrix
Create an object of the class by passing row and column values into the constructor. Then execute the
remaining functions of the program in the required sequence.
#include<iostream.h>
#include<conio.h>
class Matrix
{
int row,col;
int matrix1[10][10];
int matrix2[10][10];
int sum_matrix[10][10];
public:
Matrix(int r,int c)
{
row=r;
col=c;
}
void get_matrix()
{
int i,j;
cout<<”\nEnter values for first matrix\n”;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
cin>>matrix1[i][j];
cout<<”\nEnter values for second matrix\n”;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
cin>>matrix2[i][j];
}
void calc_matrix()
{
int i,j;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
sum_matrix[i][j]=matrix1[i][j]+matrix2[i][j];
}
void print_matrix()
{
int i,j;
cout<<”\n Resultant matrix”;
for(i=0;i<row;i++)
{
cout<<endl;
for(j=0;j<col;j++)
cout<<sum_matrix[i][j]<<”\t”;
}
}
};
void main()
{
Matrix obj(3,3);
clrscr();
obj.get_matrix();
obl.calc_matrix();
obj.print_matrix();
getch();
}
====================================================================
Question 14.
Inherit attributes of a base class named Employee into 2 child classes of the following specifications and hierarchical format.

Base class name : Employee
Purpose : Store and display corresponding data
Member data :
|
Data Name |
Visibility |
Data type |
|
name |
private |
char [20] |
|
emp_no |
private |
char [5] |
|
age |
private |
int |
Member functions: get_value(), print_value()
Class name : Administration
Purpose : Store and display corresponding data
Member Data :
|
Data Name |
Visibility |
Data type |
|
category (HR/Marketing Finance)
|
private |
char [10]
|
Member functions: get_value(), print_value()
Class name : Teaching
Purpose : Store and display corresponding data
Member Data :
|
Data Name |
Visibility |
Data type |
|
specification (Java/C++/VB)
|
private |
char [20] |
Member functions: get_value(), print_value()
Execute the program to input values into object instances of Administrator and Teacher. Then print their specific details.
================================================================================
#include<iostream.h>
#include<conio.h>
class Employee
{
cahr name[20];
cahr emp_no[5];
int age;
public:
void get_value()
{
cout<<”\nEnter name : ”;
cin>>name;
cout<<”\nEmp Number : “;
cin>>emp_no;
cout<<”\nEnter age : “;
cin>>age;
}
void print_value()
{
cout<<”\nName : “<<name;
cout<<”\nEmp No : “<<emp_no;
cout<<”\nAge : “<<age;
}
};
class Administration: public Employee
{
char category[10];
public:
void get_value()
{
Employee::get_value();
cout<<”\nEnter category : “;
cin>>category;
}
void print_data()
{
Employee::print_value();
Cout<<”\nCategory : “<<category;
}
};
class Teaching: public Employee
{
char specification[10];
public:
void get_value()
{
Employee::get_value();
cout<<”\nLanguage specification : “;
cin>> specification;
}
void print_data()
{
Employee::print_value();
cout<<”\n Language specification : “<<specification;
}
};
void main()
{
clrscr();
Administration objadmin;
cout<<”\nEnter the data for administrative officer \n”;
objadmin.get_value();
objadmin.print_value();
Teaching objteacher;
cout<<”\nEnter the data for Teacher \n”;
objteacher.get_value();
objteacher.print_value();
getch();
}
}
===============================================================================
Question 15.
Design
a telephone directory storage and retrieval system for subscriber details.
Use class and objects in file.
===============================================================================
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
class Telephone_diary
{
char phNo[12];
char name[20];
char address[50];
public:
void getdata()
{
cout<<"\nEnter name : ";
gets(name);
cout<<"Enter phone number : ";
cin>>phNo;
cout<<"Enter address : ";
gets(address);
}
int isTrue(char k[])
{
if(strcmp(k,phNo)==0)
return(1);
else
return(0);
}
void printdata()
{
cout<<"\nName : "<<name;
cout<<"\nAddress : "<<address;
cout<<"\nPhone number : "<<phNo;
}
};
void main()
{
fstream iof;
iof.open("TLBOOK.dat",ios::in|ios::out|ios::binary|ios::app);
Telephone_diary obj;
char key[12];
clrscr();
char ch;
cout<<"Do you want to insert a record....";
ch=getche();
while(ch=='Y'||ch=='y')
{
obj.getdata();
iof.write((char*)&obj,sizeof(obj));
cout<<"Do you want to insert another record....";
ch=getche();
}
iof.seekg(0);
cout<<"\nEnter phone number for search : ";
cin>>key;
int flag=0;
while(iof.read((char*)&obj,sizeof(obj)))
{
if(obj.isTrue(key)==1)
{
flag=1;
break;
}
}
if(flag==1)
obj.printdata();
else
cout<<"\nNumber not found ";
getch();
}