dk

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

PROGRAM 1

Write a C++ program to find the frequency presence of an element in an array.


#include<iostream.h>
#include<conio.h>
class frequency
{
private:
int a[10], n, i, ele, count;
public:
void input( );
void findfreq( );
void display( );
};
void frequency::input( )
{
cout<<"Enter the size of the array:";
cin>>n;
cout<<"\n Enter the array elements:";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency";
cin>>ele;
}
void frequency :: findfreq( )
{
count=0;
for(i=0; i<n; i++)
if(ele == a[i])
count++;
}
void frequency::display( )
{
if(count > 0)
cout<<ele<<" Occurs"<<count<<" Times";
else
cout<<ele<<" Does Not Exists";
}
void main( )
{
frequency f;
clrscr( );
f.input( );
f.findfreq( );
f.display( );
getch( );
}
PROGRAM 2
Write a C++ program to insert an element into an array at a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Insertion
{
private:
int a[10], n, p, ele, i;
public:
void getdata( );
void insert( );
void display( );
};
void Insertion::getdata( )
{
cout<<"Enter the size of the array";
cin>>n;
cout<<"Enter the elements for the array";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the position of the element in the array";
cin>>p;
cout<<"Enter the element to be inserted";
cin>>ele;
}
void Insertion::insert( )
{
if(p > n)
{
cout<<"array out of limits!!!";
exit(0);
}
else
{
for(i=n-1; i>=p; i--)
a[i+1] = a[i];
a[p] = ele;
n = n+1;
}
}
void Insertion::display( )
{
cout<<"Array after insertion :";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Insertion i;
clrscr( );
i.getdata( );
i.insert( );
i.display( );
getch( );
}

PROGRAM 3
Write a C++ program to delete an element from an array from a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Deletion
{
private:
int a[10], n, p, i;
public:
void getdata( );
void del( );
void display( );
};
void Deletion::getdata( )
{
cout<<"Enter the size of the array";
cin>>n;
cout<<"Enter the elements for the array:";
for (i=0; i<n; i++)
cin>>a[i];
cout<<"\n Enter the position to an delete an element";
cin>>p;
}
void Deletion::del( )
{
if(p>n)
{
cout<<"array out of limits...!!!";
exit(0);
}
else
{
for(i=p; i<n; i++)
a[i] = a[i+1];
n = n-1;
}
}
void Deletion::display( )
{
cout<<" Array after deletion ";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}

void main( )
{
Deletion d;
clrscr( );
d.getdata( );
d.del( );
d.display( );
getch( );
}

PROGRAM 4
Write a C++ program to sort the element of an array in ascending order using insertion sort.
#include<iostream.h>
#include<conio.h>
class Sort
{
private:
int a[10], n, i;
public:
void getdata ( );
void insertionsort ( );
void display( );
};
void Sort::getdata ( )
{
cout<<"Enter the size of the array:";
cin>>n;
cout<<"Enter the elements of the array:";
for(i=0; i<n; i++)
cin>>a[i];
}
void Sort::insertionsort( )
{
int j, temp;
for(i=1; i<n; i++)
{
j = i;
while(j >= 1)
{
if(a[j] < a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
j = j-1;
}
}
}
void Sort::display( )
{
cout<<"Sorted array is.....";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Sort s;
clrscr( );
s.getdata( );
s.insertionsort( );
s.display( );
getch( );
}
PROGRAM 5
Write a C++ program to search for a given element in an array using binary search method.
#include<iostream.h>
#include<conio.h>
class Bsearch
{
private:
int a[10], n, i, ele, loc;
public:
void getdata( );
void search( );
void display( );
};
void Bsearch::getdata( )
{
cout<<"Enter the size of the array:";
cin>>n;
cout<<"\n Enter elements of the array in sorted order: ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the search element ";
cin>>ele;
}
void Bsearch :: search( )
{
int B=0, E=n-1, M;
loc=-1;
while (B <= E)
{
M = (B + E)/2;
if(ele == a[M])
{
loc = M;
break;
}
else
if (ele < a[M])
E = M - 1;
else
B = M + 1;
}
}

void Bsearch::display( )
{
if(loc >= 0)
cout<<"\n Element Found at Location: "<<loc;
else
cout<<"\n Element not found...";
}

void main( )
{
Bsearch s;
clrscr( );
s.getdata( );
s.bsearch( );
s.display( );
getch( );
}

PROGRAM 6
Write a C++ program to create a class with data members principal, time and rate. Create a member
function to accept data values, to compute simple interest and to display the result.
#include<iostream.h>
#include<conio.h>
class SimpleInterest
{
private:
float p, r, t, si;
public:
void getdata( );
void display( );
};
void SimpleInterest::getdata( )
{
cout<<"Enter the Principal, Rate and Time";
cin>>p>>r>>t;
}
void SimpleInterest::display( )
{
si=(p * t * r) / 100;
cout<<"\n Simple Interest is = "<<si;
}
void main( )
{
SimpleInterest si;
clrscr( );
si.getdata( );
si.display( );
getch( );
}

PROGRAM 7
Write a C++ program to create a class with data members a, b, c and member functions to input data,
compute the discriminant based on the following conditions and print the roots.
 If discriminant = 0, print the roots are equal and their value.
 If discriminant > 0, print the real roots and their values.
 If discriminant < 0, print the roots are imaginary and exit the program.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class Quadratic
{
private:
int a, b, c, d;
double x, x1, x2;
public:
void getdata( );
void display( );
};
void Quadratic::getdata( )
{
cout<<"\n Enter the values for a, b, c";
cin>>a>>b>>c;
}
void Quadratic::display( )
{
d = b*b-4*a*c;
if(d = = 0)
{
cout<<"\n Equal Roots...";
x=-b / (2*a);
cout<<"\n Root is...."<<x;
}
else if (d > 0)
{
cout<<"\n Real and Distinct Roots...";
x1=(-b + sqrt (d)) / (2*a);
x2=(-b - sqrt (d)) / (2*a);
cout<<"\n Root 1 is "<<x1;
cout<<"\n Root 2 is "<<x2;
}
else
cout<<"\n Imaginary Roots...";
}

void main( )
{
Quadratic q;
clrscr( );
q.getdata( );
q.display( );
getch( );
}

PROGRAM 8
Write a C++ program to find the area of square/ rectangle/ triangle using function overloading.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class Funoverload
{
public:
int area(int a)
{
return a*a;
}
float area(float l, float b)
{
return l*b;
}
float area(float a, float b, float c)
{
float s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
};

void main()
{
Funoverload f;
clrscr( );
cout<<"\n Area of square is = "<<f.area(5);
cout<<"\n Area of rectangle is = "<<f.area(4.0, 6.0);
cout<<"\n Area of triangle = "<<f.area(3.0, 4.0, 5.0);
getch( );
}

PROGRAM 9
Write a C++ program to find cube of a number using inline function.
#include<iostream.h>
#include<conio.h>
class assign
{
public:
inline int cube(int a)
{
return a*a*a;
}
};
void main( )
{
assign N;
int n;
clrscr( );
cout<<"Enter the input number";
cin>>n;
cout<<"\n The Cube = "<<N.cube(n);
getch( );
}

PROGRAM 10
Write a C++ program to find sum of the series 1 + x + x2 + x3 + ….. xn using constructors.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class Series
{
private:
int sum, x, n;
public:
Series(int a, int b)
{
sum = 1;
x = a;
n = b;
}
int sumseries( );
};
int Series::sumseries( )
{
for(int i=1;i<=n;i++)
sum=sum+pow(x, i);
return sum;
}
void main()
{
int x,y;
clrscr( );
cout<<"Enter the value for Base (x) and Power (y) ";
cin>>x>>y;
Series s1(x, y);
Series s2 = s1;
cout<<"Sum of Series using Parameterized Constructor: "<<s1.sumseries( );
cout<<"Sum of Series using Copy Constructor: "<<s2.sumseries( );
getch( );
}

PROGRAM 11
Create a base class containing the data member roll number and name. Also create a member
function to read and display the data using the concept of single level inheritance. Create a derived
class that contains marks of two subjects and total marks as the data members.
#include<iostream.h>
#include<conio.h>
class Student
{
private:
int regno;
char name[20];
public:
void readdata( )
{
cout<<"Enter the Register Number: ";
cin>>regno;
cout<<"Enter the Student Name:";
cin>>name;
}
void display( )
{
cout<<"\n Register Number :"<<regno;
cout<<"\n Student Name:"<<name;
}
};
class marks : public Student
{
private:
int m1, m2, total;
public:
void readmarks( )
{
cout<<"\n Enter Two Subjects Marks: ";
cin>>m1>>m2;
}
void compute( )
{
total = m1 + m2;
cout<<"\n Total Marks : "<<total;
}
};
void main( )
{
marks m;
clrscr( );
m.readdata( );
m.display( );
m.readmarks( );
m.compute( );
getch( );
}

PROGRAM 12
Create a class containing the following data members RegisterNo, Name and Fees. Also create a
member function to read and display the data using the concept of pointers to objects.
#include<iostream.h>
#include<conio.h>
class Student
{
private:
int regno;
char name[20];
float fees;
public:
void readdata( );
void display( );
};
void Student::readdata( )
{
cout<<"\n Enter the Register Number, Name and Fees:";
cin>>regno>>name>>fees;
}
void Student::display( )
{
cout<<"\n Register Number : "<<regno;
cout<<"\n Student Name : "<<name;
cout<<"\n Fees : "<<fees;
}
void main( )
{
Student s, *sp;
clrscr( );
sp=&s;
sp -> readdata( );
sp -> display( );
getch( );
}

13. Generate the Electricity Bill for one customer:


1. Create a table for house hold Electricity bill with the following fields.
FIELD NAME TYPE
RR_NUMBER VARCHAR(10)
CONSUMER_NAME VARCHAR(15)
DATE_BILLING DATE
UNITS NUMBER(4)

2. Check the structure of table and note your observation.


3. Insert 10 records into the table.
4. Add two fields to the table.
a. BILL_AMT NUMBER(6,2)
b. DUE_DATE DATE
5. Compute the bill amount for each customer as per the following rules.
a. MINIMUM AMT Rs. 50
b. First 100 units Rs 4.50 / Unit
c. >100 units Rs. 5.50 / Unit
6. Compute due date as DATE_BILLING + 15 Days
7. List all the bills generated.
SOLUTION:
1. CREATE TABLE EBILL (RR_NUMBER VARCHAR (10), CONSUMER_NAME VARCHAR (15),
DATE_BILLING DATE, UNITS NUMBER (4));

2. DESC EBILL;

3. INSERT INTO EBILL VALUES (‘101’, ‘ASHOK’, ‘12/NOV/2023’, 125);


INSERT INTO EBILL VALUES (‘102’, ‘AMOGH’, ‘1/SEP/2022’, 75);
INSERT INTO EBILL VALUES (‘103’, ‘BHOOMIKA’, ‘5/AUG/2022’, 150);
INSERT INTO EBILL VALUES (‘104’, ‘CHARAN’, ‘8/MARCH/2023’, 225);
INSERT INTO EBILL VALUES (‘105’, ‘DHANUSH’, ‘4/JUN/2023’, 80);
INSERT INTO EBILL VALUES (‘106’, ‘ESHWAR’, ‘6/JAN/2022’, 90);
INSERT INTO EBILL VALUES (‘107’, ‘KARAN’, ‘15/DEC/2021’, 130);
INSERT INTO EBILL VALUES (‘108’, ‘LAKSHMI’, ‘10/OCT/2023’, 140);
INSERT INTO EBILL VALUES (‘109’, ‘RAHUL’, ‘20/NOV/2023’, 110);
INSERT INTO EBILL VALUES (‘110’, ‘SURYA’, ‘25/NOV/2023’, 105);

4. ALTER TABLE EBILL ADD (BILL_AMT NUMBER (8, 2), DUE_DATE DATE);

5. UPDATE EBILL SET BILL_AMT = 50;


UPDATE EBILL SET BILL_AMT = BILL_AMT + UNITS * 4.5 WHERE UNITS <= 100;
UPDATE EBILL SET BILL_AMT = BILL_AMT + 100 * 4.5 + (UNITS-100) * 5.5 WHERE UNITS > 100;

6. UPDATE EBILL SET DUE_DATE = DATE_BILLING + 15;

7. SELECT * FROM EBILL;


14. Create a Student database and compute the results.
1. Create a table for class of students with the following fields.

FIELD NAME TYPE


SID NUMBER(4)
SNAME VARCHAR(15)
S1 NUMBER(3)
S2 NUMBER(3)
S3 NUMBER(3)
S4 NUMBER(3)
S5 NUMBER(3)
S6 NUMBER(3)

2. Display the description of the fields in the table using DESC command.
3. Add records into the table for 10 students for Student ID, Student Name and marks in 6 subjects using
INSERT command.
4. Alter the table add TOTAL NUMBER (3), PERCENTAGE NUMBER (5, 2) and RESULT
VARCHAR (8).
5. Calculate the TOTAL and PERCENTAGE.
6. Compute the RESULT as “PASS” or “FAIL” by checking if the student has scored more than 35 marks
in each subject.
7. List the contents of the table.

Solution:
1. CREATE TABLE STUDENT (SID NUMBER(4), SNAME VARCHAR(15), S1 NUMBER(3), S2
NUMBER(3), S3 NUMBER(3), S4 NUMBER(3), S5 NUMBER(3), S6 NUMBER(3));

2. DESC STUDENT;

3. INSERT INTO STUDENT VALUES (101, ‘ASHA’, 87, 78, 92, 77, 86, 90);
INSERT INTO STUDENT VALUES (102, ‘BHARATH’, 67, 58, 82, 67, 76, 80);
INSERT INTO STUDENT VALUES (103, ‘CHAITHANYA’, 85, 73, 87, 72, 81, 85);
INSERT INTO STUDENT VALUES (104, ‘DEEPTHI’, 97, 88, 92, 87, 96, 99);
INSERT INTO STUDENT VALUES (105, ‘ESHWAER’, 37, 28, 32, 27, 36, 40);
INSERT INTO STUDENT VALUES (106, ‘GIRISH’, 57, 48, 52, 47, 36, 50);
INSERT INTO STUDENT VALUES (107, ‘HARSHA’, 27, 28, 32, 37, 46, 40);
INSERT INTO STUDENT VALUES (108, ‘INDU’, 88, 78, 93, 78, 86, 92);
INSERT INTO STUDENT VALUES (109, ‘JANU’, 67, 68, 72, 77, 66, 70);
INSERT INTO STUDENT VALUES (110, ‘KUNAL’, 17, 28, 32, 37, 26, 40);

4. ALTER TABLE STUDENT ADD (TOTAL NUMBER (3), PERCENTAGE NUMBER (5, 2),
RESULT VARCHAR (8));

5. UPDATE STUDENT SET TOTAL=S1+ S2+ S3+ S4+ S5+ S6;


UPDATE STUDENT SET PERCENTAGE = TOTAL / 6;

6. UPDATE STUDENT SET RESULT = ’PASS’ WHERE S1 >= 35 AND S2 >= 35 AND S3 >= 35 AND
S4 >= 35 AND S5 >= 35 AND S6 >= 35;
UPDATE STUDENT SET RESULT = ’FAIL’ WHERE S1 < 35 OR S2 < 35 OR S3 < 35 OR S4 < 35
OR S5 < 35 OR S6 < 35;

7. SELECT * FROM STUDENT;

15. Write a HTML program to create a STUDY Time Table.


<HTML>
<HEAD>
<TITLE> TIME TABLE </TITLE>
</HEAD>
<BODY>
<CENTER> <H2> STUDY TIME TABLE </H2>
<TABLE BORDER=4 BORDERCOLOR=BLUE CELLPADDING=10>
<TR BGCOLOR=PINK>
<TD ROWSPAN=2 ALIGN=CENTER> <B> DAY </B> </TD>
<TD COLSPAN=8 ALIGN=CENTER> <B> TIMINGS </B></TD>
</TR>
<TR BGCOLOR=PINK>
<TH> 06:00 PM - 07:00 PM </TH>
<TH> 07:00 PM - 08:00 PM </TH>
<TH> 08:00 PM - 09:00 PM </TH>
<TH> 09:00 PM - 09:30 PM </TH>
<TH> 09:30 PM - 10:30 PM </TH>
</TR>
<TR>
<TD> MONDAY </TD>
<TD> MATHS </TD>
<TD> PHYSICS </TD>
<TD> CHEMISTRY </TD>
<TD ROWSPAN=6 ALIGN=CENTER>BREAK</TD>
<TD> COMPUTER SCIENCE </TD>
</TR>
<TR>
<TD>TUESDAY</TD>
<TD> PHYSICS </TD>
<TD> CHEMISTRY </TD>
<TD> MATHS </TD>
<TD> ENGLISH </TD>
</TR>
<TR>
<TD> WEDNESDAY </TD>
<TD> COMPUTER SCIENCE </TD>
<TD> MATHS </TD>
<TD> PHYSICS </TD>
<TD> KANNADA </TD>
</TR>
<TR>
<TD> THRUSDAY </TD>
<TD> MATHS </TD>
<TD> PHYSICS </TD>
<TD> KANNADA </TD>
<TD> ENGLISH </TD>
</TR>
<TR>
<TD>FRIDAY </TD>
<TD>ENGLISH </TD>
<TD>COMPUTER SCIENCE </TD>
<TD>PHYSICS </TD>
<TD>MATHS</TD>
</TR>
<TR>
<TD> SATURDAY </TD>
<TD> MATHS </TD>
<TD> ENGLISH </TD>
<TD> CHEMISTRY </TD>
<TD> COMPUTER SCIENCE </TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
16. Create an HTML program with Table and Form.
<HTML>
<HEAD>
<TITLE> ONLINE APPLICATION </TITLE>
</HEAD>
<BODY>
<FORM>
<H3 ALIGN=CENTER> APPLICATION FORM </H3>
<TABLE BGCOLOR=PINK CELLSPACING=5 CELLPADDING=5 ALIGN=CENTER>
<TR>
<TD ALIGN=LEFT>STUDENT NAME: </TD>
<TD><INPUT TYPE=”TEXT”></TD>
</TR>
<TR>
<TD ALIGN=LEFT>FATHER NAME: </TD>
<TD> <INPUT TYPE=”TEXT”> </TD>
</TR>
<TR>
<TD ALIGN=LEFT> EMAIL ID: </TD>
<TD><INPUT TYPE=”TEXT”></TD>
</TR>
<TR>
<TD ALGIN=LEFT> STUDENT ADDRESS : </TD>
<TD> <TEXTAREA ROWS=4 COLS=10 NAME=”ADDR”></TEXTAREA>
</TD>
</TR>
<TR>
<TD ALIGN=LEFT>SECTION : </TD>
<TD ALGIN=LEFT>
<SELECT NAME=”DROPDOWN”>
<OPTION VALUE=1>PCMC A</OPTION>
<OPTION VALUE=2>PCMB B</OPTION>
<OPTION VALUE=3>PCMC C</OPTION>
<OPTION VALUE=4>CEBA D</OPTION>
<OPTION VALUE=5>CEBA E</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD> <INPUT TYPE="SUBMIT" VALUE="SUBMIT THE FORM"> </TD>
<TD> <INPUT TYPE="RESET" VALUE="RESET THE FORM"> </TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
VIVA QUESTIONS
1. Which operator used to access member functions of a class?
2. Which operator used to define the member functions outside the class?
3. Which is the default access specifiers of a class?
4. What is a class?
5. What is an object?
6. Mention the access specifiers in C++
7. Give an example for data encapsulation.
8. What is an array?
9. What is insertion operation with respect to data structure?
10. What is deletion operation with respect to data structure
11. What is searching?
12. What is the condition to apply binary search technique to search an element in an array?
13. What is sorting?
14. Give an example for the primitive data structure.
15. Give an example for a linear data structure.
16. Give an example for non-linear data structure.
17. What is function overloading?
18. How does the compiler identifies the particular function to be executed in a set of overloaded
functions?
19. Which characteristics of OOP is implemented using Function overloading?
20. What is an inline function?
21. Give an advantage of an inline function.
22. Mention any one disadvantage of an inline function.
23. What is a constructor?
24. When does a constructor is invoked?
25. Mention the types of constructor.
26. Which section of a class a constructor can be defined?
27. What is inheritance?
28. What is a base class?
29. What is derived class?
30. Mention the operator used to create a derived class in C++.
31. What is a pointer?
32. Mention the address operator in C++.
33. Which operator is used to allocate memory dynamically?
34. Which operator is used to deallocate memory dynamically?
35. Mention any one web browser.
36. Mention the text formation tags in HTML.
37. What is the purpose of TR tag in HTML?
38. What is DHTML?
39. Differentiate between check box and radio button.
40. How do you change the background color of a webpage?
41. Mention the tag used to scroll a text from one place to another in HTML.
42. Mention the tag used to link from one webpage to another.
43. Which command is used to add new columns to the existing table?
44. Which command is used to count the number of records in a table?
45. Differentiate between drop and delete command in SQL
46. Which clause in SQL is used to sort the records based on one or more columns?
47. Which command is used to modify the records of the table?
48. Mention the DDL commands in SQL
49. Mention the DML commands in SQL
50. Which command is used to retrieve the records of the table?

You might also like