You are on page 1of 74

COMPUTER PRACTICAL

2015-16
AISSCE EXAMINATION

SUBMITTED BY:
Name:
Boards Roll No:
Class: XII
School:
Acknowledgement

I am extremely thankful to the Principal for her


encouragement and for all the facilities that she provided
for this project work and Computer teachers XYZ, of ABC
for giving me the opportunity for this project work.

I am very thankful to them for their advice and guidance


during the course of my project work.

Signature of Candidate
Certificate

This is to certify that X, student of class XII of ABC School


has completed the Computer Practical during the
academic year 2015-2016 towards partial fulfillment of
credit for the Computer Project of AISSCE 2016 and
submitted the satisfactory report as completed in the
following pages under my supervision and does not
involve in plagiarism of any kind. The reference taken in
making this project has been declared at the end of this
report.

___________________
Teacher’s Signature
Index
Sl. Date Programs Page Signature Remarks
no no.
Write constructor and destructor definition
1 21/8/15 (for a class) that should display the object 1
number being created/destroyed of this
type
Program to illustrate access control of
2 28/8/15 inherited members in the privately derived 3
class
Calculating Sum and Product of two
3 5/9/15 6
numbers using Inheritance

Function Overloading to calculate the area


4 12/9/15 9
of a circle, rectangle and triangle

Program to create a text file and then create


another text file by converting each line of
5 19/9/15 12
the newly created text file into an uppercase
string

6 26/9/15 Program to append data in a file 15

7 29/9/15 Bubble Sort 18

8 1/10/15 Program to demonstrate Queue using Array 20

9 4/10/15 Pushing and Popping in Stack-Array 25

10 7/10/15 Insertion in Queue 29

11 15/10/15 Deletion in Array-Queue 32

Addition and deletion of new books using


12 17/10/15 36
linked list

Program to demonstrate the sum of two


13 19/10/15 40
matrices

14 25/10/15 Program to find the length of the string 43

Program to find the occurrence of character


15 27/10/15 46
in the string
A program to illustrate Multiple Inheritance
16 31/10/15 49

Program to create two arrays to store roll


17 2/11/15 numbers and marks of desired students, 53
whose number would be known at run time

Function to display the elements which lie


18 5/11/15 55
on middle of row and column

Program to check whether the string is


19 10/11/15 58
palindrome or not

Program to check whether the two strings


20 21/11/15 61
are equal or not

Program to illustrate working of default


21 25/11/15 arguments. Calculate interest amount 64
making use of default arguments

22 1/12/15 SQL Program for TABLE: STUDENT 66

K-Map (SOP)
23 7/12/15 70

K-Map (POS)
24 7/12/15 71
Write constructor and destructor definition (for a class) that should
display the object number being created/destroyed of this type:

#include<iostream.h>
#include<conio.h>
class A
{
static int count;
public:
A()
{
count++;
cout<<”Object”<<count<<”being Created\n”;
}
~A()
{
cout<<”Object”<<count<<”being Destroyed\n”;
count--;
}
};
int A::count=0;
void main()
{
void f1();
A ob1,ob2;
f1();
{
A ob3;
}
getch();
}
void f1()
{
A ob4;
Output of the program for writing constructor and destructor
definition (for a class) that should display the object number being
created/destroyed of this type:
Program to illustrate access control of inherited members in the
privately derived class:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
const int LEN=25;
class Employee
{
private:
char name[LEN];
unsigned long enumb;
public:
void getdata()
{
cout<<”Enter Name=”;
gets(name);
cout<<”Enter Employee Number:”;
cin>>enumb;
}
void putdata()
{
cout<<”Name:”<<name<<”\t”;
cout<<”Emp. Number:”<<enumb<<”\t”;
cout<<”Basic Salary:”<<basic;
}
protected:
float basic;
void getbasic()
{
cout<<”Enter Basic:”;
cin>>basic;
}
};
class Manager:public Employee
{
private:
char title[LEN];
public:
void getdata()
{
Employee::getdata();
getbasic();
cout<<”Enter Title:”;
gets(title);
cout<<”\n”;
}
void putdata()
{
Employee::putdata();
cout<<”\tTitle:”<<title<<”\n”;
}
};
void main()
{
Manager m1,m2;
cout<<”Manager1\n”;
m1.getdata();
cout<<”Manager2\n”;
m2.getdata();
cout<<”\t\tManager 1 Details\n”;
m1.putdata();
cout<<”\t\tManager2 Details\n”;
m2.putdata();
getch();
}
Output of the program to illustrate access control of inherited
members in the privately derived class:
Calculating Sum and Product of two numbers using Inheritance:

#include<iostream.h>
#include<conio.h>
class Sum
[
public:
int a,b,c;
void getdata();
void calc();
void show();
};
void Sum::getdata()
{
cout<<”Enter two numbers=”;
cin>>a>>b;
}
void Sum::calc()
{
c=a+b;
}
void Sum::show()
{
cout<<”Sum=”<<c;
}
class SumProduct : public Sum
{
public:
int p;
void pro();
void showp();
};
void SumProduct::pro()
{
p=a*b;
}
void SumProduct::showp()
{
cout<<”\nProduct=”<<p;
}
void main()
{
SumProduct s;
s.getdata();
s.calc();
s.pro();
s.show();
s.showp();
getch();
}
Output of the program for calculating Sum and Product of two
numbers using Inheritance
Function Overloading to calculate the area of a circle, rectangle
and triangle:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void area(float r)
{
float area;
cout<<"\nArea:"<<(3.14*r*r);
}
void area(float l,float b)
{
float area ;
cout<<"\nArea:"<<l*b;
}
void area(float x,float y,float z)
{
float s;
s=(x+y+z)/2;
cout<<"\nArea:"<<sqrt(s*s-x*s-y*s-z);
}
void main()
{
clrscr();
int opt,x,y,z,l,b,r;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"\nMENU\n\n1.Area of circle\n2.Area of Rectangle\n3.Area of
Triangle";
cout<<"\nEnter your Option:";
cin>>opt;
switch(opt)
{
case 1:cout<<"\nEnter radius of the circle:";
cin>>r;
area(r);
break;
case 2:cout<<"\nEnter the length and breadth of the rectangle:";
cin>>l>>b;
area(l,b);
break;
case 3:cout<<"\nEnter side 1:";
cin>>x;
cout<<"\nEnter side 2:";
cin>>y;
cout<<"\nEnter side 3:";
cin>>z;
area(x,y,z);
break;
default:cout<<"Wrong Option!!";
}
cout<<"\nDo you wnat to continue?(Y/N):";
cin>>ch;
}
getch();
}
Output of the program for Function Overloading to calculate the
area of a circle, rectangle and triangle:
Program to create a text file and then create another text file by
converting each line of the newly created text file into an
uppercase string:

# include <fstream.h>
# include <stdio.h>
# include <conio.h>
# include <ctype.h>
void main()
{
char fname[20];
char str[80], ch = 'y';
int count;
cout << "\n Enter the name of the file ";
gets(fname);
ofstream oldfile(fname);
while ((ch == 'Y') || (ch == 'y'))
{
cout << "\n Enter a line of text ";
gets(str);
oldfile << str << "\n";
cout << "\n Want to add more lines (Y/N) ";
cin >> ch;
}
oldfile.close();
// Copy each line after converting into the upper case
ofstream temp("temp.dat");
ifstream newfile(fname);
while (newfile)
{
newfile.get(ch);
if (ch != '\n')
ch = toupper(ch);
temp.put(ch);
}
newfile.close();
temp.close();
clrscr();
cout<< "\n The output file is \n";
ifstream yfile("temp.dat");
count = 0;
while (!yfile.eof())
{
yfile.getline(str,80);
cout << str << "\n";
count++;
// Check whether the number of lines on the display exceed 22 or
not
if ((count % 22) == 0)
{
cout << "\n Press any key to continue ";
cin >> ch;
}
}
yfile.close();
}
Output of the program to create a text file and then create another text file
by converting each line of the newly created text file into an uppercase
string:
Program to append data in a file:

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class stu
{
int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{
cout<<”Roll no:”;
cin>>rollno;
cout<<”Name:”;
cin>>name;
cout<<”Class:”;
cin>>Class;
cout<<”Marks:”;
cin>>marks;
if(marks>=75)
grade=’A’;
else if(marks>=60)
grade=’B’;
else if(marks>=50)
grade=’C’;
else if(marks>=40)
grade=’D’;
else
grade=’E’;
}
void putdata()
{
cout<<name<<”, roll:”<<rollno<<”has”<<marks<<”% marks
and”<<grade<<”grade.”<<endl;
}
int getrno()
{
Return rollno;
}
}s1;
void main()
{
clrscr();
ofstream of(“stu.dat”,ios::app);
char ans=’y’;
while(ans==’y’)
{
s1.getdata();
of.write((char*) & s1,sizeof(s1));
cout<<”Record added to file\n”;
cout<<”Want to enter more records(y/n)…?”;
cin>>ans;
}
of.close();
getch();
}
Output of the program to append data in a file:
Bubble Sort:

#include<iostream.h>
#include<conio.h>
void main()
{
int i,a[10],t,j;
clrscr();
cout<<"Enter 10 elements=";
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(i=1;i<10;i++)
{
for(j=0;j<10-i;j++)
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<"Sorted array in descending order=";
for(i=0;i<10;i++)
{
cout<<a[i]<<"\n";
}
getch();
}
Output of Bubble Sort:
Program to demonstrate Queue using Array:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 5
int rear=-1, front=-1;
void main()
{
void insert(int q[], int s, int num);
void delete_Q(int q[]);
void show(int q[]);
int que[SIZE],ch,x;
while(1)
{
cout<<”\nPress:\n1. Insert rear\n2. Delete front\n3. Show\n4. Exit\n”;
cout<<”Enter choice=”;
cin>>ch;
switch(ch)
{
case 1: cout<<”Enter elements to be inserted=”;
cin>>x;
insert(que,SIZE,x);
break;
case 2: delete_Q(que);
break;
case 3: show(que);
break;
case 4: exit(0);
}
}
}
void insert(int q[],int s, int num)
{
if(rear==-1)
{
front=rear=0;
q[rear]=num;
}
else if(rear==s-1)
{
cout<<”Queue is full”;
}
else
{
rear++;
q[rear]=num;
}
}
void delete_Q(int q[])
{
if(front==-1)
{
cout<<”Queue is empty”;
}
else
{
cout<<”Elements deleted=”<<q[front];
if(front==rear)
{
front=rear=-1;
}
else
{
front=front+1;
}
}
}
void show(int q[])
{
int i;
if(front==-1)
{
cout<<”Queue is empty”;
}
else
{
cout<<”Elements in the queue are=”;
for(i=front;i<=rear;i++)
{
cout<<”q[i]<<” “;
}
}
}
Output of the program to demonstrate Queue using Array:
Output of the program to demonstrate Queue using Array:
Pushing and Popping in Stack-Array:

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<process.h>
struct Node
{
int info;
Node*next;
}
*top,*newptr,*save,*ptr;
Node*Create_New_Node(int);
void Push(Node*);
void Display(Node*);
void Pop();
void main()
{
top=NULL;
int inf;
char ch=’y’;
while(ch==’y’ || ch==’Y’)
{
cout<<”\nEnter information for the new node…”;
cin>>inf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
{
cout<<”\nCannot create new node!!! Aborting!!\n”;
system(“pause”);
exit(1);
}
Push(newptr);
cout<<”\n Press Y to enter more nodes, N to exit…”;
cin>>ch;
}
system(“cls”);
do
{
cout<<”\n The Stack now is: \n”;
Display(top);
system(“pause”);
cout<<”Want to pop an element?(y/n)…”;
cin>>ch;
if(ch==’Y’ || ch==’y’)
Pop();
}
while(ch==’y’ || ch==’Y’);
getch();
}
Node*Create_New_Node(int n)
{
ptr=new Node;
ptr -> info=n;
ptr -> next=NULL;
return ptr;
}
void Push(node*np)
{
If(top=NULL)
top=np;
else
{
save=top;
top=np;
np -> next=save;
}
}
void Pop()
{
If(top==NULL)
cout<<”UNDERFLOW !!!\n”;
else
{
ptr=top;
top=top -> next;
delete ptr;
}
}
void Display(Node*np)
{
while(np!=NULL)
{
cout<<np -> info<<”->”;
np=np -> next;
}
cout<<”!!!\n”;
}
Output of the program for Pushing and Popping in Stack-Array:
Insertion in Queue:

#include<iostream.h>
#include<stdlib.h>
#include<process.h>

int Insert_in_Q(int [],int);


void Display(int [], int, int);
const int size=50;
int Queue[size], front=-1, rear=-1;
void main()
{
int Item,res;
char ch='y';
clrscr();
while(ch=='y' || ch=='Y')
{
cout<<"\nEnter item for insertion:";
cin>>Item;
res=Insert_in_Q(Queue,Item);
if(res==-1)
{
cout<<"OVERFLOW!!! Aborting!! \n";
exit(1);
}
cout<<"Now the Queue(Front.........to.........Rear)is:\n";
Display(Queue,front,rear);
cout<<"Want to insert more elements?(y/n)...";
cin>>ch;
}
getch();
}
int Insert_in_Q(int Queue[],int ele)
{
if(rear==size-1)
return-1;
else if(rear==-1)
{
front=rear=0;
Queue[rear]=ele;
}
else
{
rear++;
Queue[rear]=ele;
}
getch();
}

void Display(int Queue[], int front, int rear)


{
if(front==-1)
return;
for(int i=front;i<rear;i++)
cout<<Queue[i]<<"<-\t";
cout<<Queue[rear]<<endl;
}
Output of the program for Insertion in Queue:
Deletion in Array-Queue:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
int Remove(int []);
int Insert(int [],int);
void Display(int [],int,int);
const int size=50;
int Queue[size],front=-1,rear=-1;
void main()
{
int Item,res;
char ch='y';
clrscr();
while(ch=='y' || ch=='Y')
{
cout<<"\nEnter ITEM for insertion:";
cin>>Item;
res=Insert(Queue,Item);
if(res==-1)
{
cout<<"OVERFLOW!!! Aborting!! \n";
exit(1);
}
cout<<"\n Now the Queue(Front...to...Rear)is:\n";
Display(Queue,front,rear);
cout<<"\n Want to insert more elements?(y/n)...";
cin>>ch;
}
cout<<"Now the deletion of elements begin...(Press y for yes and n for no)\n";
cin>>ch;
while(ch=='y' || ch=='Y')
{
res=Remove(Queue);
if(res==-1)
{
cout<<"UNDERFLOW!!! Aborting!! \n";
exit(1);
}
else
{
cout<<"\nElements deleted is:"<<res<<endl;
cout<<"Now the Queue(Front....to....Rear)is:\n";
Display(Queue,front,rear);
}
cout<<"Want to delete more elements?(y/n)....";
cin>>ch;
}
getch();
}
int Insert(int Queue[],int ele)
{
if(rear==size-1)
return-1;
else if(rear==-1)
{
front=rear=0;
Queue[rear]=ele;
}
else
{
rear++;
Queue[rear]=ele;
}
getch();
}
int Remove(int Queue[])
{
int ret;
if(front==-1)
return-1;
else
{
ret=Queue[front];
if(front==rear)
front=rear=-1;
else
front++;
}
return ret;
}
void Display(int Queue[],int front,int rear)
{
if(front==-1)
return;
for(int i=front;i<rear;i++)
cout<<Queue[i]<<"<-\t";
cout<<Queue[rear]<<endl;}
Output of the program for Deletion in Array-Queue:
Addition and deletion of new books using linked list:

# include<iostream.h>
# include <conio.h>
class NODE
{
public:
int bookno;
NODE *link;
};
class LINKLIST
{
private:
NODE *first,*last,*temp;
public:
void NCREATE(int); // Create a linked list with n nodes
void insertatk(int); // Inserting at kth position
void display(); // Display the linked list
};
void LINKLIST::NCREATE( int n)
{
first = new NODE;
cout << "\n Enter the book number ";
cin >> first->bookno;
first->link = NULL;
temp = first;
for(int i =1;i<n;i++)
{
last = new NODE;
cout << "\n Enter the book number ";
cin >> last->bookno;
last->link = NULL;
temp->link = last;
temp = last;
}
}
void LINKLIST::insertatk(int j) // Function to insert the node at kth position
{
int i = 0;
NODE *newnode,*back;
newnode = new NODE;
cout<< "\nEnter the data value ";
cin>>newnode->bookno;
newnode->link = NULL;
temp = first;
while (i < (j-1))
{
back = temp;
temp = temp->link;
i++;
}
back->link = newnode;
newnode->link = temp;
}
void LINKLIST::display() //Function to display the link list
{
temp = first;
cout<< "\n The linked list is \n";
while (temp != NULL)
{
cout<< "\n"<<temp->bookno;
temp = temp->link;
}
getch();
}
void main()
{
int ch,n,k;
char ch1 = 'y';
LINKLIST list;
clrscr();
cout << "\n Enter how many nodes in the list ";
cin >> n;
list.NCREATE(n);
do
{
clrscr();
cout<< "\n1. For insert ";
cout << "\n2. For display ";
cout << "\n3. For quit ";
cout << "\nEnter your choice ";
cin>>ch;
switch (ch)
{
case 1:
cout << "\nEnter the position at which insertion is
required ";
cin >> k;
list.insertatk(k);
break;
case 2 :
list.display();
break;
}
} while (ch != 3);
}
Output of the program for Addition and deletion of new books using linked
list
Program to demonstrate the sum of two matrices:

#include<iostream.h>
#include<conio.h>
main()
{
int a[3][3], b[3][3], c[3][3];
int i, j;
cout << "\n\t Enter elements of Ist array";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
cin >> a[i][j];
}
cout << "\n\t Enter elements of IInd array";
for (i=0; i<3; i++)
{
for(j=0; j<3; j++)
cin >> b[i][j];
}
for (i=0; i<3; i++)
{
for(j=0; j<3; j++)
c[i][j] = a[i][j] + b[i][j];
}
clrscr();
cout << "First matrix is \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << a[i][j] << " ";
}
cout << "\n";
}
cout << "Second matrix is\n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << b[i][j] << " ";
}
cout << "\n";
}
cout << "\nSum of two matrix is \n";
for (i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cout << c[i][j] << " ";
}
cout << "\n";
}
return 0;
}
Output of program to demonstrate the sum of two matrices:
Program to find the length of the string:

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include <stdio.h>
//CLASS DECLARATION
class strn
{
char *a;
int i;
public:
void read(); //MEMBER FUNCTIONS
void calculate();
}; //END OF CLASS
void strn::read()
{
cout << "\n\t";
cout << "\n\tEnter your name ";
gets(a); //TO READ THE STRING
}
void strn::calculate()
{
i = 0;
while (*(a+i) != '\0')
i++;
cout << "\n\tThe length of your name is : " << i;;
}
//M A I N P R O G R A M
void main()
{
strn x; //DECLARATION OF OBJECT
clrscr();
cout<< "\n\n\n\t ";
x.read(); //CALLING MEMBER FUNCTIONS
x.calculate();
getch();

} //E N D OF MAIN
Output of the program to find the length of the string:
Program to find the occurrence of character in the string:

#include<iostream.h>
#include<string.h>
#include<conio.h>
# include <stdio.h>
//CLASS DECLARATION
class strn
{
char *a;
char ch;
int i;
public:
void read(); //MEMBER FUNCTIONS
void find();
}; //END OF CLASS
void strn::read()
{
cout << "\n\t";
cout << "\n\tEnter the first string ";
gets(a); //TO READ THE STRING
}
void strn::find()
{
i = 0;
int count = 0;
cout << "\n\t Enter the character ";
cin >> ch;
while (*(a+i) != '\0')
{
if (*(a + i) == ch)
count++;
i++;
}
cout << "\n\tThe number of times "<< ch << " occur in " << a << " is "
<< count;
}
//M A I N P R O G R A M
void main()
{
strn x; //DECLARATION OF OBJECT
clrscr();
cout << "\n\n\n\t ";
x.read(); //CALLING MEMBER FUNCTIONS
x.find();
getch();

} //E N D OF MAIN
Output of the program to find the occurrence of character in the
string:
A program to illustrate Multiple Inheritance:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class admin
{
int admno;
char name[30];
public:
void getadmin();
void putadmin();
};
void admin::getadmin()
{
cout<<"\nEnter admission no: ";
cin>>admno;
cout<<"\nEnter name: ";
gets(name);
}
void admin::putadmin()
{
cout<<"\nThe admission no is; ";
cout<<admno;
cout<<"\nThe name is: ";
cout<<name;
}
class acadm
{
int rno;
float marks;
public:
void getacadm();
void putacadm();
};
void acadm::getacadm()
{
cout<<"\nEnter rollno: ";
cin>>rno;
cout<<"\nEnter marks: ";
cin>>marks;
}
void acadm::putacadm()
{
cout<<"\nThe rollno is: ";
cout<<rno;
cout<<"\nThe total marks: ";
cout<<marks;
}
class school:public admin,public acadm //Derived class
{
char house[15],sport[20];
public:
void get_school();
void put_school();
};
void school::get_school()
{
getadmin();
getacadm();
cout<<"\nEnter house: ";
gets(house);
cout<<"\nEnter sport: ";
gets(sport);
}
void school::put_school()
{
putadmin();
putacadm();
cout<<"\nYour house is: ";
cout<<house;
cout<<"\nYour sports is: ";
cout<<sport;
}
void main()
{
clrscr();
school obj[10];
int n,i,j;
cout<<"Enter the no of students:";
cin>>n;
cout<<"\nEnter student details:";
for(i=0;i<n;i++)
{
obj[i].get_school(); //Input Function
}
cout<<"\nThe student details are:";
for(i=0;i<n;i++)
{
obj[i].put_school(); //Output Function
}
getch();
}
Output of the program to illustrate Multiple Inheritance:
Program to create two arrays to store roll numbers and marks of
desired students, whose number would be known at run time:

#include<iostream.h>
#include<conio.h>
int*rollno;
float*marks;
void main()
{
clrscr();
int size;
cout<<"How many elements are there in the array?\n";
cin>>size;
rollno=new int[size];
marks=new float[size];
if((!rollno) || (!marks))
{
cout<<"Out of memory! Aborting!";
return;
}
for(int i=0;i<size;i++)
{
cout<<"Enter rollno and marks for student"<<(i+1)<<"\n";
cin>>rollno[i]>>marks[i];
}
cout<<"Roll no \tMarks\n";
for(i=0;i<size;i++)
cout<<"\t"<<rollno[i]<<"\t\t"<<marks[i]<<"\n";
delete[]rollno;
delete[]marks;
getch();
}
Output of the program to create two arrays to store roll numbers
and marks of desired students, whose number would be known at
run time:
Function to display the elements which lie on middle of row and
column:

#include <stdio.h>
#include <iostream.h>
#include <conio.h>
const M = 10;
const N = 10;
void display_RowCol(int Array[M][N], int r, int c)
{
clrscr();
int row = r / 2;
int col = c / 2;
// Finding the middle row
cout << "Middle Row : ";
for(int j=0; j<c; j++)
cout << Array[row][j] << " ";
cout << endl;
// Finding the middle column
cout << "Middle Column : ";
for(j=0; j<c; j++)
cout << Array[j][col] << " ";
getch();
}
void main()
{
clrscr();
int Array[M][N];
int i, j;
int r, c;
cout << "Enter total no. of rows: ";
cin >> r;
cout << "Enter total no. of columns: ";
cin >> c;
// Array to be a square matrix with odd dimension
if ((r == c) && ((r%2==1) && (c%2==1)))
{
cout << "Input steps";
cout << "\n\Enter the element in the array\n";
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{
cin >> Array[i][j];
}
}
else
{
cout << "Input row and column not valid";
getch();
return;
}
display_RowCol(Array, r, c);
}
Output of the function to display the elements which lie on
middle of row and column:


Program to check whether the string is palindrome or not:

#include<iostream.h>
#include<string.h>
#include<conio.h>
//CLASS DECLARATION
class strn
{
char *a, flag;
int i, j, k;
public:
void read(); //MEMBER FUNCTIONS
void ch_pal();
strn() //USE OF CONSTRUCTOR
{
flag = 'y';
}
};
//END OF CLASS
void strn::read()
{
cout << "\n\t";
cout << "\n\tEnter the string ";
cin >> a; //TO READ THE STRING
}
void strn::ch_pal()
{
cout << "\n\tThe entered string ";
for(i=0; *(a+i)!='\0'; i++)
cout << *(a+i);
for(j=0, i-=1; i>j; j++, i--)
{
if(*(a + i) != *(a+j)) //CHECKING FOR PALINDROME
{
flag = 'n';
break;
}
}
if(flag == 'n')
cout << " is not a palindrome ";
else
cout << " is a palindrome ";
}
void main()
{
strn x; //DECLARATION OF OBJECT
clrscr();
cout << "\n\n\n\t ";
x.read(); //CALLING MEMBER FUNCTIONS
x.ch_pal();
cout << "\n\n\t\t bye!";
getch();
}
Output of the program to check whether the string is palindrome
or not:
Program to check whether the two strings are equal or not:

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include <stdio.h>
//CLASS DECLARATION
class strn
{
char *a, *b, flag;
int i, j, k;
public:
void read(); //MEMBER FUNCTIONS
void compare();
strn() //USE OF CONSTRUCTOR
{
flag = 'y';
}
}; //END OF CLASS
void strn::read()
{
cout << "\n\t";
cout << "\n\tEnter the first string ";
gets(a); //TO READ THE STRING
cout << "\n\tEnter the second string ";
gets(b); //TO READ THE STRING
}
void strn::compare()
{
i = 0;
j = 0;
while (*(a+i) != '\0')
i++;
while(*(b+j) != '\0')
j++;
if (i != j)
{
cout << "\n\t Strings are not equal ";
return;
}
i = 0;
while ((*(a+i) != '\0') && (*(b+i) != '\0'))
{
if(*(a + i) != *( b + i))
{
flag = 'n';
break;
}
i++;
}
if(flag == 'n')
cout << "\n\tStrings are not equal ";
else
cout << "\n\tStrings are equal ";
}
//M A I N P R O G R A M
void main()
{
strn x; //DECLARATION OF OBJECT
clrscr();
cout << "\n\n\n\t ";
x.read(); //CALLING MEMBER FUNCTIONS
x.compare();
cout << "\n\n\t\t bye!";
getch();
} //E N D O F M A I N
Output of the program to check whether the two strings are equal
or not:
Program to illustrate working of default arguments. Calculate
interest amount making use of default arguments:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void amount(float princ, int time=2, float rate=0.08);
void amount(float princ, int time, float rate)
{
cout<<”\nPrincipal Amount= Rs.”<<princ;
cout<<”\tTime=”<<time<<”years”;
cout<<”\tRate=”<<rate;
cout<<”\nInterest Amount=”<<(princ*rate*time)<<endl;
}
void main()
{
cout<<”Case 1”;
amount(2000);
cout<<”Case 2”;
amount(2500,3);
cout<<”Case 3”;
amount(2300,3,0.11);
cout<<”Case 4”;
amount(2500,0.08);
cout<<”Case 5”;
amount(1200,4,0.09)
Output of the program to illustrate working of default arguments.
Calculate interest amount making use of default arguments:
TABLE: STUDENT

No: Name Stipend Stream Avgmark Grade Class

1 Karan 400.00 Medical 78.5 B 12B

2 Divakar 450.00 Commerce 89.2 A 11C

3 Divya 300.00 Commerce 68.6 C 12C

4 Arun 350.00 Humanities 73.1 B 12C

5 Sabina 500.00 Nonmedical 90.6 A 11A

6 John 400.00 Medical 75.4 B 12B

7 Robert 250.00 Humanities 64.4 C 11A

8 Rubina 450.00 Nonmedical 88.5 A 12A

9 Vikas 500.00 Nonmedical 92.0 A 12A

10 Mohan 300.00 Commerce 67.5 C 12C

WRITE SQL COMMANDS FOR QUESTIONS 1 TO 7 ON THE BASIS OF TABLE STUDENT

1) Select all the Nonmedical stream students from STUDENT.

SELECT NAME

FROM STUDENT

WHERE STREAM=’NONMEDICAL’;
OUTPUT:

NAME:

SABINA

RUBINA

VIKAS

2) List the names of those students who are in class 12 sorted by stipend

SELECT NAME, STIPEND FROM STUDENT

WHERE CLASS=’12’

ORDER BY STIPEND;

OUTPUT:

NAME STIPEND

DIVYA 300.00

MOHAN 300.00

ARUN 350.00

KARAN 400.00

JOHN 400.00

RUBINA 450.00

VIKAS 500.00
3) List all students sorted by avgmark in descending order:

SELECT NAME FROM STUDENT

ORDER BY AVGMARK DESC;

OUTPUT:

ROBERT

MOHAN

DIVYA

ARUN

JOHN

KARAN

RUBINA

DIVAKAR

SABINA

VIKAS

4) To count the number of students with grade “A”

SELECT COUNT(GRADE)

FROM STUDENT

WHERE GRADE=”A”;

OUTPUT:

4
5) To insert a new student in the table anf fill the columns with some values

INSERT INTO STUDENT VALUES

(11,”MANISHA”,300.00,”NONMEDICAL”,72.5,”B”,12C);

OUTPUT:

ONE ROW ADDED

6) Give the output of the following SQL statement:

A) SELECT MIN(AVGMARK)

FROM STUDENT

WHERE AVGMARK<75;

OUTPUT:

64.4

B) SELECT SUM(STIPEND) FROM STUDENT WHERE GRADE=”B”

OUTPUT:

1150.00

C) SELECT AVG(STIPEND)FROM STUDENT WHERE CLASS=”12A”;

OUTPUT:

475.00

D) SELECT COUNT(DISTINCT)

OUTPUT:

10

You might also like