Sei sulla pagina 1di 330

CERTIFICATE

This is to certify that this Computer Science


program file belongs toHEMONESH
MAHESHWARI of class XII-A session 2019-20
of D.A.V. PUBLIC SCHOOL.

The Programs written in this file has been done by


the candidate and are all genuine.

This program file may be considered as a part of


the Computer Science CBSE board Practical
examination 2019-2020.

Date: _________ Sign of __________


Teacher in-charge
ACKNOWLEDGEMENT
Acknowledgement is the most beautiful page in
any submission .More than a formality; this
appears to me the best opportunity to express my
gratitude.
My list begins with you, Dear God.
And I would just say “THANK YOU”.
Next on my thanks list is my school. I accord
thanks to my teacher Mr. ASHOK KUMAR GOEL
who provided me this opportunity to showcase my
talent and helped me in completion of this file.
Also, I would like to thank my CLASS MATES
who supported and co-operated with me in this
work and last but not the least , my parents for
showing faith in me and my abilities.

Name: HEMONESH
Class: XII sec: A
Session: 2019-2020
Board roll no.: _______________
Hardware and Software
Requirements

HARDWARE:
Processor : Intel(R) Core™ i5 @ 1.80 GHz 2.80
GHz
Installed Memory (RAM): 8.00 GB
System Type: 64-bit Operating System, x64 based
processor
Hard Disk Drive(HDD) : No
Solid State Drive(SSD) : 256 GB

SOFTWARE:
System: Mac OS Catalina
Software used: Turbo C++ and Pages
LIST OF PROGRAMS
STRUCTURES
(1)Q1. Write a program to define a structure HONOUR with the following data members:
1. Name of the Winners 2.Type of the Award 3.Prize Amount
Now declare an array of structure with N number of elements and perform the following
using separate functions for each:
1. Fill the array
2. Show the contents of the array in a tabular form
3. Display all those winners who have earned a prize amount more than 50,000
4. Display the name and the prize amount of the biggest prize amount winner

(2)Q2. Declare a structure ELECTRIC having the following members:


Cust_NO, Name, No_of_unitsconsumed and bill.
Then the bill has to be calculated as below:
Units consumed Tariff
For the first 100 units Rs. 0.40 per unit
For the next 200 units Rs. 0.50 per unit
For the next 300 units Rs. 0.75 per unit
For the next 400 units Rs. 1.00 per unit
Beyond 1000 units Rs. 1.50 per unit
Write a complete C++ program to calculate the bill and display the information of all the
customers using array of structures in the sorted order of customer number using array sort.
Make use of functions and make the program interactive and menu driven.

FUNCTION OVERLOADING
(3)Q 1.Write a program to illustrate working of function overloading. Calculate interest
amount using function overloading.

(4)Q 2.Write a C++ program that uses an area( ) function for the calculation of area of a
triangle or a rectangle or a square. Number of sides (3 for triangle, 2 for rectangle, 1 for
square) suggest about the shape for which area is to be calculated.

CLASSES AND OBJECTS


(5)Q1. Declare a class to represent bank account of 10 customers with the following data
members. Name of the depositor, Account number, Type of account, (S for Saving and C for
Current), Balance amount. The class also contains member functions to do the following:
(i) To initialize data members (ii) To deposit money
(iii) To withdraw money after checking (iv) to display the data
Members.
The balance (minimum balance in Rs. 1000)

(6)Q 2.Write a C++ program using classes and objects to simulate result preparation system
for 20 students. The data available for each student includes rollno, name and marks in 3
subjects. The percentage marks are the average marks and the grade is calculated as follows:
Percentage marks grade
<50 ‘E’
>=50<60 ‘D’
>=60<75 ‘C’
>=75<90 ‘B’
>=90<100 ‘A’

(7)Q 3. Write a C++ program to perform the various operations on a string class without
using language supported built-in string functions. The operations to be done on the class are:
a. Read a string
b. Display the string
c. Reverse the string
d. Copy the string into an empty string
e. Concatenate two strings

(8)Q 4. Write a class to represent a vector (1 – dimensional numeric array) . Include the
following member functions :
1. For vector creation
2. For modification of a given element
3. For displaying the largest value in the vector
4. For displaying the smallest value in the vector
5. For displaying the entire vector

CONSTRUCTORS AND DESTRUCTORS


(9)Q 1. Define a class TravelPlan in C++ with the following descriptions:
Private members :
PlanCode Of type long
Place Of type character array (string)
Number_of_travellers Of type integer
Number_of_buses Of type integer

Public members :
● A constructor to assign initial values of PlanCode as 1001, Place as “Agra”,
Number_of_travellers as 5, Number_of_buses as 1
● A function NewPlan( ) which allows user to enter PlanCode, Place and
Number_of_travellers. Also, assign the value of Number_of_buses as per the
following conditions :
Number_of_travellers Number_of_buses
Less than 20 1
Equal to or more than 20 and less than 40 2
Equal to 40 or more than 40 3

(10)Q 2. Define a class Outfit in C++ with the following descriptions :


Private members :

OCode Of type string


OType Of type string
OSize Of type integer
OFabric Of type string
OPrice Of type float

A function InitPrice( ) which calculates and assigns the values of OPrice as follows :
For the value of OFabric “DENIM”,
OType OPrice(Rs)
TROUSER 1500
JACKET 2500

For fabric other than “DENIM” the above mentioned OPrice gets reduced by 25%.

Public members:
● A constructor to assign initial values of OCode, OType and OFabric with the word
“NOT INITIALISED” and OSize and OPrice with 0.
● A function Input( ) to input the values of the data members OCode, OType, OSize and
OFabric and invoke the InitPrice( ) function.
● A function Display( ) which displays the content of all the data members for an
Outfit.

INHERITANCE
(11)Q 1.Write a C++ program to read and display information about employees and
managers. Employee is a class that contains employee number (int), name (char array),
address (char array) and department (char array). Manager class contains all information of
the employee class and a list of employees working under a manager.

DATA FILE HANDLING


(12)Q1.Write a complete menu driven program that creates a file ,calculates and displays the
total number of vowels in the file ,calculates and displays the total number of spaces in the
file , calculates and displays the total number of alphabets in the file , calculates and displays
the total number of words in the file. Make use of the following functions and ask the user for
his/her choice :
1. createfile( ) 2. displayfile( ) 3. vowelcheck( )
4. spacecount( ) 5. alphacount ( ) 6. wordscount( )

(13)Q 2.Given a Binary file phone.dat , containing records of the following type:
class Phonelist
{
char Name[20];
char Address[30];
char Areacode[5];
char PhoneNum[15];
public:
void Register( );
void Show( );
void Transfer( );
int CheckCode(char AC[])
{
return strcmp(Areacode, AC);
}
};
Write complete menu driven program , complete the definitions of the functions.Void
Register( ) function to input all data and write the records to the file , void Show( ) to display
all data after reading from the file .Void Transfer( ) to copy those records which are having
Areacode as “DEL” from Phone.dat to Phone_new.dat .

(14)Q 3. Given a Binary file APPLY.DAT , containing records of the following class
Applicant type:
Class Applicant
{
Char A_Rno[10];
Char A_Name[30];
Int A_score;
Public:
Void Enrol ( )
{
Gets(A_Rno);
Gets(A_Name);
Cin>>A_Score;
}
Void Status( )
{ cout<<setw(12)<<A_Rno;
Cout<<setw(32)<<A_Name;
Cout<<setw(3)<<A_Score<<endl;
}
Int ReturnScore( )
{ return A_Score;
};
Write functions in C++
1.to write the objects of the file on to disk
2. To read objects from the file and display on screen
3. to read and display the details of those students whose A_Score is > 70.
Develop into a complete menu driven C++ program

(15)Q4. Assuming the class Applicant given below, write functions in C++ to perform the
following:
class Applicant
{ char A_Rno[10];
char A_Name[20];
int A_Score; };
i. Write the objects of class to a binary file.
ii. Reads the objects of class from binary file and display them on screen.
iii. Searches for a particular A_Rno.
iv. Reads the file and lets the user make changes in data and invokes the function to
display the values.
v. Just displays contents of the file.
Note : Include all the required function’s prototypes in the public section of the class.

(16)Q 5 . Write a menu driven program to read, display, append, and delete records in the file
MOVIE.DAT .Use the class given below.
class Movie
{ int movie_id;
char movie_name[20];
int no_of_seats;
int ticketcode;
int hallno;
public:
void readdata( );
void display( );
void append( );
void delete( );
};

(17)Q 6. Write a complete program that reads characters from the keyboard one by one. All
lower case characters get stored inside the file LOWER, all upper case characters get stored
inside the file UPPER and all other characters get stored inside file OTHERS. Use functions.

(18)Q 7. Write a complete file handling program which does the following on a text file :
(Make the program interactive, menu driven and using functions and switch case )
1. Create file 2. Display data from file 3. Show digit count 4. show alphabet count 5. show
word count 6. show line count 7. show space count 8. show vowel count 9. show count
of consonants 10. show count of all uppercase characters 11. show count of all lowercase
characters 12. show occurrence of the word "THE" or "the" or 'The" 13.show count of all 3
lettered words 14. exit
(19)Q 8. Write a complete program in C++ that reads a text file ORIG.TXT and creates another
identical file NEW.TXT except for the fact that every sequence of consecutive blank space is replaced
by a single space.
(20)Q9. Consider the class given:

class BUS
{
int Bus_No;
char Destination[15];
float Distance;
public:
void READ( );
void WRITE( );
void ENTER ( );
void SHOW( );
void UPDATE ( ); // to ask for a Bus_No and update the other details
};

Complete the member functions definition of all methods. Use the binary file "BUS.dat". Ensure that
required validations(file existing) are done before displaying the records, in the main ( ).Records
should be displayed sequentially from beginning to end. Also, add any other function , if needed.

(21)10. Consider the class given:

class CAR
{
int CAR_No;
char Destination[15];
float Distance;
public:
void READ( );
void WRITE( );
void ENTER();
void SHOW( );
void DELETE( ); // to delete records as per user's choice
};

Complete the definition of all methods .Use the binary file "CAR.dat" . Ensure that required
validations(file existing) are done before displaying the records, in the main ( ).Records should be
displayed sequentially from beginning to end. Add any function if needed.

ARRAYS (USING FUNCTIONS)


(22)Q1. Write a program to 1.add two matrices 2. Subtract 2 matrices 3. Multiply 2 matrices.
Use switch case and use functions to achieve the task.
(23)Q2. Write a program to 1.transpose a matrix 2. Find the row sum 3. Find the column sum
4. sum diagonal elements 5. sum elements below main diagonal 6. sum elements above main
diagonal of a given matrix. Use switch case and use functions to achieve the task.
(24)Q3. Write a program to illustrate the two types of searches in an integer type array. Make
use of functions and make a menu driven program.
(25)Q4. Write a program to illustrate all the three sorts – Insertion, Selection and Bubble sort
in an array. Make use of functions to do the same. Make a menu driven and user friendly
program.
(26)Q5. Write a program to merge two given arrays into the third array C .Use switch case
and implement the same with atleast 4 different combinations. Make use of functions.
(27)Q6. An array, ARRAY [20], consists of 20 positive integers .Write a complete user
friendly, menu driven functions oriented C++ program to do the following:
1. Find the pairs of integers stored in A having sum = 50
2. Find the number of elements which are odd
3. Find the number of elements which are even
4. Find the number of elements which are divisible by 30
5. Find the largest of all the elements
6. Find the smallest of all the elements
7. Find the average of all the elements
(28)Q7. Let A be N X N two-dimensional array. Write user-defined functions in C++ for the
following:
1. To find the number of non-zero elements in A.
2. To find the sum of all elements in A.
3. To find the sum of all elements A[i][j] for which i > j.
4. To find the sum of all elements A[i][j] for which i < j.
5. To find the product of all elements A[i][j] for which i = j.
(29)Q8. Program of project work done in Std 11.

LINKED LISTS, STACKS & QUEUES


(30)Q1. Write a program in C++ that creates a complete linked list class.

(31)Q2. Write a program to implement the use of Queue class.

(32)Q3. Write a program to implement the use of Stack class.

(33)Q4. Write a program in C++ to add, delete, search and display an element in a linked
queue.

(34)Q5. Write a complete menu driven program in C++ for the implementation of linked
stack.

(35)Q6. Write an interactive menu driven C++ program to implement circular queue using an
array consisting of integer data values.

SQL
(36)Q1. Write SQL commands for (a) to (f) on the basis of teacher relation given below:
Relation teacher
No. Name. Age Dept. Date of Salary Sex
joining
1. Jugal 34 Computer 10/01/97 12000 M

2. Sharmila 31 History 24/03/98 20000 F

3. Sandeep 32 Math 12/12/96 30000 M

4. Sangeeta 35 History 01/07/99 40000 F

5. Rakesh 42 Math 05/09/97 25000 M

6. Shyam 50 History 27/06/98 30000 M


7. Shiv om 44 Computer 25/02/97 21000 M

8. Shalakha 33 Math’s 31/07/97 20000 F

(a) To show all information about the teachers of the history dept.
(b) To list the names of the female teachers who are in the Hindi Dept.
(c) To list all the teachers with their Date of joining in ascending order.
(d) To display student’s Name, Fee, Age for Male teachers only.
(e) To count the number of teachers with Age<23.
(f) TO insert a new row in the TEACHER table .

(37)Q2 Consider the following tables WORKERS and DESIG .Write the SQL commands
for the statements (i) to (v)
WORKERS
W-ID FIRST NAME LAST NAME ADDRESS CITY
102 Sam Tones 33 Elm St. Paris
105 Sarah Ackerman 440 U.S. 110 New York
144 Manila Sengupta 24 Friends Street New Delhi
210 George Smith 83 First Street Howard
255 Mary Jones 842 Vine Ave. Losantiville
300 Robert Samuel 9 Fifth cross Washington
335 Henry Williams 12 Moore Street Boston
403 Ronny Lee 121Harrison Street New York
451 Pat Thompson 11 Red road Paris

W_ID SALARY BENEFITS DESIGNATION


102 75000 15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
403 32000 7500 Salesman
451 28000 7500 Salesman

i. To display W_ID first name, Address and City Of all the employees living in New
York from the table workers.
ii. To display the contents of WORKERS table in ascending order of LASTNAME.
iii. To display the First name, last name and total salary of all clerks from the tables
WORKERS and DESIG ,where Total Salary is calculated as salary + benefits.
iv. To display the minimum salary among mangers and clerks from the table DESIG
v. To display firstname, lastname and their designation who have their salaries above
60000.

(38)Q3.Consider the following table CONSIGNOR and CONSIGNEE. Write SQL


commands for following statements.
TABLE : CONSIGNOR
CnorID CnorName CnorAddress City

ND01 R Singhal Park avenue New Delhi

ND02 Amit Kumar 123, Palm Avenue New Delhi

MU15 R Kohli 5/A South Park Mumbai

MU50 S Kaur 27-K, westend Mumbai

TABLE : CONSIGNEE
CneeID CnrID CneerName CneeAddress city

MU05 ND01 Rahul Kishore ABC enclave Mumbai


ND08 ND02 P Dhingra 16/J, Moore enclave New Delhi
KO09 MU15 A P Roy 2A, Central Avenue Kolkata
MU32 ND02 S Mittal P 245, AB Colony Mumbai
ND48 MU50 B P Jain 13, Block D, A Vihar New delhi

1. To display names of all CONSIGNOR from MUMBAI.


2. To display the CneeName, CnorName where consignor city is same as
consignee city.
3. To display consignee detalils in ascending order of CneeName.
4. To display distinct city from consignor.
5. To display CneeName and CnorName Where city is Mumbai.
(39)Q 4 study the following tables FLIGHTS and FARES and write the SQL commands for
the questions that follow
Flights
FL_NO. STARTING ENDING NO_FLIGHTS NO_STOPS

IC301 MUMBAI DELHI 8 0

IC799 BANGLORE DELHI 2 1

MC101 INDORE MUMBAI 3 0

IC302 DELHI MUMBAI 8 0

AM812 KANPUR BANGALORE 3 1

IC899 MUMBAI KOCHI 1 4

AM501 DELHI TRIVANDRUM 1 5

MU499 MUMBAI MADRAS 3 3

IC701 DELHI AHEMDABAD 4 0

FARES

FL_NO AIRLINES FARE TAX

IC701 INDIAN AIRLINES 6500 10

MU499 SAHARA 9400 5

AM501 JET AIRWAYS 13450 8

IC899 INDIAN AIRLINES 8300 4


IC302 INDIAN AIRLINES 4300 10

IC799 INDIAN AIRLINES 10500 10

MC101 DECCAN AIRLINES 3500 4

Q1 Display FL_NO and NO_FLIGHTS from “KANPUR” to “BANGALORE” .


Q2 Display the total fare collected by INDIAN AIRLINES
Q3 display the FL_NO and FARE to be paid for the flights from DELHI to MUMBAI
Q4 Display STARTING, ENDING, AIRLINES and FARE from FLIGHTS and FARES
where TAX greater than 5
Q5 Display FL_NO and DISTINCT AIRLINES from FLIGHTS and FARES
INDEX
SR TOPIC PAGE SIGNATUR
No. NO. E

1 STRUCTURES

· Program to define a structure Honour

· Program define a structure Electric

2 FUNCTION OVERLOADING

· Calculate intrest using function overloading

· Calculate the area of the triangle , square , rectangle

3 CLASSES AND OBJECTS

· Create a class Bank account

· Create a class to stimulate result preparation system


for 20 students

· Program to perform various operations on a string

· Class to represent a Vector

4 CONSTRUCTORS AND DESTRUCTORS

· Define a class Travel Plan

· Define a class Outfit

5 INHERITANCE

· Program to read and display info about managers


and employees
6 DATA FILE HANDLING

· Program to calculate and display number of vowels ,


total number of spaces , total number of alphabets ,
total number of words in file

· Complete menu driven program for file


PHONE.DAT

· Menu driven program for file APPLY.DAT

· Program to read and write the objects of class


Applicant

· Menu driven programs to read , display , append and


delete records in a file

· Programs that reads lowercase letters and perform


various functions on it

· Program to read and perform various functions on


text file

· Program for copying data from file ORIG.TXT to


NEW.TXT

· menu driven program for file BUS.DAT

· menu driven program for file CAR.DAT

7 ARRAYS (USING FUNCTIONS)

· Perform various functions on two matrices

· Perform various functions on a matrix

· Implement various searches in a given program

· Illustrate differents type of sorts

· Merging two arrays into a third array

· Perform various functions on 1-D Array

· Perform various functions on 2-D Array

· Perform various functions on matrices , 1-D Array


and 2-D Array
8 LINKED LISTS , STACKS AND QUEUES

· Program implementing linked lists

· Program implementing stacks

· Program implementing Queues

· Program performinmg various functions on linked


lists

· Program performinmg various functions on stacks

· Program performinmg various functions on queues

9 SQL

· Relation Teacher

· Table Workers and Design

· Table Consignor and Consignee

· Table Flights and Fares


1

PROGRAM TO IMPLEMENT A STRUCTURE HONOUR

#include<iostream.h> //invoking reqd header files


#include<conio.h>
#include<string.h>
#include<iomanip.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
void fillarr(); //declaring all functions used.
void display();
void winner();
void max();

struct HONOUR //defining the structure


{
char name[50];
int type;
long double amt;
};
int N;
HONOUR h[100]; //array of objects

void main()
{
clrscr();
char ch;
do
{
cout<<"Enter the number of competitions conducted: ";
cin>>N; //the no of objects to be created
fillarr(); //calling all functions
display();
max();
winner();
cout<<"\n Do you wish to continue ? (Press y -yes ,n-no)? ";
cin>>ch;
}
while((ch=='y')||(ch=='Y'));
cout<<"\n THANKS ;') ";
getch();
}
void fillarr() //function to take all details from the user
{
for(int i =0; i<N;i++)
{

cout<<"\n Enter the following details of event "<<i+1;


label:
cout<<"\n Name of Position holder: ";
gets(h[i].name);
for(int j=0;h[i].name[j]!='\0';j++)
{
if(!isalpha(h[i].name[j]))
{
cout<<"\n Please enter a valid Name ";
goto label;
}
}
jump2:
cout<<"\n Position:(enter 0 if no significant pos) ";
cin>>h[i].type;
if(h[i].type<0)
{
cout<<"\n Please enter a valid Postion ";
goto jump2;
}
jump:
cout<<"\n Prize amt won(100-370000):\n";
cin>>h[i].amt;
if((h[i].amt<100)||(h[i].amt>370000))
{
cout<<"\n Please enter a valid Choice ";
goto jump;
}
}
}

void display() //function to show all the details entered


{
cout<<"\n Details entered:\n";
cout.width(15) ;
cout<<"NAME";
cout.width(15);
cout<<"POSITION ";
cout.width(15) ;
cout<<"AMOUNT WON\n";
for(int j=0;j<N;j++)
{
cout.width(15);
cout<<h[j].name;
cout.width(15);
cout<<h[j].type;
cout.width(15);
cout<<h[j].amt<<"\n";
}
}
void max()//function to show the winner with max amount
{
cout<<"\n Winner who won the maximum amount: ";
long double max=0;
char win[50];
strcpy(win,"ABC");
for(int k=0;k<N;k++)
{
if(h[k].amt>=max)
{
max=h[k].amt;
strcpy(win,h[k].name);
}
}
cout<<win;
cout<<"\n Amount won: ";
cout<<max;
}
void winner() //function to show the names of winners winning>50000 (if any)
{
cout<<"\n Winners who won amount more than 50,000:";
char ch='n';
for(int l=0;l<N;l++)
{
if(h[l].amt>50000)
{
cout<<h[l].name<<"\n";
ch='y';
}

else
continue;
}
if(ch=='n')
cout<<"N.A.";
}
PROGRAM TO IMPLEMENT A STRUCTURE ELECTRIC
//Program to calculate bill in a structure ELECTRIC
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
struct ELECTRIC //defining structure ELECTRIC
{
int CUST_No;
char Name[20];
long double unitsconsumed;
float bill;
};
void Sort(ELECTRIC e[],int n); //function for sorting
void Cbill(ELECTRIC e[],int n); //function for calculating bill
void main()
{
clrscr();
int n,i;
ELECTRIC e[20];
cout<<"\n Please enter the number of customers you want to enter details for ";
cin>>n; //Inputting information
for(i=0;i<n;i++)
{
cout<<"\n Please enter the following details for Customer ";
cout<<"\n \n Please enter the customer number: ";
cin>>e[i].CUST_No;
cout<<"\n Please enter the customer name: ";
gets(e[i].Name);
cout<<"\n Please enter the units consumed: ";
cin>>e[i].unitsconsumed;
}
char ch;
goodname: //User driven menu
cout<<"\n Please choose from the following menu ";
cout<<"\n 1) Sorting records ";
cout<<"\n 2) Calculating bill ";
cout<<"\n 3) Sorting records and Calculating bills ";
cout<<"\n 4) Exit ";
cin>>ch;
switch(ch) //Using switch case
{
case'1':
Sort(e,n);
char ch2; //Invoking functions
cout<<"\n Do you want to continue using the program...Press y for yes and n
for no ";
cin>>ch2;
if((ch2=='y')||(ch2=='Y'))
goto goodname;
else
goto goodname1;
break;

case'2':
Cbill(e,n);
char ch3;
cout<<"\n Do you want to continue using the program...Press y for yes and n
for no ";
cin>>ch3;
if((ch3=='y')||(ch3=='Y'))
goto goodname;
else
goto goodname1;
break;

case'3':
Sort(e,n);
Cbill(e,n);
char ch4;
cout<<"\n Do you want to continue using the program...Press y for yes and n
for no ";
cin>>ch4;
if((ch4=='y')||(ch4=='Y'))
goto goodname;
else
goto goodname1;
break;

case'4':
goodname1:
char ch1;
cout<<"\n Are you sure you want to exit the program ? Press Y for yes or any
key for no ";
cin>>ch1;
if((ch1=='y')||(ch1=='Y'))
exit(0);
else
{
cout<<"\n Welcome Back!! " ;
goto goodname;
}
break;

default:
cout<<"\n Please enter a valid choice ";
goto goodname;
}
getch();
}
void Sort(ELECTRIC e[], int n)
{
ELECTRIC t; //Sorting via bubble sort
for(int i=0;i<n;i++)
{
for(int j=0;j<(n-1)-i;j++)
{
if(e[j].CUST_No>e[j+1].CUST_No)
{
t=e[j+1];
e[j+1]=e[j];
e[j]=t;
}
}
}
cout<<"\n Sorted records are ";
for(i=0;i<n;i++)
{ //Displaying result
cout<<"\n Customer number: ";
cout<<e[i].CUST_No;
cout<<"\n Customer name: ";
puts(e[i].Name);
cout<<" Units consumed: ";
cout<<e[i].unitsconsumed;
}
}
void Cbill(ELECTRIC e[],int n)
{
cout<<"\n Calculating Bill "; //Calcutaion of bill
for(int i=0;i<n;i++)
{
long double amt=0.0;
if(e[i].unitsconsumed<=100)
{
amt= amt+(e[i].unitsconsumed*0.40);
}
if((e[i].unitsconsumed>100)&&(e[i].unitsconsumed<=300))
{
amt= amt+(100*0.40);
amt= amt+((e[i].unitsconsumed-100)*0.50);
}
if((e[i].unitsconsumed>300)&&(e[i].unitsconsumed<=600))
{
amt= amt+(100*0.40);
amt= amt+(200*0.50);
amt= amt+((e[i].unitsconsumed-300)*0.75);
}
if((e[i].unitsconsumed>600)&&(e[i].unitsconsumed<=1000))
{
amt= amt+(100*0.40);
amt= amt+(200*0.50);
amt= amt+(300*0.75);
amt= amt+((e[i].unitsconsumed-600)*1.00);
}
if(e[i].unitsconsumed>1000)
{
amt= amt+(100*0.40);
amt= amt+(200*0.50);
amt= amt+(300*0.75);
amt= amt+(400*1.00);
amt= amt+((e[i].unitsconsumed-1000)*1.50);
}
e[i].bill=amt;
}
cout<<"\n The Details and the bill for customer is ";
for(i=0;i<n;i++) //Displaying result
{
cout<<"\n \n Details for Customer is: ";
cout<<"\n Customer number: ";
cout<<e[i].CUST_No;
cout<<"\n Customer name: ";
puts(e[i].Name);
cout<<" Units consumed: ";
cout<<e[i].unitsconsumed;
cout<<"\n Total Amount Payable(in Rs) ";
cout<<e[i].bill;
}
}
TO CALCULATE SIMPLE INTEREST
#include<iostream.h> //invoking header files
#include<conio.h>
#include<ctype.h>
#include<process.h>
void calci(long double p,int r,int t); //all 3 parameters given by user
void calci(long double p,int t); //only principal and time period given
void calci(long double p); //only principal given
void main()
{
clrscr();
int ti,ra;
long double pr; //declaring actual parameters
char ch, ch1; //for switch and do-while respectively
do
{
cout<<"CALCULATION OF SIMPLE INTEREST\n";
cout<<"\nChoose to enter any of the following:"
<<"\n1.Only Principal Amount"
<<"\n2.Principal and time period"
<<"\n3.Principal, interest and Time Period"
<<"\n4.Exiting the program.";
cin>>ch;
switch(ch)
{
case '1': label1:
cout<<"\n Enter Principal Amount: "; //PA entered
cin>>pr;
if((pr<0)||(isalpha(pr)))
{
cout<<"\n Please enter a valid input ";
goto label1;
}
calci(pr);
break;
case '2': label2:
cout<<"\n Enter the Principal Amount: "; //PA and Time
Period entered
cin>>pr;
cout<<"\n Enter the Time Period: ";
cin>>ti;
if((ti<0)||(pr<0)||(isalpha(pr))||(isalpha(ti)))
{
cout<<"\n Please enter a valid input ";
goto label2;
}
calci(pr,ti);
break;
case '3': label3:
cout<<"\n Enter the Principal Amount: "; //all three
parameters entered
cin>>pr;
cout<<"\n Enter the Time Period: ";
cin>>ti;
cout<<"\n Enter Rate of Interest: ";
cin>>ra;

if((pr<0)||(ti<0)||(ra<0)||(isalpha(ti)||(isalpha(pr))||(isalpha(ra))))
{
cout<<"\n Please enter a valid input ";
goto label3;
}
calci(pr,ra,ti);
break;
case '4':cout<<"\n Thank you !";
exit(0);
break;
default: cout<<"\n INVALID"; //incase user enters none of 1,2,3
break;

}
cout<<"\nPress Y to continue and N to leave: ";//condition for begining again
cin>>ch1;
}
while((ch1=='y')||(ch1=='Y'));
cout<<"\nThanks a lot"; //do while ends
getch();
}
void calci(long double p,int r,int t)
{
long double si;
si=(p*r*t)/100; //by formula of SI
long double amt=si+p;
cout<<"\n The Simple interest : "<<si;
cout<<"\n Amount : "<<amt;
}
void calci(long double p,int r)
{
long double si,t=10;
si=(p*r*t)/100;
long double amt=si+p;
cout<<"\n The Simple interest( default rate:10% ): "<<si;
cout<<"\n Amount : "<<amt;
}
void calci(long double p)
{
long double si,r=10,t=10;
si=(p*r*t)/100;
long double amt=si+p;
cout<<"\n The Simple interest( default rate:10% , default time period:10yrs ): "<<si;
cout<<"\n Amount : "<<amt;
}
PRORGRAM TO CALCULATE AREA FOR VARIOUS FIGURES

#include<iostream.h> //invoking header files


#include<conio.h>
#include<ctype.h>
#include<process.h>
#include<math.h> //for sqrt()
void tri(float a,float b,float c); //defining various functions
void sqr(float a);
void rect(float a,float b);
void main() //invoking driver func
{
clrscr();
cout<<" CALCULATION OF AREA \n";
char ch,ch1; //declaring variables
float t1,t2,t3,s1,r1,r2;
do //do-while begins
{
cout<<"\n Please choose to calculate the area of: "
<<"\n 1.Triangle"
<<"\n 2.Square"
<<"\n 3.Rectangle"
<<"\n 4.Quit the program.";
cin>>ch1; //choice of the user entered
switch(ch1)
{
case '1':cout<<"\n Enter 1st side's dimension(cm): ";
cin>>t1;
cout<<"\n Enter 2nd side's dimension(cm): ";
cin>>t2;
cout<<"\n Enter 3rd side's dimension(cm): ";
cin>>t3;
tri(t1,t2,t3); //calling function for calulating ar.
break;
case '2':cout<<"\n Enter the dimension of the square's side(cm)";
cin>>s1;
sqr(s1);
break;
case '3':cout<<"\n Enter 1st side's dimension(cm): ";
cin>>r1;
cout<<"\n Enter 2nd side's dimension(cm): ";
cin>>r2;
rect(r1,r2);
break;
case '4':cout<<"\n Thank you!";
exit(0);
default: cout<<"\n INVALID"; //incase user doesnt enter a valid
input
}
cout<<"\n Press y to continue and n to leave ";
cin>>ch;
}
while((ch=='y')||(ch=='Y'));
cout<<"\nTHANK YOU";
getch();
}
void rect(float a,float b) //calculating area of a rectangle
{
float area=a*b;
cout<<"\nArea of Rectangle: "<<area<<" cm2";
}
void sqr(float a) //calculating area of a square
{
float area=a*a;
cout<<"\nArea of Square: "<<area<<" cm2";
}
void tri(float a,float b,float c) //calculating area of a triangle
{
float s=(a+b+c)/2;
float area=sqrt((s)*(s-a)*(s-b)*(s-c));
cout<<"\nArea of Triangle: "<<area<<" cm2";
}
PROGRAM TO REPRESENT A BANK ACCOUNT
//Program to represent bank account
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
#include<ctype.h>
#include<string.h>
#include<stdio.h>
class Bank //Defining Class
{
char Name[20];
int Ac_no;
char Type;
long balance;
public:
Bank() //Function to initialize data members
{
strcpy("NULL",Name);
Ac_no=1;
Type='S';
balance=1000;
}
int Retbno()
{
return Ac_no;
}
void Deposit(); //Other important functions
void Withdraw();
void Display();
};
int Lsearch( Bank b[], int ac, int n);
void Bank::Deposit() //Inputting information
{
cout<<"\n Name: ";
gets(Name);
jump:
cout<<"\n Account Number: ";
cin>>Ac_no;
if(Ac_no<=0)
{
cout<<"\n Please enter a valid Account Number: ";
goto jump;
}
jump2:
cout<<"\n Account Type('S' for Saving and 'C' for current): ";
cin>>Type;
if((Type=='s')||(Type=='S')||(Type=='c')||(Type=='C'))
{
}
else
{
cout<<"\n Please enter a valid choice ";
goto jump2;
}
jump3:
cout<<"\n Balance(in Rs) in the account: ";
cin>>balance;
if(balance<1000)
{
cout<<"\n Minimum balance should be 1000Rs. Please enter an amount above
1000Rs ";
goto jump3;
}
}
void Bank::Withdraw() //Function to withdraw money
{
double amt;
cout<<"\n Name: ";
puts(Name);
cout<<" Account Number: "<<Ac_no;
cout<<"\n Account Type: "<<Type;
jump4:
cout<<"\n Please enter the amount to be withdrawn(enter 0 if u dont want to withdraw
any money):";
cin>>amt;
if(amt<=balance)
{
cout<<"\n \t Initial Balance: "<<balance;
balance=balance-amt;
cout<<"\n \t Balance Remaining: "<<balance;
}
else
{
cout<<"\n Balance in your account is "<<balance<<". Please enter an amount
less than balance ";
goto jump4;
}
}
void Bank::Display() //Function to display details
{
cout<<"\n Name: ";
puts(Name);
cout<<" Account Number: "<<Ac_no;
cout<<"\n Account Type: "<<Type;
cout<<"\n Account Balance: "<<balance;
}
void main()
{
clrscr();
Bank b[10];
int n;
cout<<"\n Please enter the number of customers you want to deposit money for(max
10): ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Enter details for customer "<<i+1;
b[i].Deposit();
}
int ch,ac; //User driven menu
goodname:
cout<<"\n Please choose from the following options ";
cout<<"\n 1)Withdraw Money ";
cout<<"\n 2)Display Details ";
cout<<"\n 3)Exit ";
cin>>ch;
switch(ch)
{
case 1:
label1:
cout<<"\n Please enter your account number ";
cin>>ac;
i=Lsearch(b,ac,n);
if(i>=0)
b[i].Withdraw();
else
goto label1;
char ch1;
cout<<"\n Do you want to continue using the program...Press y for yes and n
for no ";
cin>>ch1;
if((ch1=='y')||(ch1=='Y'))
goto goodname;
else
goto goodname1;
break;

case 2:
label2:
cout<<"\n Please enter your account number ";
cin>>ac;
i=Lsearch(b,ac,n);
if(i>=0)
b[i].Display();
else
goto label2;
char ch2;
cout<<"\n Do you want to continue using the program...Press y for yes and n
for no ";
cin>>ch2;
if((ch2=='y')||(ch2=='Y'))
goto goodname;
else
goto goodname1;
break;
case 3:
goodname1:
char ch3;
cout<<"\n Are you sure you want to exit the program ? Press Y for yes or any
key for no ";
cin>>ch3;
if((ch3=='y')||(ch3=='Y'))
exit(0);
else
{
cout<<"\n Welcome Back!! " ;
goto goodname;
}
break;

default:
cout<<"\n Please enter a valid choice ";
goto goodname;
}
getch();
}
int Lsearch( Bank b[], int ac, int n) //Function to search in an array
{
int x;
for(int i=0;i<n;i++)
{
if(b[i].Retbno()==ac)
x=i;
}
if((x<n)&&(x>=0))
{
return x;
}
else
{cout<<"\n Please enter a valid account number ";
return -1;
}
}
PROGRAM TO IMPLEMENT RESULT PREPARATION USING
CLASSES
//Program to prepare system for calculating result
#include<conio.h>
#include<string.h>
#include<iostream.h>
#include<stdio.h>
class RESULT //Defining class
{
int rollno;
char name[20];
float marks_s1;
float marks_s2;
float marks_s3;
float avgmarks;
char grade;
public:
RESULT()
{
rollno=1;
strcpy("ABC",name);
marks_s1=0;
marks_s2=0;
marks_s3=0;
avgmarks=0;
}
void READ();
void SHOW();
void CAL();
};
void RESULT::READ() //Function to read
{
jump:
cout<<"\n Roll no: ";
cin>>rollno;
if(rollno<=0)
{
cout<<"\n Please enter a valid Roll no ";
goto jump;
}
cout<<"\n Name: ";
gets(name);
label:
cout<<" \n Marks in three subjects(each out of 100): ";
cin>>marks_s1>>marks_s2>>marks_s3;
if((marks_s1>100)||(marks_s2>100)||(marks_s3>100))
{
cout<<"\n Please enter all marks less than 100 ";
goto label;
}
CAL();
}
void RESULT::SHOW() //Function to show
{
cout<<"\n Roll no: "<<rollno;
cout<<"\n Name: ";
puts(name);
cout<<" Marks in three subjects are: "<<marks_s1<<" \t "<<marks_s2<<" \t
"<<marks_s3;
cout<<"\n Percentage Marks are: "<<avgmarks;
cout<<"\n Grade: "<<grade;
}
void RESULT::CAL() //Calculating grade
{
avgmarks=(marks_s1+marks_s2+marks_s3)/3;
if(avgmarks<50)
grade='E';
if((avgmarks>=50)&&(avgmarks<60))
grade='D';
if((avgmarks>=60)&&(avgmarks<75))
grade='C';
if((avgmarks>=75)&&(avgmarks<90))
grade='B';
if((avgmarks>=90)&&(avgmarks<100))
grade='A';
}
void main()
{ //Function main
clrscr();
char ch;
do
{
RESULT r[20];
int n;
cout<<"\n Please enter the number of students you want to calculate result for:
";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Enter details for student "<<i+1;
r[i].READ();
}
for(i=0;i<n;i++)
{
cout<<"\n Details entered for student "<<i+1<<" is ";
r[i].SHOW();
}
cout<<"\n Do you want to continue ?...Press Y for yes and N for no ";
cin>>ch;
}
while((ch=='y')||(ch=='Y'));
getch();
}
PROGRAM TO PERFORM VARIOUS OPERATION ON A STRING
USING CLASSES
//Program for a string class
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
class String //defining class
{
char ch[100];
public:
String() ////Function to initialize data members
{
strcpy(ch,"NULL");
cout<<"Ctor at work\n";
}
~String()
{
cout<<"\nDtor at work\n";
}
void READ() //Function to read the string
{
cout<<"Please enter the string\n";
gets(ch);
}
void Display() //Function to display the string
{
cout<<"\nThe entered string is:\n";
puts(ch);
}
void Reverse(); //Functions to do operations on the string
void Copy();
void Concat();

};
void String::Reverse() //Function to reverse the string
{

int len, temp;


for (len=0;ch[len]!='\0';len++);
for(int i=0,j=len-1;i<len/2;++i,--j)
{
temp=ch[i];
ch[i]=ch[j];
ch[j]=temp;
}
cout<<"The reversed string is:\n";
puts(ch);
}
void String::Copy() //Function to copy a string to another string
{
char r1a[100];
for (int i=0;ch[i]!='\0';++i)
r1a[i]=ch[i];
r1a[i]='\0';
cout<<"the copied string is\n";
puts(r1a);

}
void String::Concat() //Function to concatenate two strings
{
char a[100],b[100];
cout<<"Enter second string\n";
gets(a);
int i,j,k;
cout<<"second string is:\n";
puts(a);
for(i=0;ch[i]!='\0';++i)
{
b[i]=ch[i];
}
for(j=0,k=i;a[j]!='\0';++j,++k)
{
b[k]=a[j];
}
b[k]='\0';
cout<<"the concatenated string is:\n";
puts(b);

}
void main()

{
clrscr();
char Z;
int n;
String S; //declaring an object of string
S.READ();
S.Display();
jump:
cout<<"Enter the number for desired operation\n" //asking user to choose an
operation from the menu
<<"1. Reverse a string\n"
<<"2. Copy a string\n"
<<"3. Concatenate two strings\n"
<<"4. Exit\n";
cin>>n;
if(n==1) //if statements to execute operation accordind to user's input
{
String S1=S;
S1.Reverse();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;

}
else if(n==2)
{
S.Copy();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;
}
else if (n==3)
{
S.Concat();
cout<<"\nDo you wishto continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;

}
else if (n==4)
{ tag:
cout<<"\nDo you wish to exit? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
exit(-1);
else
{
cout<<"\nWelcome Back\n";
goto jump;
}

}
else
{
cout<<"Wrong entry, please try again\n"; //Error handling
goto jump;
}
cout<<"\nDo you wish to continue? Press Y for yes\n"; //asking user if they wish to
continue
cin>>Z;

getch();
}
PROGRAM TO PERFORM VARIOUS OPERATION ON A VECTOR
USING CLASSES

#include<iostream.h>
#include<conio.h>
#include<process.h>
class vector //defining class
{
int x;
int ar[10];
public:
void create(); //function to accept values in the vector
void Mod(); //fnction to modify an element
void large(); //function to display largest value
void Small(); //function to display smallest value
void Display(); //function to display entire vector
};
void vector::create()
{ cout<<"\nEnter the no. of elements: ";
cin>>x;
cout<<"Enter the elements: \n";
for(int i=0;i<x;++i)
cin>>ar[i];
}
void vector::Mod()
{
int z,n;
cout<<"\nEnter the element to be modified: ";
cin>>n;
cout<<"\nEnter the value you want to replace with: ";
cin>>z;
for(int q=0;q<x;++q)
{ if(ar[q]==n)
ar[q]=z;
}
}
void vector:: large()
{
int lar=ar[0];
for(int i=0;i<x;++i)
{ if(ar[i]>lar)
lar=ar[i];
}
cout<<"\nThe largest element is:\n";
cout<<lar;

}
void vector::Small()
{
int small=ar[0];
for(int i=0;i<x;i++)
{
if(ar[i]<small)
small=ar[i];
}
cout<<"\nThe smallest element is:\n";
cout<<small;
}
void vector:: Display()
{
cout<<"\nThe vector is:\n";
for(int l=0;l<x;++l)
cout<<ar[l]<<' ';
}
void main()
{ clrscr();
char Z;
int n;
vector V;
V.create(); //declaring an object of vector
jump:
cout<<"Enter the number for desired operation\n" //asking user to choose an
operation from the menu
<<"1. Modify an element\n"
<<"2. To display the largest value in vector\n"
<<"3. To display the smallest value in vector\n"
<<"4. To display the entire vector\n"
<<"5. Exit\n";
cin>>n;
if (n==1) //if statements to execute operation according to user's input
{
V.Mod();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;
}
else if (n==2)
{
V.large();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;
}
else if (n==3)
{
V.Small();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;

}
else if (n==4)
{
V.Display();
cout<<"\nDo you wish to continue? Press Y to continue and any other key to
exit\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
goto jump;
else
goto tag;
}
else if(n==5)
{
tag:
cout<<"\nDo you wish to exit? Press Y to exit and any other key to
continue\n";
cin>>Z;
if((Z=='y')||(Z=='Y'))
exit(-1);
else
{
cout<<"\nWelcome Back\n";
goto jump;
}
}
else //error handling
{
cout<<"Wrong entry, please try again\n"; //Error handling
goto jump;
}
getch();
}
PROGRAM TO IMPLEMENT CLASS TRAVELPLAN

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class TravelPlan //defining class
{
long int PlanCode; //declaring memebers
char Place[100];
int Number_of_travellers;
int Number_of_buses;
public:
TravelPlan() //Function to initialize data members
{
PlanCode=1001;
strcpy(Place,"Agra");
Number_of_travellers=5;
Number_of_buses=1;
cout<<"CTOR at work";
}
~TravelPlan() //Destructor
{
cout<<"Dtor at work\n";
}
void Newplan() //Function to take data from the user
{
cout<<"\nEnter the trip details ";
cout<<"\nEnter your Plan Code:\n";
cin>>PlanCode;
cout<<"Enter your Destination:\n";
gets(Place);
cout<<"\nEnter the number of travellers?\n";
cin>>Number_of_travellers;
Bus(); //Calling Bus
}
void Bus() //Function to calculate No. of buses required for
the trip
{
if(Number_of_travellers<20)
Number_of_buses=1;
else if(Number_of_travellers>=20 && Number_of_travellers<40)
Number_of_buses=2;
else
Number_of_buses=3;

}
void Show() //Showing the data of the trip
{
cout<<"\nThe Plan code is\n"<<PlanCode;
cout<<"\nThe Destination is:\n";
puts(Place);
cout<<"\nThe number of travellers is:\n"<<Number_of_travellers;
cout<<"\nTotal buses are:\t"<<Number_of_buses;
}
};
void main()
{
clrscr();
char ch;
do{
TravelPlan T; // declaring an object of class TravelPlan
T.Newplan();
T.Show();
cout<<"\nDo you wish to run the program again? Press Y for yes and any other key to
exit\n";
cin>>ch;
}
while((ch=='y')||(ch=='Y'));
getch();
}
PROGRAM TO IMPLEMENT A CLASS OUTFIT
//Program to calculate cost of items bought in a clothing store
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
class outfit //Defining a class
{
char ocode[15];
char otype[15];
int osize;
char ofabric[15];
float oprice;
void initprice();
public: //Access Specifier
outfit() //Constructor
{
strcpy(ocode,"Not Initialised");
strcpy(otype,"Not Initialised");
osize=0;
strcpy(ofabric,"Not Initialised");
oprice=0.0;
}
~outfit() //Destructor
{
}
float retprice()
{
return oprice;
}
void input();
void display();
};
void outfit::input() //Member Function
{
int i;
char err1='y',err2='y';
cout<<"Enter code (a string):";
gets(ocode);
t:
cout<<"Enter type:\nJacket\tTrouser\nType:";
gets(otype);
for(i=0;otype[i]!='\0';i++)
{
err1='y';
if((otype[i]<65)||((otype[i]>90)&&(otype[i]<97))||(otype[i]>122))
{
err1='n';
break;
}
}
if((strcmpi(otype,"Jacket")!=0)&&(strcmpi(otype,"Trouser")!=0))
{
cout<<"Invalid string entered.Please enter again.\n";
goto t;
}
if(err1=='n')
{
cout<<"Invalid type entered.Please enter again.\n";
goto t;
}
s:
cout<<"Enter size(28,30,32,34,36):";
cin>>osize;
if((osize!=28)&&(osize!=30)&&(osize!=32)&&(osize!=34)&&(osize!=36))
{
cout<<"Invalid size.Please enter again.\n";
goto s;
}
f:
cout<<"Enter fabric:\nDenim\tAny other\nFabric:";
gets(ofabric);
for(i=0;ofabric[i]!='\0';i++)
{
err2='y';
if((ofabric[i]<65)||((ofabric[i]>90)&&(ofabric[i]<97))||(ofabric[i]>122))
{
err2='n';
break;
}
}
if(err2=='n')
{
cout<<"Invalid fabric entered.Please enter again.\n";
goto f;
}
initprice(); //Function Call
}
void outfit::display() //Member Function
{
cout<<"Code:";
puts(ocode);
cout<<"Type:";
puts(otype);
cout<<"Size:"<<osize;
cout<<"\nFabric:";
puts(ofabric);
cout<<"Price of the entered fabric:";
cout<<oprice;
}
void outfit::initprice()
{
if((strcmpi(ofabric,"DENIM")==0))
{
if((strcmpi(otype,"trouser")==0))
{
oprice=1500;
}
if((strcmpi(otype,"jacket")==0))
{
oprice=2500;
}
}
else
{
if((strcmpi(otype,"trouser")==0))
{
oprice=1125;
}
if((strcmpi(otype,"jacket")==0))
{
oprice=1875;
}

}
}
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
int num,totalcost;
outfit o1[10];
again:
cout<<"Enter the no. of items to bought (max10):";
cin>>num;
for(int i=0;i<num;i++)
{
cout<<"Please enter the details of item "<<i+1<<":\n";
o1[i].input(); //Calling function to read data
}
for(i=0;i<num;i++)
{
totalcost+=o1[i].retprice();
cout<<"\nDisplaying Data for item "<<i+1<<":\n";
o1[i].display(); //Function call to display data
}
cout<<"\nThe total cost is:"<<totalcost;
label: //goto label
cout<<"\nDo you wish to continue? Enter Y for Yes and N for No.";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"Invalid character entered.Please enter again.\n";
goto label;
}
}while((ch=='y')||(ch=='Y'));
getch();
}
PROGRAM TO IMPLEMENT INHERITANCE OF CLASSES
//Program to inherit classes
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
class Employee
{
char Empno;
char eName[20];
char eAddress[30];
public: //Access Specifier
void eRead();
void eShow();
Employee() //Constructor
{
Empno='0';
strcpy(eName,"Not Assigned");
strcpy(eAddress,"Not Assigned");
}
};
void Employee::eRead() //Member Function
{
char err1='y';
empno:
cout<<"Employee number:";
cin>>Empno;
if((Empno<48)||(Empno>57))
{
cout<<"Invalid employee number.Please enter again.\n";
goto empno;
}
ename:
cout<<"Name:";
gets(eName);
for(int i=0;eName[i]!='\0';i++)
{
err1='y';
if((eName[i]<65)||((eName[i]>90)&&(eName[i]<97))||(eName[i]>122))
{
cout<<"Invalid string entered.Please enter again.\n";
err1='n';
break;
}
}
if(err1=='n')
{
goto ename;
}
cout<<"Address:";
gets(eAddress);
}
void Employee::eShow()
{
cout<<"Employee Number:"<<Empno;
cout<<"\nName:";
puts(eName);
cout<<"Address:";
puts(eAddress);
}
class Manager:public Employee //Inheriting publicly from Employee
{
char mName[20];
char mDepartment[30];
char mAddress[20];
public:
int empnum;
void mRead();
void mShow();
Manager()
{
strcpy(mName,"Not Assigned");
strcpy(mDepartment,"Not Assigned");
strcpy(mAddress,"Not Assigned");
}
};
void Manager::mRead()
{
cout<<"Name:";
gets(mName);
cout<<"Department:";
gets(mDepartment);
cout<<"Address:";
gets(mAddress);
cout<<"Number of employees:";
cin>>empnum;
}
void Manager::mShow() //Function to display data
{
cout<<"Name:";
puts(mName);
cout<<"Department:";
puts(mDepartment);
cout<<"Address:";
puts(mAddress);
cout<<"Number of employees:"<<empnum;
}
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
Manager M[10];
int i,j,mannum;
no:
cout<<"Please enter the number of Managers in the company:";
cin>>mannum;
if(isdigit(mannum)!=0)
{
cout<<"Invalid character.Please enter again.";
goto no;
}
for(i=0;i<mannum;i++)
{
cout<<"Please enter the details of manager "<<i+1<<":\n";
M[i].mRead(); //Function Cally
for(j=0;j<M[i].empnum;j++)
{
cout<<"Please enter the details of employee "<<j+1<<":\n";
M[i].eRead();
}
}
cout<<"\nDisplaying the data:\n";
for(i=0;i<mannum;i++)
{
cout<<"Manager "<<i+1<<":\n";
M[i].mShow();
for(j=0;j<M[i].empnum;j++)
{
cout<<"\nData of employee "<<j+1<<":\n";
M[i].eShow();
}
}
rep: //goto label
cout<<"Do you wish to continue? Enter y for yes and n for no:";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"Invalid character entered.Please enter again.\n";
goto rep;
}
}while((ch=='y')||(ch=='Y'));
getch();
PROGRAM TO PERFORM VARIOUS OPERATIONS ON TEXT FILE
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
void createfile(); //Function Prototype
void displayfile();
void vowelcheck();
void spacecount();
void alphacount();
void wordscount();
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
char choice;
cout<<"Please choose among the following:\n"<<
"1.To write to the file\n"<<
"2.To read from the file\n"<<
"3.To count the number of vowels in the file\n"<<
"4.To count the number of spaces in the file\n"<<
"5.To count the number of alphabets in the file\n"<<
"6.To count the number of words in the file\n"<<
"7.To exit\n";
again:
cin>>choice;
switch(choice)
{
case '1': createfile(); //Function Call
break;
case '2': displayfile();
break;
case '3': vowelcheck();
break;
case '4': spacecount();
break;
case '5': alphacount();
break;
case '6': wordscount();
break;
case '7': cout<<"Thank you for using the program!";
exit(0);
break;
default : cout<<"Invalid character entered. Please enter again.";
goto again;
}
label:
cout<<"\nDo you wish to continue? Enter Y for Yes and N for No.";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
goto label; //Jump statement
}while((ch=='y')||(ch=='Y'));
getch();
}
void createfile() //Function Definition
{
char str[20];
ofstream fout("text.txt");
cout<<"Please enter the data:";
gets(str);
fout<<str; //Writing in the file
cout<<"Written succesfully to the file.";
fout.close();
}
void displayfile()
{
char str[20];
ifstream fin("text.txt");
if(!fin) //Checking the existence of the file
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin>>str;
cout<<str;
}
fin.close(); //Closing the file
}
void vowelcheck()
{
char ch;
int count=0;
ifstream fin;
fin.open("text.txt");
if(!fin) //Checking the existence of a file
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(ch); //Reading from the file
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U': count++;
break;
}
}
cout<<"The no. of vowels are :"<<count;
fin.close(); //Closing the file
}
void spacecount()
{
char ch;
int count=0;
ifstream fin;
fin.open("text.txt"); //Opening the file
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(ch); //Reading character from file
if(ch==' ')
count++;
}
cout<<"The no. of spaces are :"<<count;
fin.close(); //Closing the file
}
void alphacount()
{
char ch;
int count=0;
ifstream fin;
fin.open("text.txt"); //Opening the file
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(ch); //Reading character from the file
if(((ch>=65)&&(ch<=90))||((ch>=97)&&(ch<=122)))
count++;
}
cout<<"The no. of alphabets are :"<<count;
fin.close();
}
void wordscount()
{
char ch;
int count=1; //Initialising count
ifstream fin;
fin.open("text.txt");
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(ch);
if(ch==' ')
count++;
}
cout<<"The no. of words are :"<<count; //Displaying the result
fin.close();
PROGRAM TO PERFORM VARIOUS OPERATIONS ON BINARY
FILE
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
class Phonelist //Declaring the class
{
char Name[20];
char Address[30];
char Areacode[5];
char PhoneNum[15];
public:
Phonelist() //Constructor
{
strcpy(Name,"NOT ASSIGNED");
strcpy(Address,"NOT ASSIGNED");
strcpy(Areacode,"DEL");
strcpy(PhoneNum,"Null");
}
~Phonelist() //Destructor
{
cout<<"Thank you for using the program.";
}
void Register();
void Show(); //Member Function
void Transfer();
int CheckCode(char AC[])
{
return strcmp(Areacode,AC);
}
}phone;
void Phonelist::Register()
{
cout<<"Please enter the details of the entry:\n";
name:
cout<<"Name: ";
gets(Name);
for(int i=0;Name[i]!='\0';i++)
{
if(!isalpha(Name[i]))
{
cout<<"Please enter a valid name\n";
goto name;
}
}
cout<<"Address: ";
gets(Address);
arcode:
cout<<"Area code (3 character string): ";
gets(Areacode);
for(i=0;Areacode[i]!='\0';i++)
{
if(!isalpha(Areacode[i]))
{
cout<<"Please enter a valid area code\n";
goto arcode;
}
}
num:
cout<<"Phone number (10 digit): ";
cin>>PhoneNum;
for(i=0;i<10;i++)
{
if(!isdigit(PhoneNum[i])||(PhoneNum[10]!='\0'))
{
cout<<"Please enter a valid phone number\n";
goto num;
}
}
fstream fout;
fout.open("PHONE.DAT",ios::binary|ios::out|ios::app);
if(!fout) //Checking for file existence
{
cout<<"\nThe file does not exist";
exit(-1);
}
fout.write((char*)&phone,sizeof(phone));//Writing to the file
fout.close(); //Closing the file
}
void Phonelist::Show()
{
cout<<"\nDisplaying the details: ";
cout<<"\nName: ";
puts(Name);
cout<<"Address: ";
puts(Address);
cout<<"Area code: "<<Areacode;
cout<<"\nPhone number: "<<PhoneNum<<"\n";
}
void Phonelist::Transfer()
{
fstream fin;
fin.open("PHONE.DAT",ios::binary|ios::in);
fstream fo;
fo.open("NEW_PHONE.DAT",ios::binary|ios::out);
if(!fin)
{
cout<<"\nThe file does not exist";
exit(-1);
}
while(!fin.eof())
{
fin.read((char*)&phone,sizeof(phone));
if(CheckCode("DEL")==0)
{
fo.write((char*)&phone,sizeof(phone));
}
}
fo.close();
fin.close();
}
void new_display()
{
fstream f("NEW_PHONE.dat",ios::in);
if(!f)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!f.eof())
{
f.read((char*)&phone,sizeof(phone));
phone.Show();
}
f.close();
}
void main()
{
char ch,op;
menu: //goto label
clrscr();
cout<<"Please select the option you want to choose:\n";
cout<<"1. Enter records to the file\n2. Display records from the file\n"<<
"3. To display the records of the file having areacode 'DEL'\n4. Exit\n";
cin>>op;
switch(op)
{
case '1': phone.Register(); //Function Call
phone.Transfer();
break;
case '2': ifstream fin("PHONE.dat",ios::binary);
if(!fin)
{cout<<"The file does not exist.”;
exit(-1);
}
while(!fin.eof())
{
fin.read((char*)&phone,sizeof(phone));
phone.Show();
}
fin.close();
break;
case '3': cout<<"Displaying the records:\n";
new_display();
break;
case '4': cout<<"Thank you for using the program!";
exit(0);
break;
default: cout<<"\nPlease enter a valid option.\n";
goto menu;
}
exit:
cout<<"\nDo you want to continue?[y/n]: ";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"\nPlease enter a valid option";
goto exit;
}
if((ch=='y')||(ch=='Y')) //For multiple executions
goto menu; else
cout<<"\nThank you for using the program";getch();}
PROGRAM TO PERFORM VARIOUS OPERATIONS ON BINARY
FILE APPLICANT.DAT
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<iomanip.h>
#include<ctype.h>
#include<process.h>
class Applicant //Declaring the class
{
char A_Rno[10];
char A_Name[30];
int A_Score;
public:
void Enrol() //Inline Member Function
{
cout<<"Please enter the roll no:";
cin>>A_Rno;
cout<<"Please enter the name:";
gets(A_Name);
cout<<"Please enter the score:";
cin>>A_Score;
}
void Status()
{
cout<<"\nRoll no:"<<A_Rno;
cout<<"\nName:";
puts(A_Name);
cout<<"Score:"<<setw(3)<<A_Score;
}
int return_score()
{
return A_Score;
}
}A1,A[10];
void write(); //Function Prototypes
void read();
void select();
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
char choice;
cout<<"Please choose among the following:\n"<<
"1.To write data to the file\n"<<
"2.To read data from the file\n"<<
"3.To display details of students who have scored 70+\n"<<
"4.To exit\n";
label: //goto label
cin>>choice;
switch(choice)
{
case '1': write();
break;
case '2': read(); //Function Call
break;
case '3': select();
break;
case '4': exit(0);
break;
default : cout<<"Invaild character entered.Please enter again.\n";
goto label;
}
again:
cout<<"\nDo you wish to continue ? Enter Y for Yes and N for No.";
cin>>ch;
if((toupper(ch)!='Y')&&(toupper(ch)!='N'))
{
cout<<"Invalid character entered.Please enter again.\n";
goto again;
}
}while(toupper(ch)=='Y');
getch();
}
void write() //Function Definition
{
int i,num;
ofstream fout("APPLY.DAT",ios::binary|ios::app); //Opening the file
cout<<"Please enter the number of students whose details you want to enter:";
cin>>num;
for(i=0;i<num;i++)
{
cout<<"Please enter the details of student"<<i+1<<":\n";
A[i].Enrol();
fout.write((char*)&A[i],sizeof(A[i]));
}
fout.close(); //Closing the file
}
void read()
{
ifstream fin("APPLY.DAT",ios::binary);
if(!fin) //Checking the existence of file
{
cout<<"The file does not exist.";
exit(-1);
}
cout<<"\nDisplaying the details:\n";
while(!fin.eof())
{
fin.read((char*)&A1,sizeof(A1));
A1.Status(); //Function Call
}
fin.close();
}
void select() //Function Definition
{
int pos;
fstream f("APPLY.DAT",ios::binary|ios::in);
if(!f)
{
cout<<"The file does not exist.";
exit(-1);
}
cout<<"\nDisplaying the details of students whose score is 70+:\n";
while(!f.eof())
{
f.read((char*)&A1,sizeof(A1)); //Reading from file
if(A1.return_score()>70)
{
A1.Status();
}
}
f.close(); //Closing the file
}
PROGRAM TO PERFORM VARIOUS OPERATIONS ON BINARY
FILE APPL.DAT
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
class Applicant //Declaring a class
{
char A_Rno[10];
char A_Name[20];
int A_Score;
public: //Access specifier
void Read();
void Display();
void Search();
void Modify(); //Member Function
}apl;
void Applicant::Read()
{
cout<<"Please enter all the details: ";
cout<<"\nRoll number: ";
cin>>A_Rno;
cout<<"Name: ";
gets(A_Name);
cout<<"Score: ";
cin>>A_Score;
fstream fout;
fout.open("APPL.DAT",ios::binary|ios::out|ios::app);
if(!fout) //Checking for file existence
{
cout<<"\nThe file does not exist";
exit(-1);
}
fout.write((char*)&apl,sizeof(apl));
fout.close(); //Closing the file
}
void Applicant::Display()
{
fstream fin;
fin.open("APPL.DAT",ios::binary|ios::in);
if(!fin)
{
cout<<"\nThe file does not exist";
exit(-1);
}
cout<<"Displaying the details of the records:\n";
while(!fin.eof())
{ fin.read((char*)&apl,sizeof(apl)); //Reading from the file
cout<<"\nRoll number: "<<A_Rno;
cout<<"\nName: ";
puts(A_Name);
cout<<"Score: "<<A_Score<<"\n";
}
fin.close();
}
void Applicant::Search()
{
char Rno[10],found='n';
fstream fin;
fin.open("APPL.DAT",ios::binary|ios::in); //Opening the file
if(!fin)
{
cout<<"\nThe file does not exist";
exit(-1);
}
cout<<"Enter the roll number of the entry you want to search: ";
gets(Rno);
while(!fin.eof())
{
fin.read((char*)&apl,sizeof(apl)); //Reading from the file
if(strcmpi(Rno,A_Rno)==0)
{
found='y';
cout<<"Displaying the details of the records:\n";
cout<<"\nRoll number: "<<A_Rno;
cout<<"\nName: ";
puts(A_Name);
cout<<"Score: "<<A_Score<<endl;
break;
}
}
if(found=='n')
cout<<"Record not found";
fin.close(); //Closing the file
}
void Applicant::Modify()
{
char Rno[10];
char Name[20];
int Score;
int pos;
char found='n';
fstream fio;
fio.open("APPL.DAT",ios::binary|ios::in|ios::out);
if(!fio)
{
cout<<"\nThe file does not exist";
exit(-1);
}
cout<<"Enter the roll number of the entry you want to modify: ";
gets(Rno);
while(!fio.eof())
{
fio.read((char*)&apl,sizeof(apl));
if(strcmpi(Rno,A_Rno)==0)
{
found='y';
pos=fio.tellg();
cout<<"Enter the new details";
cout<<"\nName: ";
gets(Name);
cout<<"Score: ";
cin>>Score;
strcpy(A_Name,Name);
A_Score=Score;
fio.seekg(pos-sizeof(apl));
fio.write((char*)&apl,sizeof(apl));
cout<<"\nData has been modified successfully\n";
cout<<"Displaying the details of the records:\n";
fio.seekg(ios::beg);
while(!fio.eof())
{
fio.read((char*)&apl,sizeof(apl));
cout<<"\nRoll number: "<<A_Rno;
cout<<"\nName: ";
puts(A_Name);
cout<<"Score: "<<A_Score<<endl;
}
break;
}
}
if(found=='n')
cout<<"Record not found";
fio.close(); //Closing the file
}
void main()
{
char ch;
do
{
char op;
clrscr();
menu:
cout<<"Please select the option you want to choose:\n";
cout<<"1. Enter records to the file\n2. Display records from the file\n"<<
"3. Search for a roll number\n4. Modify the entered data\n"<<
"5. Exit\n";
cin>>op;
switch(op)
{
case '1': apl.Read(); //Function Call
break;
case '2': apl.Display();
break;
case '3': apl.Search();
break;
case '4': apl.Modify();
break;
case '5': exit(0);
break;
default: cout<<"\nPlease enter a valid option.\n";
goto menu; //Jump statement
}
exit:
cout<<"\nDo you want to continue?[y/n]: ";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"\nPlease enter a valid option";
goto exit;
}
}
while((ch=='y')||(ch=='Y'));
cout<<"\nThank you for using the program";
getch();
}
PROGRAM TO READ, DISPLAY, APPEND, AND DELETE RECORDS
IN THE FILE MOVIE.DAT
#include<fstream.h>
#include<ctype.h>
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
class movie //Declaring a class
{
int movie_id;
char movie_name[20];
int no_of_seats;
int ticketcode;
int hallno;
public: //Access Specifier
movie() //Constructor
{
movie_id=0;
strcpy(movie_name,"Not Assigned");
no_of_seats=0;
ticketcode=0;
hallno=0;
}
~movie()
{
cout<<"\nThank you for using the program.";
}
void readdata(); //Member Functions
void displaydata();
void DELETE();
int getmovieid();
}M;
void movie::readdata()
{
cout<<"Enter Movie ID:";
cin>>movie_id;
cout<<"Enter Movie name:";
gets(movie_name);
cout<<"Enter no of seats:";
cin>>no_of_seats;
cout<<"Enter Ticket code:";
cin>>ticketcode;
cout<<"Enter Hall number:";
cin>>hallno;
}
void movie::displaydata()
{
cout<<"\nMovie Id:"<<movie_id;
cout<<"\nMovie name:";
puts(movie_name);
cout<<"No of seats:"<<no_of_seats;
cout<<"\nTicket Code:"<<ticketcode;
cout<<"\nHall No:"<<hallno;
}
int movie::getmovieid()
{
return(movie_id);
}
void WRITE() //To put records in the binary file MOVIE.dat
{
ofstream f("MOVIE.dat", ios::binary|ios::app);
char reply;
do
{
M.readdata();
f.write((char*)&M,sizeof(M));
rep:
cout<<"Do you wish to enter more records ? Enter Y for yes and N for no.:";
cin>>reply;
if((toupper(reply)!='Y')&&(toupper(reply)!='N'))
{
cout<<"Invalid character entered.Please enter again.";
goto rep;
}
}while(toupper(reply)=='Y');
f.close();
}
void READ() //To display records from the file MOVIE.dat
{
ifstream f("MOVIE.DAT",ios::binary);
if(!f)
{
cout<<"\nThe File does not exist!!";
exit(-1);
}
cout<<"Displaying the records:\n";
while(!f.eof())
{
f.read((char*)&M,sizeof(M));
M.displaydata();
}
f.close();
}
void movie::DELETE() //Delete a particular record as per user's wish
{
ifstream fmain("MOVIE.DAT",ios::binary);
ofstream ftemp("temp.dat",ios::binary);
int movid;
char found='n';
cout<<"Enter the movie id of the movie whose records are to be deleted:";
cin>>movid;
while(!fmain.eof())
{
fmain.read((char*)&M,sizeof(M)); //Reading from the file
if(M.getmovieid()==movid)
found='y';
else
ftemp.write((char*)&M,sizeof(M));
}
if(found=='n')
cout<<"Record not found!";
if(found=='y')
cout<<"Record successfully deleted.";
fmain.close();
ftemp.close();
remove("movie.dat");
rename("temp.dat","movie.dat");
}
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
char choice;
menu:
cout<<"MENU:\n";
cout<<"1.Append Record\n";
cout<<"2.Display all Records\n";
cout<<"3.Deletion of a Record\n";
cout<<"4.Exit\n";
cout<<"Please enter your choice:";
cin>>choice;
switch(choice)
{
case '1': WRITE();
break;
case '2': READ();
break;
case '3': M.DELETE();
break;
case '4': exit(0);
break;
default : cout<<"Invalid character entered.Please enter again.\n";
goto menu;
}
again:
cout<<"\nDo you wish to continue? Enter Y for Yes and N for No.:";
cin>>ch;
if((toupper(ch)!='Y')&&(toupper(ch)!='N'))
{
cout<<"Invalid character entered. Please enter again.";
goto again;
}
}while((toupper(ch)=='Y'));
getch();
}
4
PROGRAM TO SEGREGATE LETTERS IN A TEXT FILE
#include<fstream.h>
#include<conio.h>
#include<process.h>
void LOWER(char chr)
{
fstream fout;
fout.open("LOWER.TXT",ios::out|ios::app); //Opening a file
if(!fout) //Checking the existence of a file
{
cout<<"\nThe file does not exist";
exit(-1);
}
fout<<chr; //Writing to the file
fout.close();
}
void UPPER(char chr)
{
fstream fout;
fout.open("UPPER.TXT",ios::out|ios::app);
if(!fout)
{
cout<<"\nThe file does not exist";
exit(-1);
}
fout<<chr;
fout.close(); //Closing the file
}
void OTHERS(char chr)
{
fstream fout;
fout.open("OTHERS.TXT",ios::out|ios::app);
if(!fout)
{
cout<<"\nThe file does not exist";
exit(-1);
}
fout<<chr; //Writing to the file
fout.close();
}
void DisplayL()
{
char c;
cout<<"\nThe data in the file \"LOWER\" is:\n";
fstream fin;
fin.open("LOWER.TXT",ios::in);
if(!fin)
{
cout<<"\The file does not exist";
exit(-1);
}
while(!fin.eof())
{
fin>>c; //Reading from the file
cout<<c<<"\n";
}
fin.close(); //Closing the file
}
void DisplayU()
{
char c;
cout<<"\nThe data in the file \"UPPER\" is:\n";
fstream fin;
fin.open("UPPER.TXT",ios::in);
if(!fin) //checking the existence of a file
{
cout<<"\The file does not exist";
exit(-1);
}
while(!fin.eof())
{
fin>>c;
cout<<c<<"\n";
}
fin.close(); //Closing the file
}
void DisplayO()
{
char c;
cout<<"\nThe data in the file \"OTHERS\" is:\n";
fstream fin;
fin.open("OTHERS.TXT",ios::in); //Opening the file
if(!fin)
{
cout<<"\The file does not exist";
exit(-1);
}
while(!fin.eof())
{
fin>>c;
cout<<c<<"\n";
}
fin.close();
}
void main()
{
char ch,op,choice;
do //do while loop for multiple executions
{
clrscr();
menu:
cout<<"Please choose an option:\n"<<
"1. Enter a character\n2. Display the file \"LOWER\"\n"<<
"3. Display the file \"UPPER\"\n4. Display the file \"OTHER\"\n"<<
"5. Exit\n";
cin>>choice;
switch(choice)
{
case '1':do
{
cout<<"Enter the character(enter '0' to terminate): ";
cin>>ch;
if((ch>=65)&&(ch<=90))
LOWER(ch);
else if((ch>=97)&&(ch<=122))
UPPER(ch);
else
OTHERS(ch);
if(ch!='0')
cout<<"Character updated successfully\n";
}
while(ch!='0');
break;
case '2':DisplayL(); //Function Call
break;
case '3':DisplayU();
break;
case '4':DisplayO();
break;
case '5':exit(0);
break;
default: cout<<"Please enter a valid option\n";
goto menu;
}
exit: //goto label
cout<<"\nDo you wish to continue?[Y/N]: ";
cin>>op;
if((op!='N')&&(op!='n')&&(op!='Y')&&(op!='y'))
{
cout<<"\nPlease enter a valid option";
goto exit;
}
}
while((op=='Y')||(op=='y'));
getch();
}
5
PROGRAM TO PERFORM VARIOUS FUNCTIONS ON A TEXT FILE
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<process.h>
void createfile(); //Function Prototype
void displayfile();
void digitcount();
void alphacount();
void wordscount();
void linecount();
void spacecount();
void vowelcount();
void conscount();
void uppercount();
void lowercount();
void thecount();
void threecount();
char c,str[20];
int count;
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
int choice;
cout<<"Please choose among the following:\n"<<
"1. To write to the file\n"<<
"2. To read from the file\n"<<
"3. To count the number of digits in the file\n"<<
"4. To count the number of alphabets in the file\n"<<
"5. To count the number of words in the file\n"<<
"6. To count the number of lines in the file\n"<<
"7. To count the number of spaces in the file\n"<<
"8. To count the number of vowels in the file\n"<<
"9. To count the number of consonants in the file\n"<<
"10.To count the number of uppercase letters in the file\n"<<
"11.To count the number of lowercase letters in the file\n"<<
"12.To count the number of times 'the' occurs in the file\n"<<
"13.To count the number of all thre lettered words in the file\n"<<
"14.To exit\n";
again:
cin>>choice;
switch(choice)
{
case 1 : createfile(); //Function Call
break;
case 2 : displayfile();
break;
case 3 : digitcount();
break;
case 4 : alphacount();
break;
case 5 : wordscount();
break;
case 6 : linecount();
break;
case 7 : spacecount();
break;
case 8 : vowelcount();
break;
case 9 : conscount();
break;
case 10: uppercount();
break;
case 11: lowercount();
break;
case 12: thecount();
break;
case 13: threecount();
break;
case 14: exit(0);
break;
default: cout<<"Invalid character entered. Please enter again.";
goto again;
}
label: //goto label
cout<<"\nDo you wish to continue? Enter Y for Yes and N for No.";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
goto label; //Jump statement
}while((ch=='y')||(ch=='Y'));
getch();
}
void createfile() //Function Definition
{
ofstream fout("text.txt",ios::app);
cout<<"Please enter the data:";
gets(str);
fout<<str; //Writing in the file
cout<<"Written succesfully to the file.";
fout.close();
}
void displayfile()
{
ifstream fin("text.txt");
if(!fin) //Checking the existence of the file
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin>>str;
cout<<str;
}
fin.close(); //Closing the file
}
void digitcount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);
if((c>=48)&&(c<=57))
count++;
}
cout<<"The number of digits in the file are:"<<count;
fin.close();
}
void alphacount()
{
count=0;
ifstream fin;
fin.open("text.txt");
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);
if(((c>=65)&&(c<=90))||((c>=97)&&(c<=122)))
count++;
}
cout<<"The no. of alphabets are :"<<count;
fin.close();
}
void wordscount()
{
count=1;
ifstream fin;
fin.open("text.txt");
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);
if(c==' ')
count++;
}
cout<<"The no. of words are :"<<count;
fin.close();
}
void linecount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.getline(str,'20','.');
count++;
}
cout<<"The number of lines in the file are:"<<count;
fin.close();
}
void spacecount()
{
count=0;
ifstream fin;
fin.open("text.txt"); //Opening the file
if(!fin)
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c); //Reading character from file
if(c==' ')
count++;
}
cout<<"The no. of spaces are :"<<count;
fin.close();
}
void vowelcount()
{
count=0;
ifstream fin;
fin.open("text.txt");
if(!fin) //Checking the existence of a file
{
cout<<"File does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c); //Reading from the file
switch(c)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U': count++;
break;
}
}
cout<<"The no. of vowels are :"<<count;
fin.close();
}
void conscount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);

if((isalpha(c)==0)&&(toupper(c)!='A')&&(toupper(c)!='E')&&(toupper(c)!='I')&&(to
upper(c)!='O')&&(toupper(c)!='U'))
count++;
}
cout<<"The number of consonants in the file are:"<<count;
fin.close();
}
void uppercount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);
if((c>=65)&&(c<=90))
count++;
}
cout<<"The number of uppercase letters in the file are:"<<count;
fin.close();
}
void lowercount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin.get(c);
if((c>=97)&&(c<=122))
count++;
}
cout<<"The number of lowercase letters in the file are:"<<count;
fin.close();
}
void thecount()
{
count=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin>>str;
if(strcmpi(str,"the")==0)
count++;
}
cout<<"The number of times 'the' occurs in the file are:"<<count;
fin.close();
}
void threecount()
{
count=0;
int len=0;
ifstream fin("text.txt");
if(!fin)
{
cout<<"The file does not exist.";
exit(-1);
}
while(!fin.eof())
{
fin>>str;
len=strlen(str);
if(len==3)
count++;
}
cout<<"The number of three lettered words in the file are:"<<count;
fin.close();
}
PROGRAM TO REPLACE CONSECUTIVE SPACES BY A SINGLE
SPACE IN A TEXT FILE
//Program to read a text file and create another text file by
//replacing a sequence of 2 consective space by a single space
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
void create();
void display(); //Function Prototype
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
char choice;
menu: //goto label
cout<<"Please choose from the following:\n"<<
"1.To append data to the ORIG file.\n"<<
"2.To display the ORIG and NEW file.\n"<<
"3.To exit.\n";
cin>>choice;
switch(choice)
{
case '1' : create(); //Function Call
break;
case '2' : display();
break;
case '3' : cout<<"Thank you for using the program!";
exit(0);
default : cout<<"Invalid character entered.Please enter again.\n";
goto menu;
}
again:
cout<<"\nDo you wish to continue? Please enter Y for Yes and N for No:";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"Invalid character entered!Please enter again.\n";
goto again;
}
}while((ch=='y')||(ch=='Y'));
getch();
}
void create() //Function Definition
{
char str[20],c,x;
ofstream fout("ORIG.TXT",ios::app);
cout<<"Please enter the data:";
gets(str);
fout<<str; //Writing to the file
fout.close();
ifstream fin("ORIG.TXT");
ofstream fo("NEW.TXT"); //Opening the file
while(!fin.eof())
{
fin.get(c);
if(c==' ')
{
fin.get(x);
if(x==' ')
fo<<' ';
else
{
fin.seekg(-1,ios::cur);
fo<<c;
}
}
else
fo<<c;
}
fin.close();
fo.close(); //Closing the file
}
void display()
{
ifstream f;
char c;
f.open("ORIG.TXT"); //Opening the file
if(!f)
{
cout<<"The file does not exist.";
exit(-1);
}
cout<<"\nDisplaying the ORIG file:\n";
while(!f.eof())
{
f.get(c); //Reading from the file
cout<<c;
}
f.close();
f.open("NEW.TXT");
cout<<"\nDisplaying the NEW file:\n";
while(!f.eof())
{
f.get(c);
cout<<c;
}
f.close();
}
PROGRAM TO PERFORM VARIOUS FUNCTIONS ON A BINARY
FILE BUS.DAT
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class BUS
{
int Bus_No;
char Destination[15];
float Distance;
public:
void ENTER()
{
cout<<"\n\t\t ENTER THE DETAILS OF THE BUS"<<endl;
cout<<"\n\t ENTER THE BUS NUMBER :";
cin>>Bus_No;
cout<<"\n\t ENTER THE DESTINATION :";
gets(Destination);
cout<<"\n\tENTER THE DISTANCE :";
cin>>Distance;
SHOW();
}
void SHOW()
{
cout<<"\n\t\t BUS DETAILS "<<endl;
cout<<"\n\t THE BUS NUMBER IS :"<<Bus_No;
cout<<"\n\t THE DESTINATION IS :";
puts(Destination);
cout<<"\t THE DISTANCE TO BE TRAVELLED IS :"<<Distance;
}
void WRITE(BUS b1)
{
ofstream fout;
fout.open("BUS.dat",ios::binary|ios::app);
fout.write((char*)&b1,sizeof(b1));
fout.close();
}
void READ();
int getbusno()
{
return Bus_No;
}
void UPDATE();
};
void BUS::READ()
{
BUS B;
ifstream fin;
fin.open("BUS.dat",ios::binary);
if(!fin)
{
cout<<"\n\t THE FILE DOESNOT EXISTS :";
exit(-1);
}
while( fin.read((char*)&B,sizeof(B)))
{
B.SHOW();
getch();
}
}
void BUS::UPDATE()
{
BUS b1;
fstream f;
f.open("BUS.dat",ios::binary|ios::in|ios::out);
if(!f)
{
cout<<"\n\t THE FILE DOESNOT EXISTS !!!";
exit(-1);
}
int busno,found=0;
cout<<"\n\t ENTER THE BUS NUMBER WHOSE INFORMATION
IS TO BE UPDATED :";
cin>>busno;
while(f.read((char*)&b1,sizeof(b1)))
{
if(b1.getbusno()==busno)
{
found=1;
cout<<"\n\t ENTER THE NEW DATA :"<<endl;
b1.ENTER();
f.seekg(-1*sizeof(b1),ios::cur);
f.write((char*)&b1,sizeof(b1));
f.close();
break;
}
}
if(found==1)
{
cout<<"\n\t RECORD FOUND !!!!"<<endl;
f.seekg(0);
cout<<"\n\t NOW THE FILE CONTAINS :";
while(!f.eof())
{
f.read((char*)&b1,sizeof(b1));
b1.SHOW();
getch();
}
f.close();
}
else
{
cout<<"\n\t THE RECORD IS NOT FOUND";
}
}
void main()
{
clrscr();
BUS b1;
int ch;
cout<<"\n\t\tBUS SERVICES"<<endl;
cout<<"\n\t1.Enter details";
cout<<"\n\t2.Show Records";
cout<<"\n\t3.Update Records";
re:
cout<<"\n\n\tEnter your input: ";
cin>>ch;
switch(ch)
{
case 1: b1.ENTER();
b1.WRITE(b1);
break;
case 2: b1.READ();
break;
case 3: b1.UPDATE();
break;
default: cout<<"\n\tWrong Input!"<<endl;
goto re;
}
getch();
}
PROGRAM TO PERFORM VARIOS FUNCTIONS ON A BINARY FILE
BUS.DAT

#include<fstream.h>
#include<process.h>
#include<conio.h>
#include<stdio.h>
class CAR
{
int CAR_NO;
char Destination[15];
float Distance;
public:
void DELETE();
void READ();
void WRITE();
void ENTER()
{
cout<<"\nEnter The Car Number: ";
cin>>CAR_NO;
cout<<"Enter The Destination: ";
gets(Destination);
cout<<"Enter Distance: ";
cin>>Distance;
}
void SHOW()
{
cout<<"\nCar Number: ";
cout<<CAR_NO;
cout<<"\nDestination: ";
puts(Destination);
cout<<"Distance: ";
cout<<Distance<<endl;
}
int ReturnCN()
{
return CAR_NO;
}
};
void CAR::READ()
{
CAR C;
ifstream fin;
fin.open("CAR.dat",ios::binary);
if(!fin)
{
cout<<"\nFile Does Not Exist ";
exit(-1);
}

while(fin.read((char*)&C,sizeof(C)))
{
C.SHOW();
cout<<"\nPress any key to view more"<<endl;
getch();
}
if(fin.eof())
cout<<"\n*End of file reached*";
fin.close();
}
void CAR::WRITE()
{
CAR C;
ofstream fout;
fout.open("CAR.dat",ios::binary|ios::app);
C.ENTER();
fout.write((char*)&C,sizeof(C));
fout.close();
}
void CAR::DELETE()
{
CAR C;
int cno;
char ans,found='f';
cout<<"\nEnter The Car No whose data is to be deleted: ";
cin>>cno;
ifstream fin("CAR.dat",ios::binary);
ofstream fout("TEMP.dat",ios::binary);
if(!fin)
{
cout<<"\nFile Does Not Exist ";
exit(-1);
}
while(fin.read((char*)&C,sizeof(C)))
{
if(C.ReturnCN()==cno)
{
found='t';
cout<<"\nData which is to be deleted ";
C.SHOW();
cout<<"\nAre you sure you want to delete ";
cin>>ans;
if(ans=='n')
fout.write((char*)&C,sizeof(C));
}
else
fout.write((char*)&C,sizeof(C));
}
if(found=='f')
cout<<"\nData was not found ";
fin.close();
fout.close();
remove("CAR.dat");
rename("TEMP.dat","CAR.dat");
fin.open("CAR.dat",ios::binary);
cout<<"\nNow the file contains: ";
while(fin.read((char*)&C,sizeof(C)))
{
C.SHOW();
}
fin.close();
}
void main()
{
clrscr();
int ans;
char ch;
CAR C;
do
{
cout<<"\n\t\t\t***CAR MENU***"<<endl;
cout<<"\n1)Write the data onto the file ";
cout<<"\n2)Read the data and show its contents ";
cout<<"\n3)Delete the record ";
cout<<"\n\nEnter your input: ";
cin>>ans;
switch(ans)
{
case 1: cout<<"\nEnter the details: "<<endl;
C.WRITE();
break;
case 2: cout<<"\nThe file contains: "<<endl;
C.READ();
break;
case 3: C.DELETE();
break;
default:cout<<"\nWrong Option\b";
}
cout<<"\n\n\tDo you want to continue?(y/n): ";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
getch();
}
PROGRAM TO PERFORM VARIOUS OPERATIONS ON MATRICES

#include<iostream.h>
#include<conio.h>#include<stdlib.h>
void add(int mat[10][10],int mat2[10][10],int ro1,int col1); //Function Prototypes
void sub(int mat[10][10],int mat2[10][10],int row1,int col1);
void prod(int mat[10][10],int mat2[10][10],int row1,int col1);
void main() //Main begins
{
int mat[10][10],mat2[10][10],col1,col2,row1,row2,i,j,k,l; //Variable Declarations
char choice,ch;
do
{
clrscr();
menu:
cout<<"The menu is:"
<<"\n1.Addition "
<<"\n2.Subtraction "
<<"\n3.Multiplication "
<<"\n4.Exit"
<<"\nEnter choice:";
cin>>choice; //Display Menu and Take Choice with Switch Case
switch(choice)
{
case '1': cout<<"Please enter the number of rows and columns in
matrix 1 respectively:\n"; //Matrix Row column Input
cin>>row1>>col1;
cout<<"Please enter the number of rows and columns in
matrix 2 respectively:\n";
cin>>row2>>col2;
if((row1!=row2)||(col1!=col2)) //Checking compatibility
{
cout<<"The matrices cannot be added.";
break;
}
cout<<"Please enter elements of matrix 1:\n";
for(i=0;i<row1;i++) //Matrix 1 Input loop
{
for(j=0;j<col1;j++)
{
cin>>mat[i][j];
}
}
cout<<"Please enter elements of matrix 2:\n";
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
cin>>mat2[i][j];
}
}
add(mat,mat2,row1,col1); //Function Call
break;
case '2': cout<<"Please enter the number of rows and columns in
matrix 1 respectively:\n"; //Matrix Row column Input
cin>>row1>>col1;
cout<<"Please enter the number of rows and columns in
matrix 2 respectively:\n";
cin>>row2>>col2;
if((row1!=row2)||(col1!=col2))
{
cout<<"The matrices cannot be subtracted.";
break;
}
cout<<"Please enter elements of matrix 1:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
cin>>mat[i][j];
}
}
cout<<"Please enter elements of matrix 2:\n";
for(i=0;i<row2;i++) //Reading values of matrix 2
{
for(j=0;j<col2;j++)
{
cin>>mat2[i][j];
}
}
sub(mat,mat2,row1,col1);
break;
case '3': cout<<"Please enter the number of rows and columns in
matrix 1 respectively:\n"; //Matrix Row column Input
cin>>row1>>col1;
cout<<"Please enter the number of rows and columns in
matrix 2 respectively:\n";
cin>>row2>>col2;
if((row1!=row2)||(col1!=col2))
{
cout<<"The matrices cannot be multiplied.";
break;
}
cout<<"Please enter elements of matrix 1:\n";
for(i=0;i<row1;i++) //Reading values of matrix 1
{
for(j=0;j<col1;j++)
{
cin>>mat[i][j];
}
}
cout<<"Please enter elements of second matrix:\n";
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
cin>>mat2[i][j];
}
}
prod(mat,mat2,row1,col1); //Function call
break;
case '4': cout<<"\nThank you for using the program!";
exit(0);
break;
default : cout<<"Invalid character entered.Please enter again.";
goto menu;
}
again:
cout<<"\nDo you want to continue? Enter y for yes and n for no:";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"Invalid character entered.Please enter again.";
goto again;
}
}
while((ch=='y')||(ch=='Y'));
cout<<"\nTHANK YOU FOR USING THE PROGRAM!";
getch();
}
void add(int mat[10][10], int mat2[10][10], int row1, int col1) //Function Definition
{
int i,j,mat3[10][10];
for(i=0;i<row1;i++)
{ //Loop to add matrices
for(j=0;j<col1;j++)
{
mat3[i][j]=mat[i][j]+mat2[i][j];
}
cout<<"\n";
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat[i][j]<<"\t";
cout<<"\n";
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Displaying the added matrix:\n";
for(i=0;i<row1;i++)
{ //Loop to display the added matrix
for(j=0;j<col1;j++)
cout<<mat3[i][j]<<"\t";
cout<<"\n";
}
}
void sub(int mat[10][10],int mat2[10][10],int row1,int col1)
{
int i,j,mat3[10][10];
for(i=0;i<row1;i++)
{ //Loop to subtract matrices
for(j=0;j<col1;j++)
{
mat3[i][j]=mat[i][j]-mat2[i][j];
}
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat[i][j]<<"\t";
cout<<"\n";
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Displaying the subtracted matrix:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat3[i][j]<<"\t";
cout<<"\n";
}
}
void prod(int mat[10][10],int mat2[10][10],int row1,int col1)
{
int i,j,mat3[10][10];
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
mat3[i][j]=mat[i][j]*mat2[i][j];
}
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat[i][j]<<"\t";
cout<<"\n";
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Dipslaying the multiplied matrix:\n";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
cout<<mat3[i][j]<<"\t";
cout<<"\n";
}
}
PROGRAM TO PERFORM VARIOUS OPERATIONS ON A MATRIX
/*PROGRAM TO OPERATE ON A MATRIX*/
#include<iostream.h>
#include<conio.h>
#include<process.h>
void TRANSPOSE(int[][20],int,int); //Function Prototype
void SUMR(int[][20],int,int);
void SUMC(int[][20],int,int);
void diagonal(int arr[][20],int r1,int c1);
void SUMBELOW(int[][20],int,int);
void SUMABOVE(int[][20],int,int);
void main()
{
char ch;
do //do while loop for multiple executions
{
clrscr();
int A[20][20],r,c,i,j,choice;
menu:
cout<<"\n\t\t\t\tMATRIX MENU : \n";
cout<<"\n1.To transpose a matrix"
<<"\n2.Find row sum"
<<"\n3.Find column sum"
<<"\n4.Find sum of the diagonal elements"
<<"\n5.Find sum of elements below main diagonal"
<<"\n6.Find sum of elements above main diagonal"
<<"\n7.Exit";
cout<<"\nPlease enter your choice:";
cin>>choice;
if((choice<1)||(choice>7))
{
cout<<"\nInvalid choice! Please enter a valid choice.";
goto menu;
}
if(choice==7)
{
cout<<"Thank you for using the program!";
exit(0);
}
cout<<"Please enter the number of rows and columns in the matrix:\n";
cin>>r>>c;
cout<<"Please enter the elements of the matrix:\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cin>>A[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
switch(choice)
{
case 1 : TRANSPOSE(A,r,c);
break;
case 2 : SUMR(A,r,c);
break;
case 3 : SUMC(A,r,c);
break;
case 4 : if(r!=c)
{
cout<<"No diagonal elements present.";
break;
}
diagonal(A,r,c);
break;
case 5 : SUMBELOW(A,r,c);
break;
case 6 : SUMABOVE(A,r,c);
break;
default: ;
}
again:
cout<<"\nDo you wish to continue? <y/n> ";
cin>>ch;
if((ch!='y')&&(ch!='Y')&&(ch!='n')&&(ch!='N'))
{
cout<<"Invalid character entered.Please enter again.";
goto again;
}
}
while((ch=='y')||(ch=='Y'));
cout<<"THANK YOU FOR USING THE PROGRAM!";
}
void TRANSPOSE(int A[20][20],int m,int n)
{
int i,j;
cout<<"\nTranspose of matrix is:\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[j][i]<<"\t";
cout<<"\n";
}
}
void SUMR(int A[20][20],int m,int n)
{
int i,j,sum=0;
for(i=0;i<m;i++)
{
sum=0;
for(j=0;j<n;j++)
sum+=A[i][j];
cout<<"\nSum of elements of row"<<i+1<<" is:"<<sum;
}
}
void SUMC(int A[20][20],int m,int n)
{
int i,j,sum=0;
for(j=0;j<n;j++)
{
sum=0;
for(i=0;i<m;i++)
sum+=A[i][j];
cout<<"\nSum of elements of column"<<j+1<<" is:"<<sum;
}
}
void diagonal(int A[20][20],int m,int n)
{
int i,j,sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i==j)||(i==m-j-1))
sum+=A[i][j];
}
}
cout<<"The sum of diagonal elements is:"<<sum;
}
void SUMBELOW(int A[20][20],int m,int n)
{
int i,j,sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
sum+=A[i][j];
}
}
cout<<"\nSum of elements below the main diagonal="<<sum;
}
void SUMABOVE(int A[20][20],int m,int n)
{
int i,j,sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i<j)
sum+=A[i][j];
}
}
cout<<"\nSum of elements above the main diagonal="<<sum;
}
PROGRAM TO ILLUSTRATE THE TWO TYPES OF SEARCHES ON
AN INTERGER ARRAY
/*PROGRAM TO PERFORM LINEAR AND BINARY SEARCH*/
#include<process.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int Lsearch(int[],int,int); /*FUNCTION PROTOTYPE*/
int Bsearch(int[],int,int);
void main()
{
int ch;
char choice;
int ARR[10],i,j,k,found;
clrscr();
do
{
cout<<"CHOOSE:1.LINEAR SEARCH"
<< "\n2.BINARY SEARCH"
<<"\n3.Exit\n";
cin>>ch;
cout<<"\nHow many elements do you want to enter?";
cin>>i;
cout<<"Enter elements of array:";
for(j=0;j<i;j++)
{
cin>>ARR[j];
}
cout<<"Which element do you want to find?";
cin>>k;
switch(ch)
{
case 1: found=Lsearch(ARR,i,k); /*FUNCTION CALL*/
if(found==-1)
cout<<"\nYour element was not found.";
else
cout<<"\nElement found at position:"<<found+1;
break;
case 2:found=Bsearch(ARR,i,k);
if(found==-1)
cout<<"\nYour element was not found";
else
cout<<"\nElement found at position:"<<found+1;
break;
case 3: cout<<"THANK YOU;')";
exit(-1);
default:cout<<"INVALID";
}
cout<<"\nDo you wish to continue? (PRESS Y/y )";
cin>>choice;
}
while((choice=='y')||(choice=='Y'));
cout<<"THANKS";
getch();
}
int Lsearch(int ARR[],int size,int it) /*FUNCTION DEFINITION*/
{
for(int p=0;p<size;p++)
{
if(ARR[p]==it)
return p;
}
return -1;
}
int Bsearch(int ARR[],int size,int it)
{
int beg,last,mid;
beg=0;last=size-1;
while(beg<=last)
{
mid=(beg+last)/2;
if(it==ARR[mid])
return(mid);
else if(it>ARR[mid])
beg=mid+1;
else
last=mid-1;
}
return(-1);
}
PROGRAM TO ILLUSTRATE THE THREE TYPES OF SORTS ON AN ARRAY

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

void InsertionSort(int MAT[],int a); //Function Prototypes


void SelectionSort(int MAT[],int a);
void BubbleSort(int MAT[],int a);

void main()
{
clrscr();
char ch;
int ARR[50],size,n;
do //do while loop
{
cout<<"Enter number of elements:\n";
cin>>size;
cout<<"\nWhich type of sorting technique do you want?\n"
//MENU
<<"1)Insertion Sort\n"
<<"2)Selection Sort\n"
<<"3)Bubble Sort\n"
<<"4)Exit";
cout<<"\nPlease enter your choice \t: ";
cin>>n;
cout<<"\n";
switch(n)
{
case 1:
cout<<"You have selected Insertion Sort";
cout<<"\n\nEnter the elements:\n";
for(int i=0;i<size;i++)
cin>>ARR[i];
InsertionSort(ARR,size); //Function call
break;

case 2:
cout<<"You have selected Selection Sort";
cout<<"\n\nEnter the elements:\n";
for(i=0;i<size;i++)
cin>>ARR[i];
SelectionSort(ARR,size); //Function call
break;

case 3:
cout<<"You have selected Bubble Sort";
cout<<"\n\nEnter the elements:\n";
for(i=0;i<size;i++)
cin>>ARR[i];
BubbleSort(ARR,size); //Function call
break;
case 4:
exit(0);
break;

default:cout<<"Wrong choice..kindly enter a number


form 1 to 4\n";

cout<<"\nDo you want to try again?PRESS Y for yes and N for no


\n";
cin>>ch;

}while((ch=='y')||(ch=='Y'));
cout<<"\nThank you for using the program";
getch();
}

void InsertionSort(int MAT[],int a) //Insertion sort


{

int l,j,k,temp,MAT1[100];
cout<<"\n\nSteps followed in this sort \nInitial array :";
for(int p=0;p<a;p++)
{ cout<<MAT[p]<<" "; }

for(l=1;l<a;l++)
{
temp=MAT[l];
j=l-1;
while((temp<MAT[j])&&(j>=0))
{
MAT[j+1]=MAT[j];
j--;
}

MAT[j+1]=temp;

for(k=0;k<a;k++)
MAT1[k]=MAT[k];
cout<<" \nStep "<<l<<" : ";
for( p=0;p<a;p++)
{ cout<<MAT1[p]<<" "; }
cout<<endl<<endl;
}
cout<<"\nASCENDING ORDER:\n"; //To display array in ascending
for(k=0;k<a;k++)
cout<<MAT1[k]<<"\t";
cout<<"\nDESCENDING ORDER:\n"; //To display array in descending
for(k=a-1;k>=0;k--)
cout<<MAT1[k]<<"\t";
}
void SelectionSort(int MAT[],int a) //Selection sort
{
int j,k,small,pos,temp,MAT2[50];
cout<<"\n\nSteps followed in this sort \nInitial array :";
for(int p=0;p<a;p++)
{ cout<<MAT[p]<<" "; }
for(j=0;j<a-1;j++)
{
small=MAT[j];
pos=j;
for(k=j+1;k<a;k++)
{
if(MAT[k]<small)
{
small=MAT[k];
pos=k;
}
}
temp=MAT[j];
MAT[j]=MAT[pos];
MAT[pos]=temp;
for(k=0;k<a;k++)
MAT2[k]=MAT[k];
cout<<"\n Step "<<j+1<<" : ";
for(int p=0;p<a;p++)
{ cout<<MAT2[p]<<" "; }
cout<<endl<<endl;
}
cout<<"\nASCENDING ORDER:\n"; //To display array in ascending
for(k=0;k<a;k++)
cout<<MAT2[k]<<"\t";
cout<<"\nDESCENDING ORDER:\n"; //To display array in descending
for(k=a-1;k>=0;k--)
cout<<MAT2[k]<<"\t";
}
void BubbleSort(int MAT[],int a) //Bubble sort
{
int temp,j,k,MAT3[50];
cout<<"\n\nSteps followed in this sort \nInitial array :";
for(int p=0;p<a;p++)
{ cout<<MAT[p]<<" "; }

for(j=0;j<a-1;j++)
{
for(k=0;k<a-1;k++)
{
if(MAT[k]>MAT[k+1])
{
temp=MAT[k];
MAT[k]=MAT[k+1];
MAT[k+1]=temp;
}
}
for(int l=0;l<a;l++)
MAT3[l]=MAT[l];
cout<<"\n Step "<<j+1<<" : ";
for(int p=0;p<a;p++)
{ cout<<MAT3[p]<<" "; }
cout<<endl<<endl;
}

cout<<"\nASCENDING ORDER:\n"; //To display array in ascending


for(k=0;k<a;k++)
cout<<MAT3[k]<<"\t";
cout<<"\nDESCENDING ORDER:\n"; //To display array in descending
for(k=a-1;k>=0;k--)
cout<<MAT3[k]<<"\t";
}
OUTPUTS
PROGRAM TO MERGE TWO GIVEN ARRAYS INTO A THIRD
ARRAY
#include<iostream.h>
#include<conio.h>
#include<process.h>

void AAcombination(int MAT1[],int MAT2[],int a1,int a2); //Function


Protoyping
void ADcombination(int MAT1[],int MAT2[],int a1,int a2); //Function
Protoyping
void DAcombination(int MAT1[],int MAT2[],int a1,int a2); //Function
Protoyping
void DDcombination(int MAT1[],int MAT2[],int a1,int a2); //Function
Protoyping

void main()
{
clrscr();
char ch;
int ARR1[50],ARR2[50],size1,size2,i,l;
do //do while loop
{
cout<<"\nEnter size of Array-1:\n"; //asking user to enter
both the arrays
cin>>size1;
cout<<"\nEnter elements of Array-1:\n";
for(i=0;i<size1;i++)
cin>>ARR1[i];
cout<<"\nEnter size of Array-2:\n";
cin>>size2;
cout<<"\nEnter elements of Array-2:\n";
for(i=0;i<size2;i++)
cin>>ARR2[i];
cout<<"\nARRAY-1: ";
for(i=0;i<size1;i++)
cout<<ARR1[i]<<" ";
cout<<"\nARRAY-2: ";
for(i=0;i<size2;i++)
cout<<ARR2[i]<<" ";
cout<<"\nChoose a type of combination:\n" //Menu
<<"1)Ascending-Ascending\n"
<<"2)Ascending-Descending\n"
<<"3)Descending-Ascending\n"
<<"4)Descending-Descending\n"
<<"5)Exit\n";
cout<<"Please enter your choice: \t ";
cin>>l;
switch(l)
{
case 1:
cout<<"\nYou Have selected Ascending-Ascending option";
AAcombination(ARR1,ARR2,size1,size2);
break;
case 2:
cout<<"\nYou Have selected Ascending-Descending
option";
ADcombination(ARR1,ARR2,size1,size2);
break;
case 3:
cout<<"\nYou Have selected Descending-Ascending
option";
DAcombination(ARR1,ARR2,size1,size2);
break;
case 4:
cout<<"\nYou Have selected Descending-Descending
option";
DDcombination(ARR1,ARR2,size1,size2);
break;
case 5:exit(0);
break;
default:cout<<"Wrong choice.....Kindly enter from 1 to 5\n";
}
cout<<"\nDo you want to continue?Press y for yes and n for
no\n";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
cout<<"\nThankyou";
getch();
}

void AAcombination(int MAT1[],int MAT2[],int a1,int a2) //Function


defination
{
int A1[50],A2[50],R[50];
int j,k,l,temp;
for(j=0;j<a1;j++)
{
for(l=0;l<a1-1;l++)
{
if(MAT1[l]>MAT1[l+1])
{
temp=MAT1[l];
MAT1[l]=MAT1[l+1];
MAT1[l+1]=temp;
}
}
for(k=0;k<a1;k++)
A1[k]=MAT1[k];
}

for(j=0;j<a2;j++)
{
for(l=0;l<a2-1;l++)
{
if(MAT2[l]>MAT2[l+1])
{
temp=MAT2[l];
MAT2[l]=MAT2[l+1];
MAT2[l+1]=temp;
}
}
for(k=0;k<a2;k++)
A2[k]=MAT2[k];
}
for(l=0,k=0;l<a1;l++,k++)
R[k]=A1[l];
for(j=0;j<a2;j++,k++)
R[k]=A2[j];
cout<<"\nNew Array:\n"; //displaying the merged array
for(k=0;k<(a1+a2);k++)
cout<<R[k]<<" ";

void ADcombination(int MAT1[],int MAT2[],int a1,int a2) //Function


defination
{
int A1[50],A2[50],R[50];
int j,k,l,temp;
for(j=0;j<a1;j++)
{
for(l=0;l<a1-1;l++)
{
if(MAT1[l]>MAT1[l+1])
{
temp=MAT1[l];
MAT1[l]=MAT1[l+1];
MAT1[l+1]=temp;
}
}
for(k=0;k<a1;k++)
A1[k]=MAT1[k];
}

for(j=0;j<a2;j++)
{
for(l=0;l<a2-1;l++)
{
if(MAT2[l]>MAT2[l+1])
{
temp=MAT2[l];
MAT2[l]=MAT2[l+1];
MAT2[l+1]=temp;
}
}
for(k=0;k<a2;k++)
A2[k]=MAT2[k];
}
for(l=0,k=0;l<a1;l++,k++)
R[k]=A1[l];
for(j=a2-1;j>=0;j--,k++)
R[k]=A2[j];
cout<<"\nNew Array:\n"; //displaying merged array
for(k=0;k<(a1+a2);k++)
cout<<R[k]<<" ";

void DAcombination(int MAT1[],int MAT2[],int a1,int a2) //Function


defination
{
int A1[50],A2[50],R[50];
int j,k,l,temp;
for(j=0;j<a1;j++)
{
for(l=0;l<a1-1;l++)
{
if(MAT1[l]>MAT1[l+1])
{
temp=MAT1[l];
MAT1[l]=MAT1[l+1];
MAT1[l+1]=temp;
}
}
for(k=0;k<a1;k++)
A1[k]=MAT1[k];
}
for(j=0;j<a2;j++)
{
for(l=0;l<a2-1;l++)
{
if(MAT2[l]>MAT2[l+1])
{
temp=MAT2[l];
MAT2[l]=MAT2[l+1];
MAT2[l+1]=temp;
}
}
for(k=0;k<a2;k++)
A2[k]=MAT2[k];
}
for(l=a1-1,k=0;l>=0;l--,k++)
R[k]=A1[l];
for(j=0;j<a2;j++,k++)
R[k]=A2[j];
cout<<"\nNew Array:\n"; //displaying merged array
for(k=0;k<(a1+a2);k++)
cout<<R[k]<<" ";

void DDcombination(int MAT1[],int MAT2[],int a1,int a2) //Function


defination
{
int A1[50],A2[50],R[50];
int j,k,l,temp;
for(j=0;j<a1;j++)
{
for(l=0;l<a1-1;l++)
{
if(MAT1[l]>MAT1[l+1])
{
temp=MAT1[l];
MAT1[l]=MAT1[l+1];
MAT1[l+1]=temp;
}
}
for(k=0;k<a1;k++)
A1[k]=MAT1[k];
}

for(j=0;j<a2;j++)
{
for(l=0;l<a2-1;l++)
{
if(MAT2[l]>MAT2[l+1])
{

temp=MAT2[l];
MAT2[l]=MAT2[l+1];
MAT2[l+1]=temp;
}
}
for(k=0;k<a2;k++)
A2[k]=MAT2[k];
}
for(l=a1-1,k=0;l>=0;l--,k++)
R[k]=A1[l];
for(j=a2-1;j>=0;j--,k++)
R[k]=A2[j];
cout<<"\nNew Array:\n"; //Displaying merged array
for(k=0;k<(a1+a2);k++)
cout<<R[k]<<" ";

}
OUTPUTS
PROGRAM TO PERFORM VARIOUS FUNCTIONS ON ARRAY
//Program to perform various functions on ARRAY
#include<iostream.h>
#include<conio.h>
#include<process.h>
void PAIRS(int ARRAY[], int n); //Function Prototype
void ODD(int ARRAY[], int n);
void EVEN(int ARRAY[], int n);
void DIVBY30(int ARRAY[], int n);
void LARGEST(int ARRAY[], int n);
void SMALLEST(int ARRAY[], int n);
void AVERAGE(int ARRAY[], int n);
void main()
{
int n,i,choice;
char ch;
int ARRAY[20];
AGAIN: //goto label
clrscr();
menu:
cout<<"Welcome to the program. Please select a required function.\n"<<
"1. Find pairs of integers stored in ARRAY having sum equal to 50.\n"<<
"2. Find the number of elements which are odd.\n"<<
"3. Find the number of elements which are even.\n"<<
"4. Find the number of elements which are divisible by 30.\n"<<
"5. Find the largest of all elements.\n"<<
"6. Find the smallest of all elements.\n"<<
"7. Find the average of all elements.\n"<<
"8. Exit.\n";
cout<<"Please enter your choice.(Number corresponding).\n";
cin>>choice;
if(choice==8)
{
exit(0);
}
if((choice<1)||(choice>8))
{
cout<<"Please enter a valid choice.\n";
goto menu;
}
value: //goto label
cout<<"Please enter the number of elements you want in the ARRAY(MAX 20).\n";
cin>>n;
if((n>20)||(n<1))
{
cout<<"Please enter a number between 1 and 20.\n";
goto value;
}
cout<<"Please enter the ARRAY (all positive elements).\n";
for(i=0;i<n;i++)
{
AGAIN1:
cin>>ARRAY[i];
if(ARRAY[i]<0)
{
cout<<"The element you entered is negative. Please re-enter.\n";
goto AGAIN1;
}
}
switch(choice)
{
case 1: PAIRS(ARRAY, n);
break;
case 2: ODD(ARRAY, n);
break;
case 3: EVEN(ARRAY, n);
break;
case 4: DIVBY30(ARRAY, n);
break;
case 5: LARGEST(ARRAY, n);
break;
case 6: SMALLEST(ARRAY, n);
break;
case 7: AVERAGE(ARRAY, n);
break;
case 8:
break;
default: ;
}
cout<<"\nDo you wish to continue? Type Y for yes and N for N.\n";
cin>>ch;
if((ch=='Y')||(ch=='y')||(ch=='N')||(ch=='n'))
{
if((ch=='Y')||(ch=='y'))
{
goto AGAIN;
}
else
{
cout<<"Thank you for using the program.\n";
}
}
else
{
cout<<"Invalid choice. Please enter the correct choice.\n";
}
getch();
}
void PAIRS(int ARRAY[20], int n) //Function definition
{
int i, j, sum=0, count=1;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
sum=ARRAY[i]+ARRAY[j];
if(sum==50)
{
cout<<"\n"<<count<<" pair is
("<<ARRAY[i]<<","<<ARRAY[j]<<")";
count++;
}
}
}
if(count==1)
{
cout<<"No pair found";
}
}
void ODD(int ARRAY[20], int n)
{
int i, count=0;
for(i=0;i<n;i++)
{
if(ARRAY[i]%2!=0) //Checking whether the element is odd
{
count++;
}
}
cout<<"Total number of odd elements is equal to "<<count;
}
void EVEN(int ARRAY[20], int n)
{
int i, count=0;
for(i=0;i<n;i++)
{ //Checking whether the element is even
if(ARRAY[i]%2==0)
{
count++;
}
}
cout<<"Total number of even elements is equal to "<<count;
}
void DIVBY30(int ARRAY[20], int n)
{
int i, count=0;
for(i=0;i<n;i++)
{
if(ARRAY[i]%30==0) //Checking divisibility by 30
{
count++;
}
}
cout<<"Total number of elements divisible by 30 is equal to "<<count;
}
void LARGEST(int ARRAY[20], int n)
{
int i, max;
max=ARRAY[0]; //Initialising the largest element
for(i=1;i<n;i++)
{
if(max<ARRAY[i]) //Finding the largest element
{
max=ARRAY[i];
}
}
cout<<"The element having maximum value is "<<max;
}
void SMALLEST(int ARRAY[20], int n)
{
int i, min;
min=ARRAY[0]; //Initialising the smallest element
for(i=1;i<n;i++)
{
if(min>ARRAY[i])
{
min=ARRAY[i];
}
}
cout<<"The element having minimum value is "<<min;
}
void AVERAGE(int ARRAY[20], int n)
{
int i, sum=0;
float avg;
for(i=0;i<n;i++)
{ //Loop to calculate the sum of all elements
sum+=ARRAY[i];
}
avg=sum/n; //Calculating average
cout<<"The average of all elements is "<<avg;
}
PROGRAM TO PERFORM VARIOUS OPERATIONS ON TWO
DIMENSIONAL ARRAYS
//Header Files
#include<iostream.h>
#include<conio.h>
#include<process.h>\

//Function Prototypes
void NONZERO(int[][20],int,int);
void SUMALL(int[][20],int,int);
void SUMBELOW(int[][20],int,int);
void SUMABOVE(int[][20],int,int);
void PRODDIAG(int[][20],int,int);

void main()
{

char ch;
//Do-while loop to continue the program as long as the user demands
do
{
clrscr();
int A[20][20],r,c,i,j,choice;

//Start point for goto function


z:
//Centralise menu heading
cout<<"\n\n\t\t\t\tMATRIX MENU : "<<endl;
//Displays menu options
cout<<"\n1.Find no. of non-zero elements "
<<"\n2.Find sum of all elements"
<<"\n3.Find sum of elements in the matrix such that i>j"
<<"\n4.Find sum of elements in the matrix such that i<j"
<<"\n5.Find product of elements such that i=j"
<<"\n6.Exit"
<<"\nNOTE: i-rows,j-coloumns\n";
cout<<"\nPlease enter your choice [1-6] : ";
cin>>choice;
cout<<"\nEnter no. of rows and columns of matrix : "<<endl;
cin>>r>>c;
//Loop to enter matrix elements
cout<<"\nEnter elements of the matrix : "<<endl;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
cin>>A[i][j];
//Loop to display matrix elements
cout<<"\nEntered matrix is : "<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
/*Switch case including all function call statements to execute a function
according to user's choice */
switch(choice)
{
case 1 : NONZERO(A,r,c);
break;
case 2 : SUMALL(A,r,c);
break;
case 3 : SUMBELOW(A,r,c);
break;
case 4 : SUMABOVE(A,r,c);
break;
case 5 : PRODDIAG(A,r,c);
break;
case 6 : cout<<"\nTHANK YOU ;')";
exit(0);
//Re-displays menu screen in case of wrong choice by the user
default : cout<<"\nWrong choice! Please enter a valid choice.";
goto z;
}
cout<<"\n\nDo you wish to continue? <y/n> ";
cin>>ch;
}
//Program continues if user presses Y or y
while((ch=='y')||(ch=='Y'));
cout<<"THANK YOU ;)";
//End of main()
}
//Function to find no. of non-zero elements
void NONZERO(int A[20][20],int m,int n)
{
int i,j,count=0;
//Loop to find count of non-zero elements in matrix
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j]!=0)
count++;
}
}
//Loop to display matrix entered by user
cout<<"\nMatrix A is : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
//Displaying count
cout<<"\nNo. of non-zero elements = "<<count;
}
//Function to calculate sum of all elements in matrix
void SUMALL(int A[20][20],int m,int n)
{
int i,j,sum=0;
//Loop to calculate sum
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum+=A[i][j];
}
}
//Loop to display matrix entered by user
cout<<"\nMatrix A is : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
//Displaying calculated sum
cout<<"\nSum of all elements = "<<sum;
}
//Function to calculate sum of elements below main diagonal
void SUMBELOW(int A[20][20],int m,int n)
{
int i,j,sum=0;
//Loop to calculate sum
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
sum+=A[i][j];
}
}
//Loop to display matrix entered by user
cout<<"\nMatrix A is : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
//Displaying calculated sum
cout<<"\nSum of elements below main diagonal = "<<sum;
}
//Function to calculate sum of elements above main diagonal
void SUMABOVE(int A[20][20],int m,int n)
{
int i,j,sum=0;
//Loop to calculate sum
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i<j)
sum+=A[i][j];
}
}
//Loop to display matrix entered by user
cout<<"\nMatrix A is : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
//Displaying calculated sum
cout<<"\nSum of elements below main diagonal = "<<sum;
}
//Function to calculate product of diagonal elements
void PRODDIAG(int A[20][20],int m,int n)
{
int i,j,prod=1;
//Loop to calculate product
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
prod*=A[i][j];
}
}
//Loop to display matrix entered by user
cout<<"\nMatrix A is : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
cout<<"\n";
}
//Displaying calculated product
cout<<"\nProduct of diagonal elements = "<<prod;
}
PROGRAM TO PERFORM FUNCTIONS ON VARIOUS TYPES OF
ARRAYS AND VECTORS
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<process.h>
void DIV10(int arr1[10],int lim); //Function Prototypes
void DIV10sum(int arr1[10],int lim);
void DIV10pro(int arr1[10],int lim);
void DIV10_m(int arr2[10][10],int r1,int c1);
void DIV10sum_m(int arr2[10][10],int r1,int c1);
void diagonal(int arr2[10][10],int r1,int c1);
void diagonalpro(int arr2[10][10],int r1,int c1);
void OFF_diagonal(int arr2[10][10],int r1,int c1);
void sumdiagonal(int arr2[10][10],int r1,int c1);
void FINDCHAR1(char ca);
void FINDCHAR2(char ca);
void LOWERCHAR1(char ca);
void LOWERCHAR2(char ca);
void REV(int arr1[10],int lim);
void ROWSUM(int arr2_[10][10],int r1,int c1);
void COLSUM(int arr2[10][10],int r1,int c1);
void ROWPROD(int arr2[10][10],int r1,int c1);
void COLPROD(int arr2[10][10],int r1,int c1);
void diagonal2(int arr2[10][10],int r1,int c1);
void ADDFUNC100(int arr1[10],int lim);
void ADDFUNC100_m(int arr2[10][10],int r1,int c1);
void COUNTSPACE(char str[10]);
void equal(int arr2[10][10],int r1,int c1,int arr3_8[10][10],int r2,int c2);
void swap(int arr1_[10],int lim);
void double_m(int arr2[10][10],int r1,int c1);
void ADDMAT(int arr2[10][10],int r1,int c1,int arr3_8[10][10],int r2,int c2);
void SUBTRMAT(int arr2[10][10],int r1,int c1,int arr3_8[10][10],int r2,int c2);
void PRODMAT(int arr2[10][10],int r1,int c1,int arr3_8[10][10],int r2,int c2);
void TRANSFORM(int arr2[10][10],int r1,int c1);
void main()
{
char ch;
do // do while loop for multiple executions
{
clrscr();
int arr1[10],num,lim,r1,c1,r2,c2,i,j;
int arr2[10][10],arr3_8[10][10];
char ca,str[10];
cout<<"Please enter a valid choice:\n"<<
"1.To display those elements of a vector divisible by 10\n"<<
"2.To display sum of elements of a vector divisible by 10\n"<<
"3.To display product of elements of a vector divisible by 10\n"<<
"4.To display the elements of a matrix divisible by 10\n"<<
"5.To display the sum of elements of a matrix divisible by 10\n"<<
"6.To display the diagonal elements\n"<<
"7.To display the product of diagonal elements\n"<<
"8.To display the off-diagonal elements\n"<<
"9.To display the sum of diagonal and off-diagonal elements\n"<<
"10.To display the type of character entered(without built in
functions)\n"<<
"11.To display the type of character entered(with built in functions)\n"<<
"12.To display whether the entered character is lowercase or
uppercase\n"<<
"13.To display whether the entered character is lowercase or
uppercase\n"<<
"14.To display the reversed vector\n"<<
"15.To display the sum of each row of the matrix\n"<<
"16.To display the sum of each column of the matrix\n"<<
"17.To display the product of each row of the matrix\n"<<
"18.To display the product of each column of the matrix\n"<<
"19.To display the product of diagonal elements of the matrix\n"<<
"20.To display the vector after adding 100 to each element\n"<<
"21.To display the matrix after adding 100 to each element\n"<<
"22.To display the count of spaces in a string\n"<<
"23.To check the matrices for equality\n"<<
"24.To display the vector after swapping first and last value\n"<<
"25.To display the matrix after doubling each element\n"<<
"26.To add two matrices\n"<<
"27.To subtract two matrices\n"<<
"28.To multiply two matrices\n"<<
"29.To transform a matrix\n"<<
"30.To exit\n";
menu:
cin>>num;
switch(num)
{
case 1:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++)
{
cout<<arr1[i]<<"\t";
}
DIV10(arr1,lim); //Function Call
break;
case 2:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++) //Loop to print the vector
{
cout<<arr1[i]<<"\t";
}
DIV10sum(arr1,lim);
break;
case 3:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++)
{
cout<<arr1[i]<<"\t";
}
DIV10pro(arr1,lim); //Function Call
break;
case 4:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++) //Loop to print the matrix
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
DIV10_m(arr2,r1,c1);
break;
case 5:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
DIV10sum_m(arr2,r1,c1);
break;
case 6:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
diagonal(arr2,r1,c1); //Function Call
break;
case 7:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
diagonalpro(arr2,r1,c1);
break;
case 8:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
OFF_diagonal(arr2,r1,c1);
break;
case 9:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++) //Loop to read the matrix
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
sumdiagonal(arr2,r1,c1);
break;
case 10:cout<<"Please enter a character:";
cin>>ca;
FINDCHAR1(ca);
break;
case 11:cout<<"Please enter a character:";
cin>>ca;
FINDCHAR2(ca); //Function Call
break;
case 12:cout<<"Please enter a character:";
cin>>ca;
LOWERCHAR1(ca);
break;
case 13:cout<<"Please enter a character:";
cin>>ca;
LOWERCHAR2(ca);
break;
case 14:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++)
{
cout<<arr1[i]<<"\t";
}
REV(arr1,lim);
break;
case 15:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
ROWSUM(arr2,r1,c1);
break;
case 16:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
COLSUM(arr2,r1,c1);
break;
case 17:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
ROWPROD(arr2,r1,c1);
break;
case 18:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
COLPROD(arr2,r1,c1);
break;
case 19:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
diagonal2(arr2,r1,c1);
break;
case 20:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++)
{
cout<<arr1[i]<<"\t";
}
ADDFUNC100(arr1,lim);
break;
case 21:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
ADDFUNC100_m(arr2,r1,c1);
break;
case 22:cout<<"Please enter a string(max 10):";
gets(str);
COUNTSPACE(str);
break;
case 23:cout<<"Enter the number of rows desired in matrix 1:";
cin>>r1;
cout<<"Enter the number of columns desired in matrix 1:";
cin>>c1;
cout<<"Enter the elements of matrix 1:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Enter the number of rows desired in matrix 2:";
cin>>r2;
cout<<"Enter the number of columns desired in matrix 2:";
cin>>c2;
cout<<"Enter the elements of matrix 2:";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cin>>arr3_8[i][j];
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cout<<arr3_8[i][j]<<"\t";
cout<<"\n";
}
equal(arr2,r1,c1,arr3_8,r2,c2);
break;
case 24:cout<<"Enter the no of elements desired:";
cin>>lim;
cout<<"Enter the elements:\n";
for(i=0;i<lim;i++)
{
cin>>arr1[i];
}
cout<<"Displaying the vector:\n";
for(i=0;i<lim;i++)
{
cout<<arr1[i]<<"\t";
}
swap(arr1,lim);
break;
case 25:cout<<"Enter the number of rows desired:";
cin>>r1;
cout<<"Enter the number of columns desired:";
cin>>c1;
cout<<"Enter the elements:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying the matrix:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
double_m(arr2,r1,c1);
break;
case 26:cout<<"Enter the number of rows desired in matrix 1:";
cin>>r1;
cout<<"Enter the number of columns desired in matrix 1:";
cin>>c1;
cout<<"Enter the elements of matrix 1:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Enter the number of rows desired in matrix 2:";
cin>>r2;
cout<<"Enter the number of columns desired in matrix 2:";
cin>>c2;
cout<<"Enter the elements of matrix 2:";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cin>>arr3_8[i][j];
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cout<<arr3_8[i][j]<<"\t";
cout<<"\n";
}
ADDMAT(arr2,r1,c1,arr3_8,r2,c2);
break;
case 27:cout<<"Enter the number of rows desired in matrix 1:";
cin>>r1;
cout<<"Enter the number of columns desired in matrix 1:";
cin>>c1;
cout<<"Enter the elements of matrix 1:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Enter the number of rows desired in matrix 2:";
cin>>r2;
cout<<"Enter the number of columns desired in matrix 2:";
cin>>c2;
cout<<"Enter the elements of matrix 2:";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cin>>arr3_8[i][j];
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cout<<arr3_8[i][j]<<"\t";
cout<<"\n";
}
SUBTRMAT(arr2,r1,c1,arr3_8,r2,c2);
break;
case 28:cout<<"Enter the number of rows desired in matrix 1:";
cin>>r1;
cout<<"Enter the number of columns desired in matrix 1:";
cin>>c1;
cout<<"Enter the elements of matrix 1:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
cout<<"Enter the number of rows desired in matrix 2:";
cin>>r2;
cout<<"Enter the number of columns desired in matrix 2:";
cin>>c2;
cout<<"Enter the elements of matrix 2:";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cin>>arr3_8[i][j];
}
cout<<"Displaying matrix 2:\n";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cout<<arr3_8[i][j]<<"\t";
cout<<"\n";
}
PRODMAT(arr2,r1,c1,arr3_8,r2,c2);
break;
case 29:cout<<"Enter the number of rows desired in matrix 1:";
cin>>r1;
cout<<"Enter the number of columns desired in matrix 1:";
cin>>c1;
cout<<"Enter the elements of matrix 1:";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cin>>arr2[i][j];
}
cout<<"Displaying matrix 1:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<arr2[i][j]<<"\t";
cout<<"\n";
}
TRANSFORM(arr2,r1,c1); //Function Call
break;
case 30:cout<<"Thank you for using the program!";
exit(0);
default:cout<<"Invalid character entered! Please enter again.\n";
goto menu;
}
cout<<"\nDo you wish to continue? Enter Y for Yes and N for No:\n";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
getch();
}
void DIV10(int arr1[10],int lim) //Function Definition
{
int count=0;
cout<<"\nThe elements divisible by 10 are:";
for(int i=0;i<lim;i++)
{
if((arr1[i]%10)==0)
{
cout<<arr1[i];
count++;
}
}
if(count==0)
cout<<"No element";
}
void DIV10sum(int arr1[10],int lim)
{
int sum=0,count=0;
for(int i=0;i<lim;i++)
{
if(arr1[i]%10==0)
{
sum+=arr1[i];
count=0;
}
}
if(count==0)
{
cout<<"No element is divisible by 10!";
goto end;
}
cout<<"\nThe sum of the elements divisible by 10 is:"<<sum;
end:
}
void DIV10pro(int arr1[10],int lim)
{
int product=1,count=0;
for(int i=0;i<lim;i++)
{
if(arr1[i]%10==0)
{
product*=arr1[i];
count++;
}
}
if(count==0)
{
cout<<"No element is divisible by 10!";
goto end;
}
cout<<"\nThe product of the elements divisible by 10 is:"<<product;
end:
}
void DIV10_m(int arr2[10][10],int r1,int c1)
{
int count=0;
cout<<"The elements divisible by 10 are:";
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if(arr2[i][j]%10==0)
{
cout<<arr2[i][j]<<"\t";
count++;
}
}
}
if(count==0)
cout<<"No element";
}
void DIV10sum_m(int arr2[10][10],int r1,int c1)
{
int sum=0,count=0;
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if((arr2[i][j]%10)==0)
{
sum+=arr2[i][j];
count++;
}
}
}
if(count==0)
{
cout<<"No element is divisible by 10!";
goto end;
}
cout<<"The sum of the elements divisible by 10 is:"<<sum;
end:
}
void diagonal(int arr2[10][10],int r1,int c1)
{
if(r1==c1)
{
cout<<"The diagonal elements are:\n";
for(int i=0;i<r1;i++) //Loop to print the diagonal elements
{
for(int j=0;j<c1;j++)
{
if(i==j)
cout<<arr2[i][j]<<"\t";
}
}
}
else
{
cout<<"No diagonal elements are there!";
}
}
void diagonalpro(int arr2[10][10],int r1,int c1)
{
int product=1;
if(r1==c1)
{
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if(i==j)
product*=arr2[i][j];

}
}
cout<<"The product of diagonal elements:"<<product;
}
else
{
cout<<"No diagonal elements are there!";
}
}
void OFF_diagonal(int arr2[10][10],int r1,int c1)
{
cout<<"The elements of off the main diagonal are:\n";
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if(i==r1-j-1)
cout<<arr2[i][j]<<"\t";
}
}
}
void sumdiagonal(int arr2[10][10],int r1,int c1)
{
int sum=0;
if(r1==c1)
{
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if(i==j)
sum+=arr2[i][j];
else if(i==r1-j-1)
sum+=arr2[i][j];

}
}
}
else
{
cout<<"No diagonal elements are there!";
}
cout<<"The sum of diagonal elements:"<<sum;
}
void FINDCHAR1(char ca)
{
if((ca>=48)&&(ca<=57))
cout<<"The character entered is a number.\n";
else if((ca>=65)&&(ca<=90))
cout<<"The character entered is a uppercase alphabet.\n";
else if((ca>=97)&&(ca<=122))
cout<<"The character entered is an lowercase alphabet.\n";
else
cout<<"The character entered is a special character.\n";
}
void FINDCHAR2(char ca)
{
if(isdigit(ca)==0)
{
cout<<"The character entered is a digit,\n";
}
else if(isupper(ca)==0)
{
cout<<"The character entered is an uppercase alphabet,\n";
}
else if(islower(ca)==0)
{
cout<<"The character entered is a lowercase alphabet.\n";
}
else
{
cout<<"The character entered is a special character.\n";
}
}
void LOWERCHAR1(char ca)
{
if((ca>=65)&&(ca<=90))
{
cout<<"The character entered is a uppercase alphabet.\n";
}
else if((ca>=97)&&(ca<=122))
{
cout<<"The character entered is an lowercase alphabet.\n";
}
else
{
cout<<"It is not an alphabet.\n";
}
}
void LOWERCHAR2(char ca)
{
if(islower(ca)==0)
{
cout<<"The character entered is a lowercase alphabet.\n";
}
else if(isupper(ca)==0)
{
cout<<"The character entered is an uppercase alphabet\n";
}
else
{
cout<<"The character entered is not an alphabet.\n";
}
}
void REV(int arr1[10],int lim) //Function Definition
{
cout<<"The reversed vector is:\n";
for(int i=lim-1;i>=0;i--)
cout<<arr1[i]<<"\t";
}
void ROWSUM(int arr2[10][10],int r1,int c1)
{
int sum=0;
for(int i=0;i<r1;i++)
{
sum=0;
for(int j=0;j<c1;j++) //Loop to calculate sum
{
sum+=arr2[i][j];
}
cout<<"The sum of elements of row"<<i+1<<"is:"<<sum<<"\n";
}
}
void COLSUM(int arr2[10][10],int r1,int c1)
{
int sum=0;
for(int j=0;j<c1;j++)
{
sum=0;
for(int i=0;i<r1;i++)
{
sum+=arr2[i][j];
}
cout<<"The sum of elements of column"<<j+1<<"is:"<<sum<<"\n";
}
}
void ROWPROD(int arr2[10][10],int r1,int c1)
{
int product=1;
for(int i=0;i<r1;i++) //Loop to calculate product
{
product=1;
for(int j=0;j<c1;j++)
{
product*=arr2[i][j];
}
cout<<"The product of elements of row"<<i+1<<"is:"<<product<<"\n";
}
}
void COLPROD(int arr2[10][10],int r1,int c1)
{
int product=1;
for(int j=0;j<c1;j++)
{
product=1;
for(int i=0;i<r1;i++)
{
product*=arr2[i][j];
}
cout<<"The product of elements of column"<<j+1<<"is:"<<product<<"\n";
}
}
void diagonal2(int arr2[10][10],int r1,int c1)
{
int product=1;
if(r1==c1)
{
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
if(i==j)
product*=arr2[i][j];
else if(i==r1-j-1)
product*=arr2[i][j];

}
}
cout<<"The product of diagonal elements:"<<product;
}
else
{
cout<<"No diagonal elements are there!";
}
}
void ADDFUNC100(int arr1[10],int lim)
{
for(int i=0;i<lim;i++)
{
arr1[i]=arr1[i]+100;
}
cout<<"The vector after adding 100 to each elements:\n";
for(i=0;i<lim;i++) //Loop to print the modified vector
{
cout<<arr1[i]<<"\t";
}
}
void ADDFUNC100_m(int arr2[10][10],int r1,int c1)
{
int i,j;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
arr2[i][j]=arr2[i][j]+100;
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<arr2[i][j]<<"\t";
}
cout<<"\n";
}
}
void COUNTSPACE(char str[10])
{
int count=0;
for(int i=0;str[i]!='\0';i++)
{
if(str[i]==' ')
count++;
}
cout<<"The number of spaces in the entered string is:"<<count;
}
void equal(int arr2[10][10],int r1,int c1,int arr3[10][10],int r2,int c2)
{
if((r1==r2)&&(c1==c2))
{
for(int i=0;i<r1;i++) //Checking the equality
{
for(int j=0;j<c1;j++)
{
if(arr2[i][j]!=arr3[i][j])
{
cout<<"The two matrices are identical but not
equal\n";
goto label;

}
}
}
cout<<"The two matrices are equal\n";
}
else
{
cout<<"The two matrices are not equal\n";
}
label:
}
void swap(int arr1[10],int lim)
{
int temp;
temp=arr1[0];
arr1[0]=arr1[lim-1];
arr1[lim-1]=temp;
cout<<"The vector after swapping first and last value is:\n";
for(i=0;i<lim;i++) //Loop to print the desired result
{
cout<<arr1[i]<<"\t";
}
}
void double_m(int arr2[10][10],int r1,int c1)
{
int i,j;
for(i=0;i<r1;i++) //Loop to double each element
{
for(j=0;j<c1;j++)
{
arr2[i][j]=arr2[i][j]*2;
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<arr2[i][j]<<"\t";
}
cout<<"\n";
}
}
void ADDMAT(int arr2[10][10],int r1,int c1,int arr3[10][10],int r2,int c2)
{
int arr4_8[10][10],i,j;
if((r1==r2)&&(c1==c2))
{
for(i=0;i<r1;i++) //Loop to add the matrices
{
for(j=0;j<c1;j++)
{
arr4_8[i][j]=arr2[i][j]+arr3[i][j];
}
}
cout<<"The added matrix is as follows:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<arr4_8[i][j]<<"\t";
}
cout<<"\n";
}
}
else
{
cout<<"The matrices cannot be added.\n";
}
}
void SUBTRMAT(int arr2[10][10],int r1,int c1,int arr3[10][10],int r2,int c2)
{
int arr4[10][10],i,j;
if((r1==r2)&&(c1==c2))
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
arr4[i][j]=arr2[i][j]-arr3[i][j];
}
}
cout<<"The subtracted matrix is as follows:\n";
for(i=0;i<r1;i++) //Loop to print the result
{
for(j=0;j<c1;j++)
{
cout<<arr4[i][j]<<"\t";
}
cout<<"\n";
}
}
else
{
cout<<"The matrices cannot be subtracted.\n";
}
}
void PRODMAT(int arr2[10][10],int r1,int c1,int arr3[10][10],int r2,int c2)
{
int arr4[10][10],i,j;
if((r1==r2)&&(c1==c2))
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
arr4[i][j]=arr2[i][j]*arr3[i][j];
}
}
cout<<"The multiplied matrix is as follows:\n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<arr4[i][j]<<"\t";
}
cout<<"\n";
}
}
else
{
cout<<"The matrices cannot be multiplied.\n";
}
}
void TRANSFORM(int arr2[10][10],int r1,int c1)
{
cout<<"The transposed matrix is as follows:";
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
cout<<arr2[j][i]<<"\t";
}
cout<<“\n";}
PROGRAM TO CREATE A COMPLETE LINKED LIST CLASS
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node //Declaration of node
{
int info;
node*next;
}*start;
class List //Class Declaration
{
public:
node*create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos();
void display();
List()
{
start= NULL;
}
};
void main() //Main Menu
{
clrscr();

int choice,nodes,element,position,i;
List l;
start=NULL;
do
{

clrscr();
cout<<"\n\t\t**************************";
cout<<"\n\t\t Operations on linked list " ;
cout<<"\n\t\t**************************";
cout<<"\n\t\t1. Insert Node at Beginning ";
cout<<"\n\t\t2. Insert Node at Last ";
cout<<"\n\t\t3. Delete a Node";
cout<<"\n\t\t4. Display Linked List ";
cout<<"\n\t\t5. Exit ";
cout<<"\n\n\t\t Enter your choice: ";
re:
cin>>choice;
switch(choice)
{
case 1: cout<<"\n\t Inserting Node at Beginning: ";
l.insert_begin();
l.display();
cout<<"\n";
break;
case 2: cout<<"\n\t Inserting Node at Last: ";
l.insert_last();
l.display();
cout<<"\n";
break;
case 3: cout<<"\n\t Deleting a Node: ";
l.delete_pos();
l.display();
cout<<"\n";
break;
case 4: cout<<"\n\t Display the Linked List: ";
l.display();
cout<<"\n";
break;
case 5: cout<<"\n\t Program Over ";
getch();
break;
default: cout<<"\n\t Wrong choice!";
cout<<"\n\t Reenter Choice: ";
goto re;
}
getch();
} while(choice!=5);

}
//Creating Node
node*List::create_node(int value)
{
node *temp;
temp=new node;
temp->info=value;
temp->next=NULL;
return temp;

}
void List::insert_begin() // Inserting element in beginning
{
int value;
cout<<"\n\n\t Enter value to be inserted: ";
cin>>value;
struct node *temp;
temp= create_node(value);
if(start== NULL)
{
start=temp;

}
else
{
temp->next=start;
start=temp;
}
cout<<"\n\n\t Element Inserted at Beginning. ";
}

//Inserting Node at Last


void List::insert_last()
{
int value;
cout<<"\n\n\t Enter value to be inserted: ";
cin>>value;
struct node *temp,*s;
temp=create_node(value);
s=start;
while(s->next !=NULL)
{
s=s->next;
}
s->next=temp;
cout<<"\n\n\t Element inserted at last.\n ";
}
//Insertion of node at a given position

//Delete element at a given position


void List::delete_pos()
{
int pos,i,counter=0;
if(start==NULL)
{
cout<<"\n\n\t List is empty. ";
return;
}
position:
cout<<"\n\n\t Enter the position of value to be deleted: ";
cin>>pos;
struct node *s, *ptr,*q;
s=start;
if(pos==1)
{
ptr=s;

start=s->next;
cout<<"\n\n\tElement deleted is"<<s->info;
delete s;
}
else
{
while(s->next!=NULL)
{
s=s->next;
counter++;
}
if((pos>0)&&(pos<=counter))
{
s=start;
for(i=1;i<pos;i++)
{
ptr=s;
s=s->next;
}
ptr->next=s->next;

}
else
{
cout<<"\n\n\t Position out of range.Enter the valid position ";
goto position;
}

cout<<"\n\n\tElement deleted is"<<s->info;


delete s;

}
}
//Display Elements of a link list
void List::display()
{
struct node *temp;
if(start==NULL)
{
cout<<"\n\n\t The List is Empty.";
return;
}
temp=start;
cout<<"\n\n\t Elements of list are: ";
while(temp!=NULL)
{
cout<<temp->info<<"->";
temp=temp->next;
}

cout<<"NULL";
}
OUTPUTS
PROGRAM TO IMPLEMENT THE USE OF QUEUE CLASS
#include<iostream.h> //header file for console input and output
#include<conio.h> //header file for function to clear the screen
#include<process.h> //header file for function to exit program
class queue //class to implement queue
{
private:
int front,rear; //positions of first and last elements in queue
int a[5]; //the actual queue, with each data member in this array
public:
queue() //constructor
{
int front=-1; //This signifies that
int rear=-1; //the queue has no data member
}
void addQ(int item) //Function for inserting element
{
/*Checking if queue is full
Maximum capacity of queue is 5 */
if(rear==4)
cout<<"\nQueue is full .No element could be added";
else if(rear==-1)
{

cout<<"\nElement has been added";


front=0;
rear=0;
a[front]=item;
}
else
a[rear++]=item;
cout<<"\nElement has been added"; /*Adding element to the back of the queue
as per First In First Out(FIFO) rule*/
}
void delQ()
{

if(front==-1) //Checking if queue is empty


cout<<"\nQueue is empty .Underflow";
else
{
cout<<"Element to be deleted"<<a[front];
if(rear=0)
{

cout<<"\n Element deleted. Now Queue is empty";


front=-1;
rear=-1;
}
else
{
a[front]=0;
front++;}
}
/*front is incremented, thereby virtually deleting
front element as per FIFO rule*/
}
void display(); //Function to display queue
};
void queue::display()
{
if(front<=rear)
for( int i=front;i<=rear;i++)
cout<<a[front]<<" ";
else if(rear=-1)
{

cout<<"\nNO element could be displayed . Queue is empty";


}
}
void main() //start of main()
{
queue q1; //object of class queue
int item,choice; //Declaring necessary variables
char ch; //for do-while loop condition
do
{
clrscr(); //function to clear screen
cout<<"\n\t\tQueue Manipulation Menu ";
cout<<"\n1.Add item to queue ";
cout<<"\n2.Delete item from queue ";
cout<<"\n3.Display all items in queue ";
cout<<"\n4.Exit ";
cout<<"\nYour Choice : ";
cin>>choice; //taking user's choice
switch(choice)
{
case 1 : cout<<"\nEnter element ";
cin>>item;
q1.addQ(item);
q1.display();
break;
case 2 : q1.delQ();
q1.display();
cout<<"\nItem deleted ";
break;
case 3 : q1.display();
break;
case 4 : cout<<”\n Program Over”;
exit(0);
break;
default :cout<<"\nPlease enter valid choice ";
break;
}
cout<<"\nDo you wish to continue (y/n) : ";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
cout<<”\n Program Over”;
} //end of main
OUTPUTS
PROGRAM TO IMPLEMENT THE USE OF STACK CLASS
#include<iostream.h> //Header file for Console Input and Output Functions
#include<conio.h> //Header file that includes Function clrsr()
#include<process.h> //Header file that contains Function exit()

#define size 5 //Defines a constant named 'size' with value 5

class stack //Defines a new class named 'stack'


{
private: //Declares private members of class 'stack'
int A[size]; //An array of size 'size' (5)
int top; //Variable for knowing position of top element
public: //Declares public members of class 'stack'
stack() //Constructor of class 'stack'
{
top=-1;
}
void push(int item); //Function to add element to Array
int pop(); //Function to delete element from Array
void display(); //Function to display elements of Array

};

void stack::push(int item) //Definition of function push of class stack


{
if(top==size-1) //Checking if stack is full
cout<<"\nStack is Full ";
else
{
top++; //Increment position of top element
A[top]=item; //The new top element is initialized
}
}
int stack::pop() //Definition of function pop of class stack
{
int item;
if(top==-1) //Checking if stack is empty
{
cout<<"\nStack is Empty : ";
return(-1);
}
else
{
item=A[top]; //Storing value of top element for display purposes
top--; //Decrementing position of top element,
//Previous top element is effectively deleted,
//For it will not be displayed as part of stack
return item;
}
}
void stack::display() //Definition of function display of class stack
{
cout<<”\n Current stack is \n “;
int i;
for(i=top;i>=0;i--)
cout<<A[i]<<" "; //Displaying each element of array in stack
}
void main() //Start of main()
{
clrscr(); //function to clear screen
stack s1; //Crating object of class 'stack'
int choice,val; //Declaring neccesary
char ch; //variables for progrsm
/* 'choice' for switch case , 'val' for storing value
taken from user, 'ch' for do-while loop
*/
do //start of do-while loop
{
cout<<"\n\t\tStack Manipulation Menu "<<endl;
cout<<"\n\t1.Add Element (Push) "; // Menu for
cout<<"\n\t 2.Delete Element(Pop) "; // manipulation of
cout<<"\n\t 3.Display Elements "; // data stored in
cout<<"\n\t 4.Exit "; // stack
cout<<"\n\t Your Choice : ";
cin>>choice; //User's choice taken
switch(choice) //start of switch case statement
{
case 1 : cout<<"\nEnter value to be entered/pushed : ";
cin>>val;
s1.push(val); //Calling function 'push'
s1.display();
break;
case 2 : int x;
x=s1.pop(); //Calling function 'pop' and
//storing deleted value in x
cout<<"\nThe value deleted/popped is : "<<x;
s1.display();
break;
case 3 : cout<<"Elements in Stack :- "<<endl;
s1.display(); //Calling function 'display'
break;
case 4 : cout<<”\n Program Over “;
exit(0); //Exiting from program
break;
default : cout<<"\nPlease enter a valid choice "; //In case of wrong choice
break;
} //End of switch case
cout<<"\nDo you want to continue (y/n) : ";
cin>>ch; //Taking choice from user
}while((ch=='y')||(ch=='Y')); //End of do-while loop
} //End of main()
OUTPUTS
PROGRAM IN TO ADD, DELETE, SEARCH AND DISPLAY AN
ELEMENT IN A LINKED QUEUE
#include<iostream.h> //Header file for Console Input Output Functions
#include<conio.h> //Header file for Function clrscr()
#include<process.h> //Header file for Function exit()
struct node //Declaring structure 'node'
{
int data;
node *next; //Pointer to itself
};
class queue //Creating a new linked class 'queue'
{
private: //Declaring private members of class 'queue'
node *rear; //pointer to object of structure 'node'
node *front; //pointer to object of structure 'node'
public: //Declaring public members of class node
queue() //Constructor for class 'queue'
{
rear=NULL;front=NULL;
}
void qinsert(); //
void qdelete(); //Function
void qdisplay(); //Prototypes
void qsearch(); //
~queue(); //Destructor Prototype
};
void queue::qinsert() //Defining member function 'qinsert'
{
node *temp;
temp=new node;
cout<<"Data : ";
cin>>temp->data;
temp->next=NULL;
if(rear==NULL)
{
rear=temp;
front=temp;
}
else
{
rear->next=temp;
rear=temp;
}
}
void queue::qdelete() //Defining member function 'qdelete'
{
if(front!=NULL)
{
node*temp=front;
cout<<front->data<<"\nElement Deleted "<<endl;
front=front->next;
delete temp;
if(front==NULL)
rear=NULL;
}
else
cout<<"\nQueue Empty ";
}
void queue::qdisplay() //Defining member function 'qdisplay'
{
node*temp=front;
while(temp!=NULL)
{
cout<<temp->data<<endl;
temp=temp->next;
}
}
queue::~queue() //Defining destructor for 'queue'
{
while(front!=NULL)
{
node*temp=front;
front=front->next;
delete temp;
}
}
void queue::qsearch() //Defining member function 'qsearch'
{
int item,fl=0,pos=0;
cout<<"\nEnter item to be searched for : " ;
cin>>item;
node*temp=front;
while(temp!=NULL)
{
pos++;
if(item==temp->data)
{
cout<<"\n"<<item<<" found at position "<<pos;
fl=1;
break;
}
else
temp=temp->next;
}
if(!fl)
cout<<"\nItem not found ";
}
void main() //Start of main()
{
clrscr(); //clearing the screen
queue q1; //creating object of class 'queue'
int choice; //Declaring necessary
char ch; //variables
/*choice for switch case,
ch for do-while loop*/
do //Start of do-while loop
{
cout<<"\n\t\tQueue Manipulation Menu "; //Menu
cout<<"\n\t1.Insert Element "; //for
cout<<"\n\t2.Delete Element "; //manipulation
cout<<"\n\t3.Search For Element "; //of
cout<<"\n\t4.Display All Elements "; //data
cout<<"\n\t5.Exit "; //in
cout<<"\n\tYour Choice : "; //queue
cin>>choice;
switch(choice) //start of switch case
{
case 1 : q1.qinsert(); //calling function qinsert()
q1.qdisplay();
break;
case 2 : q1.qdelete(); //calling function qdelete()
q1.qdisplay();
break;
case 3 : q1.qsearch(); //calling function qsearch()
break;
case 4 : q1.qdisplay(); //calling function qdisplay()
break;
case 5 : cout<<”\n Program Over “;
exit(0); //exits the program
break;
default : cout<<"\nPlease enter a valid choice "; //In case of wrong choice
break;
}
cout<<"\nDo you wish to continue (y/n) : ";
cin>>ch;
}while((ch=='y')||(ch=='Y')); //End of do-while loop
cout<<”\n Program Over “;
} //End of main()
OUTPUTS
PROGRAM FOR THE IMPLEMENTATION OF LINKED STACK
#include <iostream.h>
#include <conio.h>
#include <process.h>

struct node //Structure node define


{
int data;
node*next;
};

class stack //Class stack defined


{
node*top;

public:

stack() //Constructor of class Stack


{
top=NULL;
}
void push(); //Function push() to add an element to the top of the
stack
void pop(); //Function pop() to remove an element from the top of
the stack
void display(); //Function display() to display contents of stack
~stack(); //Destructor of class stack

};

void stack::push() //Function push() defined


{
node*temp;
temp=new node;
cout<<"Enter data:\n";
cin>>temp->data;
temp->next=top;
top=temp;
}

void stack::pop() //Function pop() defined


{
if(top!=NULL)
{
node*temp=top;
top=top->next;
cout<<temp->data<<"Element deleted\n";
delete temp;
}
else
cout<<endl<<"Stack is empty\n";
}

void stack::display() //Function display() defined


{
cout<<"\n Current Stack is : ";
node*temp=top;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}

stack::~stack()
{
while(top!=NULL)
{
node*temp=top;
top=top->next;
delete temp;
}
}

void main()
{
clrscr();
stack s;
int ch;
do
{ label:
cout<<"\n***********MAIN MENU************\n"
<<"1)Push Element\n"
<<"2)Pop Element\n"
<<"3)Display Stack\n"
<<"4)Exit\n"
<<"Enter your choice\n";
cin>>ch;

switch(ch)
{
case 1:s.push(); //Function push() called
s.display();
break;
case 2:s.pop(); //Function pop() called
s.display();
break;
case 3:s.display(); //Function display() called
break;
case 4: cout<<"\n Program Over ";
exit(0);
break;
default:cout<<"Wrong choice, Please choose a correct choice \n";
goto label;
exit(0);
}
}while(ch<4);
cout<<"\n Program Over ";
getch();
}
QUERIES OF RELATION ‘TEACHER’

a) SELECT*
FROM RelationTeacher
WHERE Dept=’History’;
--Display all the information of teachers of the history department

b) SELECT*
FROM RelationTeacher
WHERE Dept=’Hindi” AND Sex=’F’;
--Display the names of all the female teachers of the Hindi department

c) SELECT*
FROM RelationTeacher
ORDER BY DateOfJoin;
--Display the list of teachers with their date of joining in the ascending
order
(d) SELECT*
FROM RelationTeacher
WHERE Sex=’M’;

e) SELECT COUNT(*)
FROM RelationTeacher
WHERE Age<23;
--To count the number of teachers having age less than 23

f) INSERT INTO RelationTeacher


values(‘8’,’Shalakha’,’33’,’Math’,’1997-07-31’,’20000,’F’);
--To insert a new row in Relation Teacher

QUERIES FOR RELATION ‘WORKERS AND DESIG’


(i) SELECT W_ID,First_Name,Address,City
FROM WORKERS
WHERE(City='New York');
--Displays W_ID,first name,address,city of workers who live in New York

(ii) SELECT * FROM WORKERS


ORDER BY Last_Name;
--Displays table workers ordered by last name in ascending order

(iii) SELECT MIN(Salary) FROM DESIG


WHERE(Designation='Manager' OR Designation='Clerk');
--Displays minimum salary among managers and clerks

QUERIES FOR RELATION ‘ CONSIGNOR AND CONSIGNEE’

1. SELECT CnorName FROM CONSIGNOR


WHERE City = ‘Mumbai’;
--Display name of all consignors from Mumbai

2. SELECT CneerName, CnorName FROM CONSIGNOR C1,


CONSIGNER C2
WHERE C1.City=C2.City;
-- To display the CneeName, CnorName where consignor city is same as
consignee city

3. SELECT* FROM CONSIGNEE


GROUP BY CneerName
ORDER BY CneerName ASC;
-- To display consignee detalils in ascending order of CneerName.

4. SELECT DISTINCT City


FROM CONSIGNOR;
--To display distinct city from consignor.
5. SELECT CneerName, CnorName
FROM CONSIGNOR C1, CONSIGNEE C2
WHERE C1.City=”Mumbai” AND C2.City=”Mumbai”;
-- To display CneeName and CnorName Where city is Mumbai.
QUERIES FOR RELATION ‘FLIGHTS AND FARES’
1. SELECT FL_NO, NO_FLIGHTS
FROM FLIGHTS
WHERE FL_STARTING=”KANPUR” AND
FL_ENDING=”BANGALORE”;
--To display FL_NO and NO_FLIGHTS from “KANPUR” to
“BANGALORE

2. SELECT SUM(FARE)
FROM FARES
WHERE AIRLINES=”INDIAN AIRLINES”;

3. SELECT FLIGHTS, FL_NO, FARES, FARE


FROM FLGHTS, FARES
WHERE FL_STARTING=”DELHI” AND FL_ENDING=”MUMBAI”;

4. SELECT FL_STARTING, FL_ENDING, AIRLINES, FARE


FROM FLIGHTS F1, FARES F2
WHERE F2.TAX>5;
5. SELECT DISTINCT AIRLINES
FROM FLIGHTS, FARES;
BIBLIOGRAPHY

This program file could not have been completed


without the following sources:-
 Computer Science with C++ Standard 11
By Sumita Arora
 Computer Science with C++ Standard 12
By Sumita Arora
 Object Oriented Programming with C++
By E. Balagurusamy
 Object Oriented Programming in C++
By Robert Lafore

594
BIBLIOGRAPHY

This program file could not have been completed


without the following sources:-
● Computer Science with C++ Standard 11
By Sumita Arora
● Computer Science with C++ Standard 12

By Sumita Arora
● Object Oriented Programming with C++

By E. Balagurusamy
● Object Oriented Programming in C++

By Robert Lafore

595

Potrebbero piacerti anche