0% found this document useful (0 votes)
5 views34 pages

Wa0119.

........................

Uploaded by

Shruti Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views34 pages

Wa0119.

........................

Uploaded by

Shruti Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

1.Social Media Program.

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct insta
{
char un[30];
char n[30];
char bio[40];
char mn[10];
struct insta *next;
}*start=NULL,*last=NULL;
typedef struct insta Node;
class Aic
{
public:
void add();
void del();
void update();
void search();
};
void Aic::add()
{
Node *q,*t;
t=(Node *)malloc(sizeof(Node));
cout<<"Enter the details :";
cout<<"\nEnter phone number";
cin>>t->mn;
cout<<"\nEnter user name";
cin>>t->un;
cout<<"\nEnter name";
cin>>t->n;
cout<<"\nEnter bio";
cin>>t->bio;
t->next=NULL;
if(start==NULL)
start=t;
else
{
q=start;
while(q->next!=NULL)
{
q=q->next;
}
q->next=t;
}
}
void Aic::del()
{
Node *ptr,*loc;
char x[30];
cout<<"Enter the account name to be deleted\n";
cin>>x;
ptr=start;
if(start==NULL)
{
cout<<"Account Not Found\n";
return;
}
else
{
while(ptr!=NULL)
{
if(strcmp(ptr->un,x)==0)
{
loc->next=ptr->next;
free(ptr);
return;
}
loc=ptr;
ptr=ptr->next;
}
}
}

void Aic::update()
{
Node *temp;
int c=1;
char u[30];
temp=start;
cout<<"Enter the account name to be updated\n";
cin>>u;
while(temp!=NULL)
{
if(strcmp(temp->un,u)!=0)
{
c++;
cout<<"\nAccount Not Found";
}
else
{
cout<<"Renter the details";
cout<<"\nEnter phone number";
cin>>temp->mn;
cout<<"\nEnter user name";
cin>>temp->un;
cout<<"\nEnter name";
cin>>temp->n;
cout<<"\nEnter bio";
cin>>temp->bio;

break;
}
temp=temp->next;
}
}

void Aic::search()
{
Node *temp;
int c=1;
char u[30];
temp=start;
cout<<"Enter the account name to be searched\n";
cin>>u;
while(temp!=NULL)
{
if(strcmp(temp->un,u)!=0)
{
c++;
cout<<"\nAccount Not Found";
}
else
{
cout<<"\n User name : "<<temp->un;
cout<<"\n Name : "<<temp->n;
cout<<"\n Bio : "<<temp->bio;
cout<<"\n Phone no. : " <<temp->mn;
break;
}
temp=temp->next;
}
}

void main()
{
Aic obj;
int g=0,c=0;
do
{
cout<<"Enter 1 to add account\n";
cout<<"Enter 2 to update account \n";
cout<<"Enter 3 to delete account \n";
cout<<"Enter 4 to search account\n";
cout<<"Enter 5 to exit\n " ;
cout<<"Enter your choice";
cin>>c;
switch(c)
{
case 1:
obj.add();
break;
case 2:
obj.update();
break;
case 3:
obj.del();
break;
case 4:
obj.search();
break;
case 5:
exit(0);

}
cout<<"\nEnter 1 to contine \ 0 to exit";
cin>>g;
}
while(g==1);
}
2.Wap to generate otp and verify it with the otp entered by user.

#include<iostream.h>
#include<time.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
class Ot
{
public:
int uc1,uc2;
int gotp();
void ver();
};
int Ot::gotp()
{
int g;
srand(time(0));
return rand()%10000;
}
void Ot::ver()
{
int got=gotp();
int uotp;
time_t start=time(0);
cout<<"\nYour OTP :"<<got;
cout<<"\nEnter OTP: ";
cin>>uotp;
time_t current=time(0);
if(got==uotp)
{
if(difftime(current,start)<10)
cout<<"Login Succesfully...\n";
else
{
cout<<"OTP Expire\n";
cout<<"\nEnter 1 to Regenerate OTP\n Enter 2 to exit\n";
cin>>uc1;
if(uc1==1)
{
Ot::gotp();
Ot::ver();
}
else
exit(0);
}

}
else
{
cout<<"Incorrect OTP\n";
cout<<"\nEnter 1 to Regenerate OTP\n Enter 2 to exit\n";
cin>>uc2;
if(uc2==1)
{
Ot::gotp();
Ot::ver();
}
else
exit(0);
}

void main()
{
Ot obj;
obj.gotp();
obj.ver();
}
3.Password program.
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include<string.h>
void main()
{
struct info
{
char un[20];
char p[10];
}s={"Shruti","7809"};
char n[20];
char pass[5];
int i=0;
char a;
cout<<"Enter User Name : ";
cin>>n;
cout<<"\nEnter 4 digit Password : ";
for(i=0;i<4;)//infinite loop
{
a=getch();//stores char typed in a
if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9')) //check if a is numeric or
alphabet
{
pass[i]=a;//stores a in pass
++i;
cout<<"*";
}
if(a=='\b'&&i>=1)//if user typed backspace
//i should be greater than 1.
{
cout<<"\b \b ";//rub the character behind the cursor.
--i;
}

if(a=='\r')//if enter is pressed


{
pass[i]='\0';//null means end of string.
break;//break the loop
}
}
cout<<"\nYou entered : "<<pass;
if((strcmp(s.p,pass)==0) && (strcmp(s.un,n)==0))
cout<<"\nYou login succesfully...\n" ;
else
cout<<"\n You entered wrong password...\n";
getch();
}
4.Bank Program to open account ,delete account, access account.
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
struct ban
{
long int acn;
int ag;
char nm[30],at[30];
float bal;
struct ban *next;
}*start=NULL,*last=NULL;;
class Bank
{
public:
void openacc();
void delacc();
};
void Bank::openacc()
{
struct ban *p;
p=(struct ban *)malloc(sizeof(struct ban *));
cout<<"\n Enter the Account Type (Savings or Current)";
cin>>p->at;
cout<<"\n Enter the Customer Name";
gets(p->nm);
cout<<"\n Enter the Age";
cin>>p->ag;
cout<<"\n Enter the Amount to be Deposited(Mininmum balance 1000)";
cin>>p->bal;
srand(time(0));
p->acn= (rand()%100000);
if(start==NULL)
{
start=last=p;
}
else
{
last->next=p;
last=p;
}
cout<<"Your " <<p->at <<" Account Number: "<<p->acn;
}
void Bank::delacc()
{
struct ban *ptr,*loc;
long int a;
char ty[20];
cout<<"\n Enter the Account Type";
gets(ty);
cout<<"\n Enter the Account Number that is to be deleted";
cin>>a;
ptr=start;
loc=NULL;
if(start==NULL)
{
cout<<"\n No Account Exist";
return;
}
else if(start->next==NULL)
{
if(ptr->acn==a)
{
start=last=NULL;
free(ptr);
cout<<"Your " <<ptr->at<< " got deleted";
return;
}
}
else
{
while(ptr!=NULL)
{
if(ptr->acn==a)
{
loc->next=ptr->next;
free(ptr);
cout<<"Your " <<ptr->at<< " account got deleted";
return;
}
loc=ptr;
ptr=ptr->next;
}
}
}
class Savings:Bank
{

public:
void s_deposit();
void s_withdraw();
void s_balance();
};

void Savings::s_deposit()
{
struct ban *t;
float dp,i;
long int a;
t=start;
cout<<"\nEnter the Account NUmber";
cin>>a;
while(t!=NULL)
{
if(t->acn==a)
{
cout<<"\nEnter Deposit amount:";
cin>>dp;
t->bal=t->bal+dp;
i=(t->bal*2)/100;
t->bal=(t->bal)+i;
cout<<"\n Money Deposited";
return;
}
t=t->next;
}
}
void Savings::s_withdraw()
{
float wd;
long int a;
struct ban *t;
cout<<"\n Enter the Account Number";
cin>>a;
cout<<"\nEnter Withdrawl Amount";
cin>>wd;
t=start;
while(t!=NULL)
{
if(t->acn==a)
{
if(wd<t->bal && t->bal>1000)
{
t->bal=t->bal-wd;
cout<<"\n Balance Amount after withdrawing :"<<t->bal;
}
else
cout<<"\n Insufficient Balance";
}
t=t->next;
}
}
void Savings::s_balance()
{
struct ban *t;
long int a;
cout<<"\n Enter the Account Number :";
cin>>a;
t=start;
while(t!=NULL)
{
if(t->acn==a)
{
cout<<"Available Bal:"<<t->bal;
return;
}

t=t->next;
}
}
class Current:Bank
{
public:
void c_deposit();
void c_withdraw();
void c_balance();
};
void Current::c_deposit()
{
struct ban *t;
float dp;
long int a;
cout<<"\n Enter the Account Number ";
cin>>a;
cout<<"\nEnter the Deposit Amount";
cin>>dp;
t=start;
while(t!=NULL)
{
if(t->acn==a)
{
t->bal=(t->bal)+dp;
}
t=t->next;
}
}
void Current::c_withdraw()
{
struct ban *t;
float wd;
cout<<"\n Enter the Withdrwal Amount";
cin>>wd;
t=start;
while(t!=NULL)
{
if(wd<t->bal && t->bal>1000)
t->bal=(t->bal)-wd;
else
{
cout<<"\n Insufficient Balance";
return;
}
t=t->next;
}
}
void Current::c_balance()
{
struct ban *t;
long int a;
cout<<"\n Enter the Account Number :";
cin>>a;
t=start;
while(t!=NULL)
{
if(t->acn==a)
{
cout<<"Available Bal:"<<t->bal;
}
else
{
cout<<"\n Not found";
return;
}
t=t->next;
}
}
void main()
{
Bank ob;
Savings obj;
Current obj1;
char uc,ta;
int s,s1,c,i=0,lo;
do
{
top:
cout<<"\n Enter your choice : \n 1.Open Account \n 2.Delete Account \n 3.Access Account\n
4.Exit";
cin>>s;
switch(s)
{
case 1:

if(i<2)
{
ob.openacc();
i++;
}
else
{
cout<<"\n Account cannot be opened";
goto top;
}
break;
case 2:
ob.delacc();
i--;
break;
case 3:
cout<<"\n Enter your choice: \n S for Saving Account \n C for Currnt Accont";
cin>>uc;
if(uc=='S' || uc=='s')
{
cout<<"\n........SAVINGS ACCOUNT..........";
cout<<"\n Enter your choice : \n 1.Deposit \n 2.Withdrawal \n 3.Check Balance \n
4.Return to Main Menu";
cin>>s1;
switch(s1)
{
case 1:
obj.s_deposit();
break;
case 2:
obj.s_withdraw();
break;
case 3:
obj.s_balance();
break;
case 4:
goto top;
default:
cout<<"\n Wrong Choice";
}
}
if(uc=='C' || uc=='c')
{
cout<<"\n............CURRENT ACCOUNT...........";
cout<<"\n Enter your choice : \n 1.Deposit \n 2.Withdrawal \n 3.Check Balance \n 4.Return
to Main Menu";
cin>>s1;
switch(s1)
{
case 1:
obj1.c_deposit();
break;
case 2:
obj1.c_withdraw();
break;
case 3:
obj1.c_balance();
break;
case 4:
goto top;
default:
cout<<"\n Wrong Choice";
}
break;
case 4:
cout<<"\n Thankyou for banking with us....";
exit(0);
default:
cout<<"\n Wrong Choice";
}
}

cout<<"\n Do you wish to continue?(enter 1 to continue /0 to exit)";


cin>>lo;

}
while(lo==1);
}
5.Shape Program.
#include<iostream.h>
#define pi 3.14
class Shape
{
public:
void disp(float r)
{
cout<<r<<" sq. unit";
}
};
class Rectangle:Shape
{
float l,b,a;
public:
Rectangle(float x,float y)
{
l=x;
b=y;
}
void rect()
{
a=l*b;
cout<<"\n Area of Rectangle : ";
Shape::disp(a);
}
};
class Square:Shape
{
float s,as;
public:
Square(float m)
{
s=m;
}
void squ()
{
as=s*s;
cout<<"\n Area of Square : ";
Shape::disp(as);
}
};
class Circle:Shape
{
float r,ac;
public:
Circle(float rad)
{
r=rad;
}
void circ()
{
ac=pi*r*r;
cout<<"\n Area of Circle : ";
Shape::disp(ac);
}
};
void main()
{
Rectangle obj(5.0,7.8);
obj.rect();
Square obj2(8.0);
obj2.squ();
Circle obj3(7.5);
obj3.circ();
}
6.Set operation using object passing.
#include<iostream.h>
class Set
{
public:
int a[10],b[20],i,j,k;
void inp();
void intersn(Set o1,Set o2);
void unio(Set o1,Set o2);
void minu(Set o1,Set o2);
};
void Set::inp()
{
cout<<"\n Enter the array :";
for(i=0;i<5;i++)
{
cin>>a[i];
}
}
void Set::intersn(Set o1,Set o2)
{
cout<<"\n Intersection";
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(o1.a[i]==o2.a[j])
{
cout<<o1.a[i]<<"\t";
}
}
}
}
void Set::unio(Set o1,Set o2)
{
int f=0,s=0;
j=0;
for(i=0;i<5;i++)
{
b[j]=o1.a[i];
j++;
}
for(i=0;i<5;i++)
{
for(k=0;k<5;k++)
{

if(o2.a[i]==o1.a[k])
{

f=1;
}
}
if(f!=1)
{
b[j]=o2.a[i];
j++;

}
f=0;
}
s=j;
cout<<"\n Union: ";
for(i=0;i<s;i++)
{
cout<<b[i]<<"\t";
}

}
void Set::minu(Set o1,Set o2)
{
int f=0;
cout<<"\n A-B : ";
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(o1.a[i]==o2.a[j])
{
f=1;
}
}
if(f!=1)
{
cout<<o1.a[i]<<"\t";
}
f=0;
}
}
void main()
{
int ch;
Set obj1,obj2;
obj1.inp();
obj2.inp();
Set obj3;
cout<<"\n Enter 1 to find Union\n 2 to find intersection\n 3 to find A-B";
cin>>ch;
switch(ch)
{
case 1:
obj3.unio(obj1,obj2);
break;
case 2:
obj3.intersn(obj1,obj2);
break;
case 3:
obj3.minu(obj1,obj2);
break;
default:
cout<<"Wrong Choice";
}
}
7.Program to check whether the given string is Anagram or not.
#include<iostream.h>
#include<stdio.h>
int slen(char x[])
{
int c=0,i;
for(i=0;x[i]!=NULL;i++)
{
c++;
}
return c;
}
int main()
{
char str1[20], str2[20];
int len, len1, len2, i, j, found=0, not_found=0;
cout<<"Enter first string:\n";
cin>>str1;
cout<<"Enter second string:\n";
cin>>str2;
len1 = slen(str1);
len2 = slen(str2);
if(len1 == len2)
{
len = len1;
for(i=0; i<len; i++)
{
found = 0;
for(j=0; j<len; j++)
{
if(str1[i] == str2[j])
{
found = 1;
break;
}
}
if(found == 0)
{
not_found = 1;
break;
}
}
if(not_found == 1)
cout<<"\nStrings are not Anagram";
else
cout<<"\nStrings are Anagram";
}
else
cout<<"\nBoth string must contain same number of character to be an Anagram
Strings";
return 0;
}
8.Program to input 4*4 array & swap first and last row.
#include<iostream.h>
class Ar
{
int a[20][20],i,j;
public:
void get();
void arr();
};
void Ar::get()
{
cout<<"\nEnter 4*4 array";
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
cout<<"\n enter element for " << i <<" row "<< j <<" column";
cin>>a[i][j];
}
}
cout<<"\n enterd array\n";
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}

}
void Ar::arr()
{
int t;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(i==0)
{
t=a[i][j];
a[i][j]=a[i+3][j];
a[i+3][j]=t;
}
}
}
cout<<"\n After swapping\n";
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{

cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
}
void main()
{
Ar obj;
obj.get();
obj.arr();
}

9.Program to input 10 students name in an array & display only those students name whose
name starts with vowel and ends with consonant.
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class Qn
{
char nm[30][30];
int i,j;
public:
void get();
};
void Qn::get()
{
int l=0,k=0;
char f,e;
cout<<"\n Enter students name\n";
for(i=0;i<10;i++)
{
for(j=0;j<1;j++)
{
cout<<"enter " <<i+1<<"students name : ";
gets(nm[i]);
}
}
cout<<"names starting with vowel and ending with consonant are:\n";
for(i=0;i<10;i++)
{
for(j=0;j<1;j++)
{
l=strlen(nm[i]);
f=nm[i][0];
e=nm[i][l-1];
if((f=='a' || f=='e' || f=='i' || f=='o' || f=='u' || f=='A' || f=='E' || f=='I' || f=='O' || f=='U' ) && (e!
='a'&& e!='e' && e!='i' && e!='o' && e!='u' && e!='A' && e!='E' && e!='O' && e!='I' &&
e!='U'))
puts(nm[i]);
}
}
}
void main()
{
Qn obj;
obj.get();
}
10.Wap to input student name, roll number, address & show details of the student using copy
constructor.
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class Ab
{
public:
long int rn;
char nm[20];
char add[35];
Ab(long int r,char n[],char a[])
{
rn=r;
strcpy(nm,n);
strcpy(add,a);
}
Ab(Ab &p)
{
rn=p.rn;
strcpy(nm,p.nm);
strcpy(add,p.add);
}
void put();
};
void Ab::put()
{
cout<<"Roll no : "<<rn<<"\n" <<"Students Name : "<<nm<<"\n"<<"Address : "<<add<<"\
n";
}
void main()
{
long int r;
char n[20],a[35];
cout<<"\n Enter roll no. : ";
cin>>r;
cout<<"\n Enter students name : ";
gets(n);
cout<<"\n Enter address : ";
gets(a);
Ab obj(r,n,a);
Ab obj2(obj);
cout<<"\n Using Copy Constructor \n";
obj2.put();
}
11.Program to make few Java/python built-in function.
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class Az
{
public:
char s[30],c[30],sr[60];
int i,j,k;
void inp();
void substr(int ,int );
void substrd(int );
int indexo(char );
int lindex(char );
char chari(int );
void appends(char [],char []);
};
void Az::inp()
{
cout<<"Enter a string\n";
gets(s);
}

void Az::substr(int x,int y)


{
j=0;
for(i=x;i<y;i++)
{
c[j]=s[i];
j++;
}
c[j]=NULL;
for(i=0;c[i]!=NULL;i++)
{
cout<<c[i];
}
}
void Az::substrd(int x)
{
j=0;
for(i=x;s[i]!=NULL;i++)
{
c[j]=s[i];
j++;
}
c[j]=NULL;
for(i=0;c[i]!=NULL;i++)
{
cout<<c[i];
}
}
int Az::indexo(char z)
{
k=0;
for(i=0;s[i]!=NULL;i++)
{
if(s[i]==z)
{
k=i;
break;
}
}
return k;
}
int Az::lindex(char m)
{
k=0;
int l;
l=strlen(s);
for(i=l-1;i>=0;i--)
{
if(s[i]==m)
{
k=i;
break;
}
}
return k;
}
char Az::chari(int t)
{
char u;
for(i=0;s[i]!=NULL;i++)
{
if(i==t)
{
u=s[i];
break;
}
}
return u;
}
void Az::appends(char q[],char m[])
{
j=0;
for(i=0;q[i]!=NULL;i++)
{
sr[j]=q[i];
j++;
}
for(i=0;m[i]!=NULL;i++)
{
sr[j]=m[i];
j++;
}
sr[j]=NULL;
for(i=0;sr[i]!=NULL;i++)
{
cout<<sr[i];
}
}
void main()
{
int a,b,p,t,c,m=0;
char o,u;
char x[30],y[30];
Az obj;
cout<<"\nEnter your choice\n 1.substr()\n2.substrd()\n3.indexof()\n4.charat()\
n5.lastindexof()\n6.append()\n";
cin>>t;
do
{
switch(t)
{
case 1:
obj.inp();
cout<<"Enter the starting index for a substring\n";
cin>>a;
cout<<"Enter the last index for a substring\n";
cin>>b;
obj.substr(a,b);
break;
case 2:
obj.inp();
cout<<"Enter the starting index for a substring\n";
cin>>c;
obj.substrd(c);
break;
case 3:
obj.inp();
cout<<"Enter the character to find the index \n";
cin>>u;
obj.indexo(u);
break;
case 4:
obj.inp();
cout<<"Enter the index of the charcter to be displayed\n";
cin>>p;
cout<<obj.chari(p);
break;
case 5:
obj.inp();
cout<<"Enter the character to find the index from last \n";
cin>>o;
cout<<obj.lindex(o);
break;
case 6:
cout<<"\nEnter first string";
gets(x);
cout<<"\nEnter second string";
gets(y);
obj.appends(x,y);
break;
default:
cout<<"\nWrong Choice";
}
cout<<"\n Press 1 to continue\n 0 to exit";
cin>>m;
}
while(m==1);
}
12.Program to find the smallest and the largest word from the string .

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include<string.h>

class Ls {
char sentence[40], word[20], largest[20],smallest[20];
int i;

public:
void large(char []);
void small(char []);
};

void Ls::large(char sentence[20]) {


int max = 0, count = 0, j = 0;

for (i = 0; sentence[i] != '\0'; i++) {


if (sentence[i] != ' ') {
word[j] = sentence[i];
j++;
if (sentence[i + 1] == '\0') {
word[j] = '\0';
count = strlen(word);
if (max < count) {
max = count;
strcpy(largest, word);
}
j = 0;
}
}
else {
word[j] = '\0';
count = strlen(word);
if (max < count) {
max = count;
strcpy(largest, word);
}
j = 0;
}
}
cout << "The largest word is " << largest;
}

void Ls::small(char sentence[20])


{
int min = 1000, count = 0, j=0;

for (i = 0; sentence[i] != '\0'; i++) {


if (sentence[i] != ' ') {
word[j] = sentence[i];
j++;
if (sentence[i + 1] == '\0') {
word[j] = '\0';
count = strlen(word);
if (min>count) {
min = count;
strcpy(smallest, word);
}
j = 0;
}
}
else {
word[j] = '\0';
count = strlen(word);
if (min>count) {
min = count;
strcpy(smallest, word);
}
j = 0;
}
}
cout << "The smallest word is " << smallest;
}

int main()
{
char sen[20];
Ls obj;
cout<<"\nEnter a sentence: ";
cin.getline(sen,20);

obj.large(sen);
cout<<"\n";
obj.small(sen);
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy