• No results found

case 1: ans='y';

while(ans=='y'||ans=='Y') {

cout<<"\n Enter element to be inserted :"; cin>>m;

k=insert(q,m);

if(k==-1)

cout<<"\n Overflow !!!!";

cout<<"\n The resultant Queue is : ";

display(q,front,rear);

cout<<"\n\n Want to enter again ?: ";

cin>>ans;

cout<<"\n Underflow !!!!";

break;

} else

{

cout<<"\n The deleted element is "<<u<<"\n";

cout<<"\n The resultant Queue is : \n\n";

display(q,front,rear);

}

cout<<"\n\n Want to delete again ?: ";

cin>>ans;

} break;

case 3: cout<<"\n The Queue is : \n\n";

display(q,front,rear);

break;

default: cout<<"\n Please enter desired keyword : ";

}

cout<<"\n Choose from the menu again ? : ";cin>>ch;

}while(ch=='y'||ch=='Y');

getch();

}

OUTPUT

/* Wap to implement stack as a linked liststack as a linked liststack as a linked liststack as a linked list */

node *create(int a) {

ptr=new node; //To create a new node ptr->roll=a;

ptr->next=NULL;

return ptr;

}

void push(node *np) {

np->next=save;

} }

void pop() {

if(top==NULL)

cout<<"\n Underflow!!!!";

else

void display(node *np) {

while(np!=NULL) {

cout<<np->roll<<" -> ";

np=np->next;

}

}

<<"\n 1. Push."

<<"\n 2. Pop."

<<"\n 3. Display." //Main Menu

<<"\n 4. Quit."

<<"\n\nEnter your choice : ";

cin>>n;

cout<<"\n Enter element to be inserted .";

cin>>m;

newptr=create(m);

if(newptr==NULL)

cout<<"\n Cannot create !!!!";

push(newptr);

cout<<"\n The Stack formed is : ";

display(top);

cout<<"\n\n Want to enter again ?: ";

cin>>k;

cout<<"\n The Stack formed is : \n\n";

display(top);

cout<<"\n\n Want to delete again ?: ";

cin>>k;

} break;

case 3: cout<<"\n The Stack formed is : ";

display(top);

break;

case 4: exit(0);

break;

default: cout<<"\n Please enter desired keyword : ";

}

cout<<"\n Do you want to continue..? : ";

cin>>ch;

}while(ch=='y'||ch=='Y');

getch();

}

OUTPUT

/* Wap in c++ to implement Queue as a linked listQueue as a linked listQueue as a linked listQueue as a linked list */

#include<iostream.h> // Header files declared

#include<conio.h>

struct node {

int roll;

node* next;

}*front,*rear,*ptr,*newptr,*np;

node *create(int a) {

ptr=new node; //To create a new node ptr->roll=a;

ptr->next=NULL;

return ptr;

}

void insert(node *np) {

if(front==NULL) front=rear=np;

else {

rear->next=np;

rear=np;

} }

void delet()

{

if(front==NULL)

cout<<"\n Underflow!!!!";

else

void display(node *np) {

front=rear=NULL;

int n,m;

char ans,ch;

do

{ cout<<"\nChoose from the menu : "

<<"\n 1) Insert." //Main Menu

<<"\n 2) Delete

<<"\n 3) Display."

<<"\n\n Enter your choice : ";

cin>>n;

switch(n) {

case 1: ans='y';

while(ans=='y'||ans=='Y') {

cout<<"\n Enter element to be inserted .";

cin>>m;

newptr=create(m);

if(newptr==NULL)

cout<<"\n Cannot create !!!!";

insert(newptr);

cout<<"\n The Queue formed is : ";

display(front);

cout<<"\n Want to enter more nodes ?: ";

cin>>ans;

} break;

case 2: ans='y';

while(ans=='y'||ans=='Y') {

delet();

cout<<"\n Queue : ";

display(front);

cout<<"\n Want to delete more ?: ";

cin>>ans;

} break;

case 3: cout<<"\n Queue : ";

display(front);

break;

default: cout<<"\n You entered wrong choice...";

}

cout<<"\n Want to return to main menu ? : ";

cin>>ch;

}while(ch=='y'||ch=='Y');

getch();

}

OUTPUT

/* Wap in C++ to create a linked list of integerscreate a linked list of integerscreate a linked list of integers and perform some basic operation on it. create a linked list of integers

cout<<"\n\nFirst node deleted";

}

node*create_new_node(int n)

void search(node*np,int a) {

do //Main Menu {

cout<<"\n\nChoose from the menu :\n1.Insert at the end\n2.Insert at beginning\n3.Searching\n4.Deletion from begining \n5.Display \n";

cout<<"\n\nEnter your choice";

cout<<"\n\nEnter information for the new node : ";

cin>>info;

newptr=create_new_node(info);

if(newptr!=NULL)

cout<<"\n\nNode has been created";

else {

cout<<"\n\nNode cannot be created;";

exit(1);

}

insert_end(newptr);

cout<<"\n\nThe Linked list is : ";

display(start);

cout<<"\n\nWant to insert again : ";

cin>>choice;

}while(choice=='y'||choice=='Y');

break;

case 2: do {

cout<<"\n\nEnter info for new node: ";

cin>>info;

newptr=create_new_node(info);

if(newptr!=NULL)

cout<<"\n\nNode has been created ";

else {

cout<<"\n\nNode cannot be created ";

exit(1);

}

insert_beg(newptr);

cout<<"\n\nThe Linked list is : ";

display(start);

cout<<"\n\nWant to insert again : ";

cin>>choice;

}while(choice=='y'||choice=='Y');

break;

case 3: do {

cout<<"\n\nEnter info to be searched : ";

cin>>n;

search(start,n);

cout<<"\n\nWant to search again : ";

cin>>choice;

}while(choice=='y'||choice=='Y');

break;

case 4: delnode();

break;

case 5: display(start);

break;

}// end of do switch

cout<<"\n\nWant to choose again : ";

cin>>ans;

}

while(ans=='y'||ans=='Y');

getch();

}

OUTPUT

/* Wap in C++ to read file “sports.dat”“sports.dat”“sports.dat” and copy only those records where event name is “sports.dat”

ATHLETIC ATHLETIC ATHLETIC

ATHLETIC using the concept of Data file handlingData file handlingData file handlingData file handling */

#include<fstream.h>

#include<string.h> // Header files declared

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

struct sports {

char event[20];

char participants[10][30];

int no_of_participants;

} s[20], s2[20];

void copy(fstream &ob);

int i=0;

cout<<"\n\nEnter the name of Event : ";

cin.getline(s[i].event,20);

cout<<"\n\nEnter the total number of participants in Event "<<s[i].event<<" : ";

cin>>s[i].no_of_participants;

cout<<"\n\nEnter the name of Praticipants : \n";

cin.get();

for(int j=0; j<s[i].no_of_participants; j++) cin.getline(s[i].participants[j],30);

ob.write((char*)&s[i], sizeof(sports)); //To write into the file

cout<<"\n\n\nWant to Enter Details of Another Event (Y/N) : ";

cin>>choice;

i++;

} while(choice=='y'||choice=='Y');

cout<<"\n\n\n\n\n******************************************************************************

******************************\n\n";

copy(ob);

cout<<"\n\n************************************************************************************

*****************************\n\n\n";

getch();

}

void copy(fstream &o) {

sports s[20];

o.seekg(0);

ofstream file;

file.open("athletic.dat",ios::binary);

file.seekp(0);

int j,n=0;

int c=0;

while(o) {

o.read((char*)&s[c], sizeof(sports));

if(strcmp("athletic",s[c].event)==0) {

file.write((char*)&s[c], sizeof(sports));

n=1;

break;

} c++;

}

if(n==0) {

cout<<"\n\nUnsuccessful Search.";

getch();

exit(0);

}

o.close();

file.close();

sports sp;

ifstream oo;

oo.open("athletic.dat",ios::binary);

while(oo) {

oo.read((char*)&sp, sizeof(sports));

}

cout<<"\n\nThe Records of file are : \n\n";

cout<<"\n\nEvent = "<<sp.event;

cout<<"\n\n\n\nThe Participants are : \n\n";

for(int i=0; i<sp.no_of_participants; i++) {

cout<<sp.participants[i]<<"\n\n";

}

oo.close();

remove("athletic.dat");

remove("sports.dat");

}

OUTPUT

/* Wap to print and find the sum of Fibonacci series Fibonacci series Fibonacci series Fibonacci series using recursion.recursion.recursion. */ recursion.

#include<iostream.h> // Header files declared

#include<conio.h>

int fibonacci(int n);

void main() {

clrscr();

int n;

cout<<"\n\n Enter the number of terms upto which you want the sum of fibonnaci series :

";

cin>>n;

cout<<"\n\nThe fibonacci series generated is : \n\n";

cout<<"1 1 ";

int s=fibonacci(n);

cout<<"\n\nThe sum of fibonacci series for "<<n<<" terms = "<<s;

getch();

}

int first=1;

int second=1;

int third;

int i=2;

int sum=0;

int fibonacci(int n) { if(n==1)

sum=1;

else if(n==2) sum=2;

// n = 1 2 3 4 5 else if(n>1 && i!=n) // num = 1 1 2 3 5 {

third=first+second;

cout<<third<<” “;

if(i==2)

sum+=first+second+third;

else

sum+=third;

first=second;

second=third;

++i;

fibonacci(n);

}

return sum;

}

OUTPUT

/* Wap in C++ to print and find the sum of even /odd numbers using recursionrecursionrecursionrecursion.*/

#include<iostream.h> // Header files declared

#include<conio.h>

int sum_even(int );

int sum_odd(int );

int sum=0;

int num=0;

void main() { clrscr();

int n;

int s_e, s_o;

cout<<"\n\nEnter the number upto which you want the sum of even/odd numbers : ";

cin>>n;

cout<<"\n\n The list of integers is : \n\n";

for(int l=1; l<=n; l++) cout<<l<<"\n";

s_e=sum_even(n);

s_o=sum_odd(n);

cout<<"\n\nThe sum of even numbers upto "<<n<<" = "<<s_e;

cout<<"\n\nThe sum of odd numbers upto "<<n<<" = "<<s_o;

getch();

}

int sum_even(int n) {

if(num%2==0) sum=sum+num;

if(num!=n && num<n) {

++num;

sum_even(n);

}

return sum;

}

int sum_2=0;

int num_2=0;

int sum_odd(int n) {

if(num_2%2!=0)

sum_2=sum_2+num_2;

if(num_2!=n) {

num_2++;

sum_odd(n);

}

return sum_2;

}

OUTPUT

/* Wap in c++ using pointers to find the smallest smallest smallest smallest and the largest largest largest element in a largest dynamically created array

dynamically created array dynamically created array dynamically created array.*/

#include<iostream.h> // Header files declared

#include<conio.h>

void main() {

clrscr();

int *array, smallest, largest, n;

cout<<"\n\nEnter the number of elements : ";

cin>>n;

array=new[n];

cout<<"\n\nEnter the elements : \n\n";

for(int i=0; i<n; i++) cin>>array[i];

i=0;

cout<<"\n\nThe array formed is : \n\n";

while(i!=n) {

cout<<array[i]<<" ";

i++;

}

smallest=array[0];

for(i=0; i<n; i++) {

if(array[i]<=smallest)

smallest=array[i]; //Comparing the elements }

largest=array[0];

for(i=0; i<n; i++) {

if(array[i]>=largest) largest=array[i];

}

cout<<"\n\nThe smallest element is : "<<smallest<<"\n\nThe largest element is :

"<<largest;

getch();

}

OUTPUT

/* Wap using pointersusing pointersusing pointersusing pointers to swapswapswapswap two integers. */

#include<iostream.h> // Header files declared

#include<conio.h>

void swap_using_pointers(int *, int *);

void main() {

clrscr();

int a,b;

cout<<"\n\nEnter first integer : "; cin>>a;

cout<<"\n\nEnter second integer : "; cin>>b;

swap_using_pointers(&a,&b);

cout<<"\n\nNow value of first integer = "<<a;

cout<<"\n\nNow value of second integer = "<<b;

getch();

}

void swap_using_pointers(int *a,int *b) {

int temp;

temp=*a;

*a=*b;

*b=temp;

}

OUTPUT

/* Wap using pointerspointerspointers to find the lengthpointers find the lengthfind the lengthfind the length of a string and print the reversed stringreversed stringreversed string . */ reversed string

#include<iostream.h>

#include<string.h> // Header files declared

#include<conio.h>

void main() {

clrscr();

char *str= new char[256];

cout<<"\n\nEnter the string : ";

cin.getline(str,256);

cout<<"\n\nThe string length => "<<strlen(str);

cout<<"\n\nThe reverse string is : ";

char intermediate;

for(int j=strlen(str)-1,i=0; i<=strlen(str)/2; j--,i++) {

intermediate = *(str+j);

//Loop to reverse the string

*(str+j)=*(str+i);

*(str+i)=intermediate;

}

cout<<str;

getch();

}

OUTPUT

/*Program to sort an array in ascending order using Selection sort Selection sort Selection sort Selection sort */

lb: cout<<"Enter the size of array : ";

cin>>n;

if(n<=0||n>80)

{cout<<"\n\nEnter size of array less than or equal to 80.";

goto lb;

}

cout<<"\n\nEnter the elements of array : \n\n";

for(int i=0; i<n; i++) cin>>A[i];

void selection_sort(int A[],int n);

selection_sort(A,n);

cout<<"\n\n\n\n\nSorted array is : \n\n";

for(i=0; i<n; i++)

cout<<"\n\nArray after iteration "<<count<<" is :\n\n";

for(k=0; k<n; k++) cout<<A[k]<<" ";

} }

OUTPUT

/* WapWapWap to create a text file to input roll no. and marks of ten students and display them Wap on screen after reading from the text file using data file handlingusing data file handlingusing data file handlingusing data file handling. */

cout<<"\n\nEnter the roll no. of student "<<i+1<<" : "; cin>>a[i];

cout<<"\n\tEnter the marks of student "<<i+1<<" => "; cin>>b[i];

}

ofstream student;

student.open("stud.txt");

for(i=0; i<10; i++) {

student<<"\n\nMarks of roll no. "<<a[i]<<" => "<<b[i];

}

student.close();

i=0;

cout<<”\n\nStudent details are :\n\n”;

char str[80][80];

OUTPUT

/* WAP USING FUNCTION OVERLOADING TO CALCULATE A^B */

float calc(float a, float b) {

return pow(a,b);

}

float calc(int a, float b) {

return pow(a,b);

}

float calc(float a, int b) {

cout<<"Enter int P : "; cin>>P;

cout<<"Enter int Q : "; cin>>Q;

cout<<"Enter real R : "; cin>>R;

cout<<"Enter real S : "; cin>>S;

cout<<P<<"^"<<Q<<" = "<<pow(P,Q)<<"\n\n"; // Using ‘pow’ from math.h cout<<P<<"^"<<R<<" = "<<pow(P,R)<<"\n\n";

cout<<R<<"^"<<Q<<" = "<<pow(R,Q)<<"\n\n";

cout<<R<<"^"<<S<<" = "<<pow(R,S);

getch();

}

OUTPUT

/* WAP USING FUNCTION OVERLOADING TO CALCULATE AREA OF CIRCLE, SQUARE, RECTANGLE, RIGHT TRIANGLE AND TRIANGLE USING HERON’S FORMULAE */

#include<iostream.h>

#include<math.h> // Header files declared

#include<conio.h>

float area(float p) {

return 3.14*p*p;

}

float area(int p) {

return p*p;

} // Function overloading of ‘area’

float area(float p,float q) {

float area(float p,float q, float r) {

cout<<"\n\nChoose from the following : ";

cout<<"\n\n1. Area of square ";

cout<<"\n\n2. Area of circle "; // Main Menu cout<<"\n\n3. Area of rectangle ";

cout<<"\n\n4. Area of right triangle ";

cout<<"\n\n5. Area of triangle ";

cout<<"\n\nEnter your choice : "; cin>>ch;

switch(ch)

{

case 1: cout<<"\n\nEnter side of square : ";

cin>>p;

cout<<"\n\narea of square is : "<<area(p);

break;

case 2: cout<<"\n\nEnter radius of circle : ";

cin>>a;

cout<<"\n\narea of circle is : "<<area(a);

break;

case 3: cout<<"\n\nEnter length of rectangle : ";

cin>>a;

cout<<"\n\nEnter breadth of rectangle : ";

cin>>b;

cout<<"\n\narea of rectangle is : "<<area(a,b);

break;

case 4: cout<<"\n\nEnter base and altitude of right triangle : ";

cin>>p;

cin>>q;

cout<<"\n\narea of right triangle is : "<<area(q,p);

break;

case 5: cout<<"\n\nEnter sides of triangle : ";

cin>>a;

cin>>b;

cin>>r;

cout<<"\n\narea of triangle is : "<<area(a,b,r);

break;

}

cout<<"\n\nWant to choose again : ";

cin>>choice;

}while(choice=='y'||choice=='Y');

getch();

}

OUTPUT

/* WAP USING MULTIPLE INHERITANCE FOR THE CLASSES STUDENT, GAME AND PERSON */

#include<iostream.h> // Header files declared

#include<stdio.h>

#include<conio.h>

class person{ char name[21];

int age;

cout<<"\n\nName of the student is: "<<name;

cout<<"\n\nAge of the student is : "<<age;

}

cout<<"\n\nEnter the game name : ";

cin.get();cin.getline(game_name,20);

class student: public person, public game

{ float Tmarks; // Multiple inheritance

else if(Tmarks>80&&Tmarks<=90)

return 'B';

else if(Tmarks>70&&Tmarks<=80) return 'C';

else if(Tmarks>60&&Tmarks<=70) return 'D';

cout<<"\n\nEnter the roll number: "; cin>>rollno;

input();

cout<<"\n\nRoll number : "<<rollno;

OUTPUT();

cout<<"\n\nTotal marks are : "<<Tmarks;

cout<<"\n\nGrade = "<<calgrade();

}

cout<<”\n\nstudent details are : \n\n”;

A.display();

getch();

}

OUTPUT

SQL

COMMANDS

SCREENSHOTS (SQL)

sql .txt mysql> use shlok;

Database changed

mysql> CREATE TABLE CUSTOMERS(

-> ID INT NOT NULL,

Query OK, 0 rows affected (0.31 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );

Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (2, 'Khilan', 25, 'Delhi', 1500.00 );

Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (3, 'kaushik', 23, 'Kota', 2000.00 );

Query OK, 1 row affected (0.09 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (4, 'Chaitali', 25, 'Mumbai', 6500.00 );

Query OK, 1 row affected (0.09 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (5, 'Hardik', 27, 'Bhopal', 8500.00 );

Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) -> VALUES (6, 'Komal', 22, 'MP', 4500.00 );

Query OK, 1 row affected (0.06 sec)

mysql> SELECT ID, NAME, SALARY FROM CUSTOMERS;

+----+---+---+

sql .txt

| 5 | Hardik | 8500.00 |

| 6 | Komal | 4500.00 | +----+---+---+

6 rows in set (0.00 sec)

mysql> SELECT * FROM CUSTOMERS;

+----+---+---+---+---+

mysql> SELECT ID, NAME, SALARY -> FROM CUSTOMERS

mysql> SELECT ID, NAME, SALARY -> FROM CUSTOMERS

Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0

Page 2

sql .txt

mysql> DELETE FROM CUSTOMERS -> WHERE ID = 6;

Query OK, 1 row affected (0.04 sec)

mysql> SELECT * FROM CUSTOMERS -> ORDER BY NAME, SALARY;

mysql> ALTER TABLE CUSTOMERS ADD SEX char(1);

Query OK, 0 rows affected (0.53 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM CUSTOMERS;

+----+---+---+---+---+---+

mysql> ALTER TABLE CUSTOMERS DROP SEX;

Query OK, 0 rows affected (0.69 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM CUSTOMERS;

+----+---+---+---+---+

sql .txt

mysql> SELECT ID, NAME, AGE, ADDRESS, SALARY -> FROM CUSTOMERS

mysql> SELECT * FROM CUSTOMERS -> WHERE SALARY LIKE '200%';

mysql> SELECT SALARY FROM CUSTOMERS -> ORDER BY SALARY;

mysql> DROP TABLE CUSTOMERS;

Query OK, 0 rows affected (0.16 sec)

Page 4

Related documents