Академический Документы
Профессиональный Документы
Культура Документы
}
void concat()
{
char str1[30], str2[30];
int l1=0,l2=0,i=0,flag=0;
cout<<"\n Enter the string1 (size<=30) ";
gets(str1);
while(str1[l1]!='\0')
{
l1++;
}
cout<<"\n Enter the string2 (size<=30) ";
gets(str2);
while(str2[l2]!='\0')
{
l2++;
}
for(i=0;i<l2;i++)
{
str1[l1+i]=str2[i];
}
str1[l1+l2]='\0';
cout<<"\n The concatenated String is: ";
puts(str1);
}
void main()
{
clrscr();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
char ch;
cin>>ch;
do
{
if(ch=='1')
findlength();
if(ch=='2')
compare();
if(ch=='3')
concat();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
cin>>ch;
}while(ch!='4');
getch();
}
Q.2. Create an array containing country and capital now write a menu
driven program to: display capital of the given country.
print the tabular report of the country and corresponding capital.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct world
{
char country[30];
char capital[30];
};
void main()
{
clrscr();
world w[10];
int i=0,n;
cout<<"Enter no. of records (<=10): ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the country: ";
gets(w[i].country);
cout<<"Enter the capital: ";
gets(w[i].capital);
}
char ch,*cont;
int flag;
cout<<"\n\t1.Search for capital\n\t2.List all Records\n\t3.Exit";
cin>>ch;
do
{
if(ch=='1')
{
cout<<"\nEnter the country : ";
gets(cont);
flag=0;
for(i=0;i<n;i++)
{
if(strcmp(cont,w[i].country)==0)
{
cout<<"\n capital is: "<<w[i].capital;
flag=1;
break;
}
}
if(flag==0)
cout<<"\ncountry not found";
}
if(ch=='2')
{
cout<<"\nCOUNTRY\t\tCAPITAL";
cout<<"\n-------\t\t-------";
for(i=0;i<n;i++)
cout<<"\n"<<(w[i].country)<<"\t\t"<<(w[i].capital);
}
Q.3. Write a function in C++ which accepts a 2-D array of integers and its
size as arguments and displays elements which are exactly two-digit
number.
#include<iostream.h>
#include<conio.h>
void twodigit(int a[10][10],int m,int n)
{
int i,j,flag=0;
cout<<"The Two digit Numbers are: ";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(a[i][j]>=10&&a[i][j]<=99)
{
cout<<a[i][j]<<ends;
flag=1;
}
}
if(flag==0)
cout<<"None";
}
void main()
{
clrscr();
int a[10][10],i,j,m,n;
cout<<"\n EnterNo. of rows: ";
cin>>m;
cin>>ch;
do
{
switch(ch)
{
case '1':
cout<<"\nEnter the Roll no.";
cin>>trn;
flag=0;
for(i=0;i<n;i++)
if(trn==rno[i])
{
cout<<"\n Name: "<<name[i]<<"\t";
cout<<"Roll No.: "<<rno[i];
cout<<"\nMark1: "<<m1[i];
cout<<"\nMark2: "<<m2[i];
cout<<"\nMark3: "<<m3[i];
cout<<"\n----------";
cout<<"\nTotal: "<<tot[i];
flag=1;
}
if(flag==0)
cout<<"Record not found";
break;
case '2':
cout<<"\nRollno\tName \tMark1\tMark2\tMark3";
cout<<"\tTotal";
cout<<"\n------\t----------\t----\t----\t----";
cout<<"\t-----";
for(i=0;i<n;i++)
{
cout<<"\n"<<rno[i]<<"\t"<<name[i]<<"\t"
<<m1[i]<<"\t"<<m2[i]<<"\t"<<m3[i]<<"\t"
<<tot[i];
}
break;
}
cout<<"\n\t1.Report card for particular student"
"\n\t2.List all records\n\t3.Exit";
cin>>ch;
}while(ch!='3');
getch();
}
Q.5. Write a program to display the report card of any student and also
print the tabular report of the whole class in ascending order of total
marks.
(use structure: Roll no., Name, mark 1, mark 2, mark 3, Total).
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
struct student
{
char name[30];
int roll;
int mark1;
int mark2;
int mark3;
int total;
}st[100];
main()
{
int n,ch,i,j;
char choice;
do
{
clrscr();
cout << "1. For enter "<<endl;
cout << "2. For tabular report"<<endl;
cout << "3. For Report card"<<endl;
cout << "4. For exit";
cin >> ch;
switch(ch)
{
case 1: cout << "Enter how many students ";
cin >>n;
for(i=0;i<n;i++)
{
cout << "Enter name ";
gets(st[i].name);
cout <<st[i].mark2;
gotoxy(46,r);
cout <<st[i].mark3;
gotoxy(56,r);
cout <<st[i].total;
r++;
}
break;
case 3: int troll;
cout << "\nEnter the roll number to be searched ";
cin >> troll;
for(i=0;i<n;i++)
{
if (st[i].roll == troll)
{
cout << " \n Name "<<st[i].name;
cout << "\n Roll "<< st[i].roll;
cout << "\n Mark1 "<<st[i].mark1;
cout << "\n Mark2 "<<st[i].mark2;
cout << "\n Mark3 "<<st[i].mark3;
cout << "\n total "<<st[i].total;
}
}
break;
case 4: exit(0);
}
cout << "\n Do U want to continue";
cin>>choice;
}while(choice == 'Y' ||choice =='y');
}
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
break;
case '3':
cout<<"\nThe element to be searched";
int el;
cin>>el;
int first=0,last=n-1,mid=0,flag=0;
while(first<=last&&flag==0)
{
mid=(first+last)/2;
if(a[mid]==el)
{
flag=mid;
}
else if(a[mid]<el)
{
first=mid+1;
}
else
{
last=mid-1;
}
}
if(flag>0)
cout<<"\nThe Element is Found at: "<<++flag<<" in the sorted
array";
else
cout<<"\n No such Element";
break;
case '4':
cout<<"\n";
for(i=0;i<n;i++)
cout<<a[i]<<ends;
}
}while(ch!='5');
}
Q.7. A class student has three data members and few member functions:1.
2.
3.
4.
5.
Name.
Roll no.
Marks.
Input()
Display()
To create a file.
To print the stream according to the total marks of the student:96 or more
Computer Science.
91-95
Electronics.
86-90
Mechanical.
81-85
Electrical.
76-80
Chemical.
71-75
Civil.
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
class student
{
char name[30];
int rollno;
int marks;
public:
void input()
{
cout<<"\nEnter Name: ";
gets(name);
cout<<"Enter Rollno.: ";
cin>>rollno;
cout<<"enter marks";
cin>>marks;
}
void display()
{
cout<<"\n"<<name<<"\t"<<rollno<<"\t"<<marks<<"\t";
if(marks>=96)
cout<<"computer sc.";
else if(marks>=91&&marks<=95)
cout<<"Electronics";
else if(marks>=86&&marks<=90)
cout<<"Mechanical";
else if(marks>=81&&marks<=85)
cout<<"Electrical";
else if(marks>=76&&marks<=80)
cout<<"Chemical";
else if(marks>=71&&marks<=75)
cout<<"Civil";
else
cout<<"none";
}
};
void main()
{
clrscr();
student s;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Show Records\n\t3.Exit\n";
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("st.dat",ios::app|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
s.input();
ofile.write((char*)&s,sizeof(student));
}
ofile.close();
break;
cout<<"\nName\tRollno\tMarks\tStream";
afile.open("st.dat",ios::in);
while(afile)
{
afile.read((char *)&s,sizeof(student));
if (!afile)
break;
s.display();
}
afile.close();
break;
case '3' : exit(0);
case '2' :
}
cout<<"\n\t DO U want to continue <Y/N>: ";
cin>>ch1;
}while(tolower(ch1)!='n');
getch();
}
case '2' :
break;
cout<<"\nFormatted text:\t";
afile.open("vwl.txt",ios::in);
while(afile)
{
afile.get(ch);
cout<<ch;
}
afile.close();
break;
case '3' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
}
afile.close();
cout<<"\n No of Vowels: "<<v;
cout<<"\n No of digits: "<<d+1;
cout<<"\n No of words: "<<w;
break;
case '3' :
char tmp2;
afile.open("smp.txt",ios::in);
ofile.open("spl.txt",ios::out);
while(!afile.eof())
{
afile.get(tmp2);
if(tmp2==' ')
{
ofile<<'#';
}
else
{
ofile<<tmp2;
}
}
afile.close();
ofile.close();
cout<<"\nFormatted text:\t";
afile.open("spl.txt",ios::in);
while(afile)
{
afile.get(ch);
cout<<ch;
}
afile.close();
break;
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{
cout<<"\n\t1.Create Text\n\t2.Read from File\n\t3.create another file";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
case '2' :
char tmp1;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(isalpha(tmp1))
{
if (islower(tmp1))
{
if (tmp1=='a'||tmp1=='e'||tmp1=='i'||tmp1=='o'||tmp1=='u')
cout << "\n Lower case vowel "<<tmp1;
else
cout<<"\n Lower case consonants "<<tmp1;
}
if (isupper(tmp1))
{
if
(tmp1=='A'||tmp1=='E'||tmp1=='I'||tmp1=='O'||tmp1=='U')
cout << "\n Upper case vowel "<<tmp1;
else
cout<<"\n Lower case consonants "<<tmp1;
}
}
case '3' :
}
afile.close();
break;
ofile.open("smp.txt",ios::in);
afile.open("smp1.txt",ios::out);
char c;
while(ofile)
{
ofile.get(c);
c = tolower(c);
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afile.put(c);
}
ofile.close();
afile.close();
case 2: display();
break;
case 3 : exit(0);
}
cout<<"\n\t DO U want to continu<Y/N>: ";
cin>>ch1;
}while(tolower(ch1)!='n');}
donor d;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Search Records\n\t3.List Records\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("dnr.dat",ios::out|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
d.input();
ofile.write((char*)&d,sizeof(donor));
}
ofile.close();
break;
case '2' :
cout<<"\nEnter Blood Group to be searched: ";
char bg[5],flag=0;
gets(bg);
afile.open("dnr.dat",ios::in);
while(afile)
{
afile.read((char *)&d,sizeof(donor));
if(!afile)
break;
if (strcmp(bg,d.getbgroup())==0)
{
d.display();
flag=1;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
afile.open("dnr.dat",ios::in);
while(afile)
{
afile.read((char *)&d,sizeof(donor));
if(!afile)
break;
d.display();
}
afile.close();
break;
B no.
B name.
Price.
And required function.
cin>>price;
}
void display()
{
cout<<"\nBook Name: "<<bname<<"\tBook No.: "<<bno<<"\tPrice: "<<price<<"\t";
}
int getbno()
{
return bno;
}
};
void main()
{
clrscr();
book b;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Search Records\n\t3.Modify Records\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("bk.dat",ios::out|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
b.input();
ofile.write((char*)&b,sizeof(book));
}
ofile.close();
break;
case '2' :
cout<<"\nEnter Book No. to be searched: ";
int bn,flag=0;
cin>>bn;
afile.open("bk.dat",ios::in);
while(afile)
{
afile.read((char *)&b,sizeof(book));
if(!afile)
break;
if (bn==b.getbno())
{
b.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
cout<<"\nEnter Book No. to be modified ";
int bn1,flag1=0,r=0;
cin>>bn1;
afile.open("bk.dat",ios::in|ios::out|ios::binary);
while(afile)
{
afile.read((char *)&b,sizeof(book));
if(!afile)
break;
if (bn1==b.getbno())
{
b.setprice();
afile.seekp(r*sizeof(b),ios::beg);
afile.write((char *)&b,sizeof(book));
flag1=1;
break;
}
r++;
}
if(flag1==0)
cout<<"\n No record Found";
afile.close();
break;
Q.15. Define a class clothing in C++ with the following description:Private members
Code
of
Type
of
Size
of
Material of
Price
of
type
type
type
type
type
string.
string.
string.
string.
string.
Type
Price (Rs.)
TROUSER
1500
SHIRT
1200
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
class Clothing
{
char Code[15];
char Type[15];
int Size;
char Material[20];
float Price;
public:
// Constructor to assign initial values
Clothing()
{
strcpy(Code, "NOT ASSIGNED");
strcpy(Type, "NOT ASSIGNED");
strcpy(Material, "NOT ASSIGNED");
Size = 0;
Price = 0;
}
// Function to calculate value
void CalPrice()
{
if (strcmp(Material, "COTTON") == 0)
{
Price = 1500;
}
else
if (strcmp(Material, "SHIRT") == 0)
{
Price = 1200 - (1200 * (25/100));
}
}
// Function to input the values
void Enter()
{
cout << "Enter code : ";
gets(Code);
cout << "Enter type : ";
gets(Type);
cout << "Enter size : ";
cin >> Size;
cout << "Enter Material : ";
gets(Material);
CalPrice();
}
// Function to display values
void Show()
{
cout << "Code : ";
puts(Code);
cout << "Type : ";
puts(Type);
cout << "Size : " << Size << endl;
cout << "Material : ";
puts(Material);
cout << "Price : " << Price;
}
};
void main()
{
clrscr();
Clothing C;
C.Enter();
C.Show();
}
S no.
S name
Fees.
Required functions.
}
int getsno()
{
return sno;
}
};
void main()
{
clrscr();
Sports s;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Search Records\n\t3.Delete Records\n\t4.Exit\n";
cout << "Enter your choice... ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("Sport.dat",ios::out|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
s.input();
ofile.write((char*)&s,sizeof(Sports));
}
ofile.close();
break;
case '2' :
cout<<"\nEnter Sports No. to be searched: ";
int sn,flag=0;
cin>>sn;
afile.open("Sport.dat",ios::in);
while(afile)
{
afile.read((char *)&s,sizeof(Sports));
if(!afile)
break;
cout << s.getsno();
if (sn==s.getsno())
{
s.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
cout<<"\nEnter Sports No. to be Deleted ";
int sn1,flag1=0;
cin>>sn1;
afile.open("Sport.dat",ios::in|ios::binary);
ofile.open("TSport.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(Sports));
if(!afile)
break;
if (sn1==s.getsno())
{
flag1=1;
}
else
{
ofile.write((char *)&s,sizeof(Sports));
}
}
if(flag1==0)
cout<<"\n No record Found";
afile.close();
ofile.close();
afile.open("TSport.dat",ios::in|ios::binary);
ofile.open("Sport.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(Sports));
ofile.write((char *)&s,sizeof(Sports));
}
afile.close();
ofile.close();
break;
Front is the first node of QUEUE & REAR is the last node.
Write a menu driven program: To add element in the queue.
To delete element from the queue.
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a queue structure
struct node
{
int Eno;
float Salary;
node *link;
};
// Functions prototype to add queue, delete queue, and show queue
node *add_Q(node *rear, int val,float val1);
// Add queue
node *del_Q(node *front, int &val, float &val1);// Delete queue
void show_Q(node *front);
// Show queue
// Main programming logic
void main()
{
node *front, *rear;
int val;
float val1;
int choice;
char opt = 'Y'; // To continue the do loop in case
front = rear = NULL;
// Initialization of Queue
clrscr();
do
{
cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Queue";
cout << "\n\t2. Deletion from Queue";
cout << "\n\t3. Traverse of Queue";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter Your choice from above ";
cin >> choice;
switch (choice)
{
case 1:
do
{
cout << "Enter the value to be added in the
queue ";
cin >> val;
cin >> val1;
rear = add_Q(rear, val,val1);
if (front == NULL)
front = rear;
cout << "\nDo you want to add more element
<Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y';
// Initialize for the second loop
do
{
front = del_Q(front, val, val1);
if (front == NULL)
rear = front;
if (val != -1)
cout << "Value deleted from Queue is "
<< val;
cout << "\nDo you want to delete more element
<Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3:
show_Q(front);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body to add queue elements
node *add_Q(node *rear, int val, float val1)
{
node *temp;
temp = new node;
temp->Eno = val;
temp->Salary = val1;
temp->link = NULL;
rear->link = temp;
rear = temp;
return (rear);
}
// Function body to delete queue elements
node *del_Q(node *front, int &val, float &val1)
{
node *temp;
clrscr();
if (front == NULL)
{
cout << "Queue Empty ";
val = -1;
}
else
{
temp = front;
front = front->link;
val = temp->Eno;
val1 = temp->Salary;
temp->link = NULL;
delete temp;
}
return (front);
}
// Function body to show queue elements
void show_Q(node *front)
{
node *temp;
temp = front;
clrscr();
cout << "The Queue values are";
while (temp != NULL)
{
cout <<"\nENO : "<< temp->Eno;
cout <<"\nSalary : "<<temp->Salary;
temp = temp->link;
}
}
{
cout << "Enter the roll no. : ";
cin >> troll;
cout << "Enter age : ";
cin >> tage;
top = push(top, troll, tage);
cout << "\nDo you want to add more elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the second loop
do
{
top = pop(top);
if (troll != -1)
cout << "Value deleted from Stack is " << troll;
cout << "\nDo you want to delete more elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3:
show_Stack(top);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body for adds stack elements
node *push(node *top, int val, int tage)
{
node *temp;
temp = new node;
temp->roll = val;
temp->age = tage;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}
return(top);
}
// Function body for delete stack elements
int i;
if (top < 0)
{
cout << "Stack Empty";
return;
}
i = top;
clrscr();
cout << "The values are ";
do
{
cout << "\n" << stack[i];
i = i - 1;
}while(i >= 0);
}
case 2:
opt = 'Y';
// Initialize for the second loop
do
{
val = del_Q(queue, front, rear);
if (val != -1)
cout << "Value deleted from Queue is "
<< val;
cout << "\nDo you want to delete more element
<Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3:
show_Q(queue, front, rear);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body to add circular queue with array of character
void add_Q(char queue[], int front, char val, int &rear)
{
if ((rear + 1) % MAX == front)
{
cout << "Queue Full ";
}
else
{
rear = (rear + 1) % MAX;
queue[rear] = val;
}
}
// Function body to delete circular queue with array of character
char del_Q(char queue[], int &front, int rear)
{
char value;
if (front == rear)
{
cout << "Queue Empty ";
value = -1;
}
else
{
front = (front + 1) % MAX;
value = queue[front];
}
return (value);
}
// Function body to show circular queue with array
void show_Q(char queue[], int front, int rear)
{
clrscr();
cout << "The values are ";
do
{
front = (front + 1) % MAX;
cout << "\n" << queue[front];
}while(front != rear);
}
SQL
Q-4 List the details of all employees whose hire date is 23 May 1990.
rd
Q-5
List the details of the employees who have four lettered name.
Q-6 List the details of all employees whose annual salary in between
900 and 10000.
Q-7 List the details of all employees who earn more than 4000.
Q-9 Write a query to display the name of employees whose name contains
t as the last alphabet.
Q-11 Write a query to display name, salary and hire date of employees
who are hire between may 23, 1990 and December 31 1990. Order the query
in ascending order of hire date.
Q-12 write a query to display the employees name, salary and current
date.
Q-13 For each employees display the employees name and total numbers
of years lapsed between hire date and today.
Q-14 Write a query which displays the employees name with other letter
in lower case and length of these name string.
Q-15 Modify the salary and increase by 1000, for all who get salary
more than 1500.
Q-18 Write a query to join two Tables Employee and department on the
basis of field dept id.
Q-19 Display a details like sum, average, highest used and lowest
salary of the employee.
INDEX
S.NO
PROGRAMS
REMARK