Professional Documents
Culture Documents
Computer - Copy-1
Computer - Copy-1
h>
#include<stdlib.h>
#include<conio.h>
}
void amount(int time, float rate)
{ cout <<"nPrincipal Amount : 2000";
cout << "tTime :" << time <<" years";
cout<<"\tRate :" << rate ;
cout <<"nInterest Amount:" << (2000 *time *rate) <<
"\n";
}
void amount(float princ)
{ cout <<"InPrincipal Amount:" << princ;
cout << "tTime: 2 years";
cout << "tRate :0.08";
cout << "nInterest Amount:"<< (princ *2 * 0.08)
<<"\n";
}
void main ()
{ system ("cls");
cout <<"Case 1";
amount(2000.0F);
cout << "Case 2";
amount(2500.0F, 3);
cout << "Case 3";
amount(2300.0F,3,0.11F);
cout <<"Case 4" ;
amount(2, 0.12F);
cout << "Case 5";
amount(6, 0.07F);
getch();
}
#include<iostream.h>
#include<stdlib.h>
class ITEM {
int itemcode[50];
float it_price[50];
public:
void initialize (void);
float largest (void);
float sum (void);
void display_Items (void);
};
void ITEM::initialize (void)
{ for(int i= 0;i< 50; i++)
{ cout <<" Item No: "<< (i+1) ;
cout <<"\n "<<"<Enter Item code: " ;
cin >> itemcode[i];
cout<<"\n "<<" Enter item price: ";
cin >> it_price[i] ;
cout<<"\n";}
}
float ITEM:: largest(void)
{ float large=it_price[0];
for( int i= 1; i < 50; i++)
{
if(large < it_price[0])
large= it_price[i] ;}
return large;
} float ITEM :: sum (void)
{ ITEM order;
order.initialize();
void puttime(void)
{ cout <<"Time is:"<<hrs <<":" <<mins << ":"<<
secs <<"\n"; }
void convert(Time t, char ch) ;
void sum(Time t1, Time t2);
int gethrs() {return hrs ; }
int getmins(){ return mins;}
int getsecs() {return secs;} };
void Time:: convert(Time t, char ch)
{
switch(ch)
{ case 'h': cout <<" Time in hours is : "
<<t.hrs <<":"<< t.mins <<": " << t.secs
<< " hrs \n ";
break;
case 'p': cout<< "Time in am/pm is:"
<< ((t.hrs>12)? (t.hrs-12): t.hrs)<<":
"
<< t.mins << ": "<< t.secs;
cout << ((t.hrs > 12)?" pm": "am
")<<"\n ";
break;
default: cout <<" Wrong choice \n " ;
}; }
void Time::sum(Time t1, Time t2)
{int h, m, s, sq, mq;
sq = (t1.secs+ t2.secs)/60 ;
s = (t1.secs + t2.secs)%60;
mq =(sq + t1.mins + t2.mins)/60;
m = (sq + t1.mins + t2.mins) %60;
h = mq + t1.hrs + t2.hrs;
if (h == 24) h = 0;
cout<< "Total time:
"<<h<<":"<<m<<":"<<s<<"\n "; }
void prnvalues(Time t1)
{cout<<"total sec: "<<t1.tot_secs;
cout<<"\n";
}
int main ()
{Time tm1, tm2;
int tt;
tm1.gettime (15, 13, 27);
tm2.gettime (7, 48, 38);
cout << "Enter h to
convert in hours format, p for arn / pm format:";
char ch;
cin>>ch;
tm1. convert
(tm2,ch);
tm1. sum
(tm1,tm2);
prnvalues(tm2);
return 0;
}
#include<iostream.h>
#include<string.h>
class Time { int hrs, mins, secs;
char suf[4];
public:
int tot_secs;
void gettime(int h , int m, int s)
{ hrs= h;
mins= m;
secs= s;
tot_secs =(hrs* 60) +(mins *60)+secs;
strcpy{suf,"Hrs"};
}
void puttime(void)
{ cout <<"Time is:"<<hrs <<":" <<mins << ":"<<
secs <<"\n"; }
char*getsuf()
{return suf;}void convert(Time t, char ch) ;
void sum(Time t1, Time t2);
int gethrs() {return hrs ; }
int getmins(){ return mins;}
int getsecs() {return secs;} };
void Time:: convert(Time t, char ch)
{
switch(ch)
{ case 'h':if(strcmp(t.suf,"Hrs")!=0)
{t.hrs=(strcmp(t.suf,"am")==0?t.hrs:t.hrs+12;
cout <<" Time in hours is : "
<<t.hrs <<":"<< t.mins <<": " << t.secs
<< "<<t.suf<< " \n ";
break;
case 'p': cout<< "Time in am/pm is:"
<< ((t.hrs>12)? (t.hrs-12): t.hrs)<<":
"
<< t.mins << ": "<< t.secs;
cout << ((t.hrs > 12)?" pm": "am
")<<"\n ";
break;
default: cout <<" Wrong choice \n " ;
}; }
void Time::sum(Time t1, Time t2)
{int h, m, s, sq, mq;
sq = (t1.secs+ t2.secs)/60 ;
s = (t1.secs + t2.secs)%60;
mq =(sq + t1.mins + t2.mins)/60;
m = (sq + t1.mins + t2.mins) %60;
h = mq + t1.hrs + t2.hrs;
if (h == 24) h = 0;
cout<< "Total time:
"<<h<<":"<<m<<":"<<s<<"\n "; }
void prnvalues(Time t1)
{cout<<"total sec: "<<t1.tot_secs;
cout<<"\n";
}
int main ()
{Time tm1, tm2;
int tt;
tm1.gettime (15, 13, 27);
tm2.gettime (7, 48, 38);
cout << "Enter h to
convert in hours format, p for arn / pm format:" char
ch;
cin>>ch;
tm1. convert (tm2,ch);
tm1. sum (tm1,tm2);
prnvalues(tm2);
return 0;
}
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
class Deposit{
long int principal;
int time ;
float rate;
float total_amt;
public:
Deposit() ;
Deposit(long p, int t, float r);
Deposit(long p, int t);
Deposit(long p, float r);
void calc_amt(void);
void display(void);
};
Deposit:: Deposit()
{ principal =time= rate = 0.0; }
Deposit::Deposit(long p, int t, float r)
{ principal = p; time= t; rate= r;}
Deposit::Deposit(long p, int t)
{ principal = p; time= t;rate=0.08; }
Deposit::Deposit(long p,float r )
{ principal =p; time = 2;rate=r;}
void Deposit::calc_amt(void)
{ total_amt=principal+(principal* time*rate)/100;
}
void Deposit::display(void)
{ cout <<" \nPrincipal Amount : Rs. "<< principal;
cout <<"t Period of investment: "<<time<<"years";
cout <<" \nRate of interest:" <<rate;
cout <<" \tTotal Amount: Rs. " << total_amt<<" \n
" ;
}
void main()
{ system (" cls ");
Deposit D1, D2(2000,2,0.07f), D3(4000,1),
D4(3000,0.12f);
D1.calc_amt();
D2.calc_amt();
D3.calc_amt();
D4.calc_amt();
cout <<"Object \n"; D1.display();
cout << "Object 2\n "; D2.display() ;
cout <<"Object 3\n"; D3.display();
cout <<"Object 4\n"; D4.display();
getch();
}
#include <iostream.h>
#include<stdlib.h>
#include<conio.h>
class Base {
public:
int a ;
};
class D1: virtual public Base
{ public:
int b;
};
class D2 : virtual public Base
{ public:
int c;
};
class D3 : public D1, public D2
{ public:
int total;
};
void main()
{system (" cls ");
D3 ob;
ob.a = 25;
ob.b = 50;
ob.c = 75;
ob.total = ob.a + ob.b + ob.c;
cout<<ob.a <<" \t " <<ob.b << "\t" <<ob.c<<" \t "
<<ob.total <<endl;
getch();
}
#include<iostream.h>
#include<fstream.h>
class stu{ int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"Rollno:"; cin>>rollno;
cout<<"Name:";cin>>name;
cout<<"Class:";cin>>Class;
cout<<"Marks:";cin>>marks;
if(marks>=75)grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
void putdata()
{
cout<<name<<",rollno"<<rollno<<"has"<<marks<<"%marks
and"<<grade<<"grade."<<endl;
}
int getrno()
{ return rollno;
}
}s1;
int main()
{ ofstream fo("stu.dat",ios::app|ios::binary);
char ans='y';
while(ans=='y')
{ s1.getdata();
fo.write((char*)&s1,sizeof(s1));
cout<<"Record added to file.\n";
cout<<"Want to enter more records?(y/n)..";
cin>>ans;
}
fo.close();
return 0;
}
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
class stu{ int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"Rollno:"; cin>>rollno;
cout<<"Name:";cin>>name;
cout<<"Class:";cin>>Class;
cout<<"Marks:";cin>>marks;
if(marks>=75)grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
void putdata()
{
cout<<",Rollno"<<rollno<<"\tName:"<<name<<"\nMarks:"<
<marks<<"\tGrade:"<<grade<<endl;
}
int getrno()
{ return rollno;
}
}s1,stud;
int main()
{ ifstream fi("stu.dat",ios::in|ios::binary);
ofstream fo("temp.dat",ios::out|ios::binary);
char last='y';
cout<<"Enter details of student whose record is
to be inserted\n";
s1.getdata();
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(s1.getrno()<=stud.getrno())
{ fo.write((char*)&s1,sizeof(s1));
last='n';
break;
}
else
fo.write((char*)&stud,sizeof(stud));
}
if(last=='y')
fo.write((char*)&s1,sizeof(s1));
else if(!fi.eof())
{ while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
fo.write((char*)&stud,sizeof(stud));
}
}
fi.close();
fo.close();
remove("stu.dat");
rename("temp.dat","stu.dat");
fi.open("stu.dat",ios::in);
cout<<"file now contains\n";
while(!fi.eof())
{ fi.read((char*)&stud,sizeof(stud));
if(fi.eof())break;
stud.putdata();
}
fi.close();
return 0;
}
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
class stu{ int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"Rollno:"; cin>>rollno;
cout<<"Name:";cin>>name;
cout<<"Class:";cin>>Class;
cout<<"Marks:";cin>>marks;
if(marks>=75)grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
void putdata()
{
cout<<",Rollno"<<rollno<<"\tName:"<<name<<"\nMarks:"<
<marks<<"\tGrade:"<<grade<<endl;
}
int getrno()
{ return rollno;
}
}s1,stud;
int main()
{ clrscr();
ifstream fio("stu.dat",ios::in);
ofstream file("temp.dat",ios::out);
int rno; char found='f',confirm='n';
cout<<"enter rollno of student whose record is to
be deleted\n";
cin>>rno;
while(!fio.eof())
{ fio.read((char*)&s1,sizeof(s1));
if(s1.getrno()==rno)
{ s1.putdata();
found='t';
cout<<"Are you sure,you want to delete this
record?(y/n)..";
cin>>confirm;
if(confirm=='n')
file.write((char*)&s1,sizeof(s1));
}
else
file.write((char*)&s1,sizeof(s1));
}
if(found=='f')
cout<<"Record not found!!\n";
fio.close();
file.close();
remove("stu.dat");
rename("temp.dat","stu.dat");
fio.open("stu.dat",ios::in);
cout<<"Now the file contains\n";
while(!fio.eof())
{
fio.read((char*)&stud,sizeof(stud));
if(fio.eof())break;
stud.putdata();
}
fio.close();
getch();
return 0;
}
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
class stu{ int rollno;
char name[25];
char Class[4];
float marks;
char grade;
public:
void getdata()
{ cout<<"Rollno:"; cin>>rollno;
cout<<"Name:";cin>>name;
cout<<"Class:";cin>>Class;
cout<<"Marks:";cin>>marks;
if(marks>=75)grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
void putdata()
{
cout<<",Rollno"<<rollno<<"\tName:"<<name<<"\nMarks:"<
<marks<<"\tGrade:"<<grade<<endl;
}
int getrno()
{ return rollno;}
void modify();
}s1,stud;
void stu::modify()
{ cout<<"Rollno:"<<rollno<<endl;
cout<<"Name:"<<name<<"\tClass:"<<Class<<"\tMarks:
"<<marks<<endl;
cout<<"Enter new details."<<endl;
char nm[20]=" ",Cl[4]=" ";
float mks;
cout<<"New Name:(Enter'.'to retain old one)";
cin>>nm;
cout<<"New class:(press'.'to retain old one)";
cin>>Cl;
cout<<"New Marks:(press -1 to retain old one)";
cin>>mks;
if(strcmp(nm,".")!=0)
strcpy(name,nm);
if(strcmp(Cl,".")!=0)
strcpy(Class,Cl);
if(mks!=-1)
{ marks=mks;
if(marks>=75) grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
}
int main()
{ clrscr();
fstream
fio("stu.dat",ios::in|ios::out|ios::binary);
int rno; long pos; char found='f';
cout<<"Enter rollno of student whose record is to
be modified\n";
cin>>rno;
while(!fio.eof())
{ pos=fio.tellg();
fio.read((char*)&s1,sizeof(s1));
if(s1.getrno()==rno)
{ s1.modify();
fio.seekg(pos);
fio.write((char*)&s1,sizeof(s1));
found='t';
break;
}
}
if(found=='f')
cout<<"Record not found!!\n";
fio.seekg(0);
cout<<"Now the file contains\n";
while(!fio.eof())
{
fio.read((char*)&stud,sizeof(stud));
stud.putdata();
}
fio.close();
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
void Selsort(int[],int);
int main()
{
clrscr();
int AR[50],ITEM,N,index;
cout<<"how many elements do you want to create array
with?(max 50)...";
cin>>N;
cout<<"\n Enter Array elements...";
for(int i=0;i<N;i++)
{
cin>>AR[i];
}
Selsort(AR,N);
cout<<"\n\nThe Sorted array is as shown below...\n";
for(i=0;i<N;i++)
{
cout<<AR[i]<<" ";
}
cout<<endl;
getch();
return 0;
}
void Selsort(int AR[],int size)
{
int small,pos,tmp;
for(int i=0;i<size-1;i++)
{
small=AR[i];
pos=i;
for(int j=i+1;j<size;j++)
{
if(AR[j]<small)
{
small=AR[j];
pos=j;
}
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
cout<<"\nArray after pass-"<<i+1<<"-is:";
for(j=0;j<size;j++)
{
cout<<AR[j]<<" ";
}
}
#include<iostream.h>
#include<conio.h>
void Bubblesort(int[],int);
int main()
{
clrscr();
int AR[50],ITEM,N,index;
cout<<"\nHow many elements do U want to create Array
with?(max 50)...";
cin>>N;
cout<<"\nEnter the array Elements...\n";
for(int i=0;i<N;i++)
{
cin>>AR[i];
}
Bubblesort(AR,N);
cout<<"\n\nThe sorted array is as shown below...\n";
for(i=0;i<N;i++)
{
cout<<AR[i]<<" ";
}
cout<<endl;
getch();
return 0;
}
void Bubblesort(int AR[],int size)
{
int tmp,ctr=0;
for(int i=0;i<size;i++)
{
for(int j=0;j<(size-1);j++)
{
if(AR[j]>AR[j+1])
{
tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;
}
}
cout<<" Array after iteration-"<<++ctr<<"-is:";
for(int k=0;k<size;k++)
{
cout<<AR[k]<<" ";
}
cout<<endl;
}
}
#include<iostream.h>
#include<limits.h>
#include<conio.h>
void Inssort(int[],int);
int main()
{
clrscr();
int AR[50],ITEM,N,index;
cout<<"how many elements fo U want to create array
with?(max 50)...";
cin>>N;
cout<<"\nEnter the array elements...";
for(int i=1;i<=N;i++)
{
cin>>AR[i];
}
Inssort(AR,N);
cout<<"\n\nThe sorted array is as shown below...\n";
for(i=1;i<=N;i++)
{
cout<<AR[i]<<" ";
}
cout<<endl;
getch();
return 0;
}
void Inssort(int AR[],int size)
{
int tmp,j;
AR[0]=INT_MIN;
for(int i=1;i<=size;i++)
{
tmp=AR[i];
j=i-1;
while(tmp<AR[j])
{
AR[j+1]=AR[j];
j--;
}
AR[j+1]=tmp;
cout<<"array after pass-"<<i<<"-s:";
for(int k=1;k<=size;k++)
{
cout<<AR[k]<<" ";
}
cout<<endl;
}
}
s
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
#include<conio.h>
int Push(int[],int&,int);
void Display(int[],int);
const int size=50;
int main()
{
clrscr();
int stack[size],item,top=-1,res;
char ch='y';
system("cls");
while(ch=='y'||ch=='Y')
{
cout<<"\nEnter Item for insertion:";
cin>>item;
res=Push(stack,top,item);
if(res==-1)
{
cout<<"OVERFLOW!!!aborting!!\n";
exit(1);
}
cout<<"\nThe stack now is:\n";
Display(stack,top);
cout<<"want to insert more elements?(y/n)";
cin>>ch;
}
getch();
return 0;
}
int Push(int stack[],int& top,int ele)
{
if(top==size-1)
{
return -1;
}
else
{
top++;
stack[top]=ele;
}
return 0;
}
void Display(int stack[],int top)
{
cout<<stack[top] <<" <--"<<endl;
for(int i=top-1;i>=0;i--
Submitted by:Vikash chand
Submitted to :Sunaina kataria
CERTIFICATE
Examiner’s Signature:
Principal:
Date:
Institution stamp
ACKNOWLEDGEMENT
This project also could not be completed without the help of my parents.
I would also like to thank my friends Upkar and Subham for their most
valuable effort to help me. Last but not the least; I would once again like
to express my gratitude to my friends, teachers, my parents for their
support and willingness to spend their important time with me.
Submitted by:Vikash chand BOARD ROLL NO.:-
Submitted to :Mrs.Swati ma’am
(CHEMISTRY PGT)
S.NO. PROGRAM DATE
1
2
3
4
5
6
7
8
Name:Vikash chand class:12-a
Roll no:26
Institution :MODERN SCHOOL VAISHALI
This is certified to be bonafide work of the student in the
computer laboratory during the academic year 2019-20.
Examiner’s Signature:
Principal:
Date:
Institution stamp
ACKNOWLEDGEMENT
This project also could not be completed without the help of my teachers,
my parents for their support and willingness to spend their important
time with me.