Beruflich Dokumente
Kultur Dokumente
SCIENCE
PRACTICAL FILE
#include <iostream>
using std::cout;
using std::cin;
int main()
cout << "1. Enter hours, minutes and seconds (range 00:00:00 -
23:59:59): ";
{
if(hour1 < 23)
cout << "Passed seconds from last 12 (am or pm): " <<
passedSeconds(hour1, minute1,second1);
cout << "\n2. Enter hours, minutes and seconds (range 00:00:00 -
23:59:59): ";
return 0;
}
int passedSeconds(int hour, int minute, int second)
hour -= 12;
}
1. Enter hours, minutes and seconds (range 00:00:00 - 23:59:59): 2
3
3
Passed seconds from last 12 (am or pm): 7383
2. Enter hours, minutes and seconds (range 00:00:00 - 23:59:59): 5
6
7
#include<iostream>
#include<cstdlib>
using namespace std;
float area(float r)
{
return(3.14 * r * r);
}
float area(float b,float h)
{
return(0.5 * b * h);
}
float area(int p, int k)
{
return (l * b);
}
int main()
{
float b,h,r,l;
int ch,k,p;
do
{
cout<<"\n\n *****Menu***** \n";
cout<<"\n 1. Area of Circle";
cout<<"\n 2. Area of Triangle";
cout<<"\n 3. Area of Rectangle";
cout<<"\n 4. Exit";
cout<<"\n\n Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1:
{
cout<<"\n Enter the Radius of Circle : ";
cin>>r;
cout<<"\n Area of Circle : "<<area(r);
break;
}
case 2:
{
cout<<"\n Enter the Base & Height of Triangle : ";
cin>>b>>h;
cout<<"\n Area of Triangle : "<<area(b,h);
break;
}
case 3:
{
cout<<"\n Enter the Length & Breadth of Rectangle
: ";
cin>>l>>b;
cout<<"\n Area of Rectangle : "<<area(p,k);
break;
}
case 4:
exit(0);
default:
cout<<"\n Invalid Choice... ";
}
}while(ch!=4);
return 0;
}
*****Menu******
1. Area of circle
2. Area of Triangle
3. Area of rectangle
4. Exit
1. Area of circle
2. Area of Triangle
3. Area of rectangle
4. Exit
1. Area of circle
2. Area of Triangle
3. Area of rectangle
4. Exit
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
int addno;
char name[21];
int Class;
int rollno;
public:
void getdata()
{
cout<<"Enter Addmission No.:";
cin>>addno;
cout<<"Enter Name:";
gets(name);
cout<<"Enter Class:";
cin>>Class;
cout<<"Enter Roll No.:";
cin>>rollno;
}
void showdata()
{
cout<<"\nAddmission No.:"<<addno;
cout<<"Name:";
puts(name);
cout<<"\nClass:"<<Class;
cout<<"\nRoll No.:"<<rollno;
}
}J[10];
void main()
{
for(int i=0;i<10;i++)
{
cout<<"\nStudent "<<i<<endl;
J[i].getdata();
}
for(i=0;i<10;i++)
{
cout<<"\nStudent "<<i<<endl;
J[i].showdata();
}
getch();
}
PROGRAM 4 :
private members :
for material other than “COTTON”, the above mentioned GPprice price
gets reduced by 25%
public members :
PTO
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
class clothing
{ char Code[21],Type[21];
int size;
char material[21];
float price;
void calc_price( )
{
if(strcmp(strupr(material),"COTTON")==0)
{ if(strcmp(strupr(Type),"TROUSER")==0)
price=1500;
if(strcmp(strupr(Type),"SHIRT")==0)
price=1200;
}
else
{ if(strcmp(strupr(Type),"TROUSER")==0)
price=1500*0.75;
if(strcmp(strupr(Type),"SHIRT")==0)
price=1200*0.75;
}
}
public:
clothing( )
{ strcpy(Code,"NOT ALLOTED");
strcpy(Type,"NOT ALLOTED");
size=0;
strcpy(material,"NOT ALLOTED");
price=0;
}
void enter( )
{ cout<<"\nEnter the Cloth Code: ";
gets(Code);
cout<<"\nEnter the Cloth Type: ";
gets(Type);
cout<<"\nEnter the Cloth Size: ";
cin>>size;
cout<<"\nEnter the cloth material:";
gets(material);
calc_price( );
}
void show( )
{ cout<<"\nThe Cloth Code: "<<Code;
cout<<"\nThe Cloth Type: "<<Type;cout<<"\nThe Cloth Size:
"<<size;
cout<<"\nThe Cloth Material: “ <<material;
cout<<"\nThe Cloth Price: "<<price; } };
void main( )
{ clothing C;
C.enter( );
C.show( );
}
Program 5:
#include<iostream>
#include<string>
using namespace std;
class Publication
{
private:
string title;
float price;
public:
void getData()
{
cout<<“\nEnter Title: ”; cin>>title;
cout<<“Enter Price: $”; cin>>price;
}
void putData()
{ cout<<“\nTitle: ”<<title<<“\nPrice: ”<<price; }
};
//\////\////\////\////\////\////\////\////\////\////\////\//
//\////\////\////\////\////\////\////\////\////\////\////\//
void putData()
{ Publication::putData(); cout<<“\nPages: ”<<pages; }
};
//\////\////\////\////\////\////\////\////\////\////\////\//
//\////\////\////\////\////\////\////\////\////\////\////\//
void putData()
{ Publication::putData(); cout<<“\nMinutes: ”<<minutes; }
};
int main()
{
Book b; Tape t;
b.getData();
t.getData();
return 0;
}
Program 6:
#include <iostream>
using namespace std;
public:
// main function
int main() {
#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main()
{
ifstream fin("STORY.txt"); //opening text file
int count=0;
char ch[20],c[20],b[20],q[20];
c[20]= ‘The’;
b[20]=’THE’;
q[20]=’the’;
while(fin)
{
fin>>ch;
if(strcmp(ch,c)==0||strcmp(ch,b)==0||strcmp(ch,a)==0)
count++;
}
cout<<"Occurrence="<<count<<"n";
fin.close(); //closing file
return 0;
}
Program 8 :
Write a program to input a text file name, read the contents of the
file and create a new file named COPY.TXT, which shall contain
only those words from the original file which don’t start with an
uppercase vowel (i.e., with ‘A’, ‘E’, ‘I’, ‘O’, ‘U’). For example, if the
original file contains
The First Step To Getting The Things You Want Out Of Life
is This: Decide What You Want. - Ben Stein
The First Step To Getting The Things You Want Life is This:
Decide What You Want. - Ben Stein
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
FILE *input;
FILE *output;
input=fopen("input.txt","r");
output=fopen("Copy.Txt","w");
char s[100];
while(!feof(input)) {
fscanf(input,"%s",s);
if(!(s[0]=='A'||s[0]=='E'||s[0]=='I'||s[0]=='O'||s[0]=='U')) {
fprintf(output,"%s ",s);
}
}
fclose(input);
fclose(output);
return 0;
Program 9:
Write a program to Copy one file onto the end of another, adding line
numbers
#include <stdio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
fclose(fptr1);
fclose(fptr2);
return 0;
}
Output:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>
class phoneBook{
char name[20],phno[6];
public:
void getdata();
void showdata();
char *getname(){ return name; }
char *getphno(){ return phno; }
void update(char *nm,char *telno){
strcpy(name,nm);
strcpy(phno,telno);
}
};
void phoneBook :: getdata(){
cout<<"\nEnter Name : ";
cin>>name;
cout<<"Enter Phone No. : ";
cin>>phno;
}
void main(){
phoneBook rec;
fstream file;
file.open("c:\\phone.dat", ios::ate | ios::in | ios::out | ios::binary);
char ch,nm[20],telno[6];
int choice,found=0;
while(1){
clrscr();
cout<<"\n*****Phone Book*****\n";
cout<<"1) Add New Record\n";
cout<<"2) Display All Records\n";
cout<<"3) Search Telephone No.\n";
cout<<"4) Search Person Name\n";
cout<<"5) Update Telephone No.\n";
cout<<"6) Exit\n";
cout<<"Choose your choice : ";
cin>>choice;
switch(choice){
case 1 : //New Record
rec.getdata();
cin.get(ch);
file.write((char *) &rec, sizeof(rec));
break;
Program 11 :
Write a program using pointers to find the length of a string and print
reversed string
#include <stdio.h>
#include <string.h>
// swap character
ch = *end_ptr;
*end_ptr = *begin_ptr;
*begin_ptr = ch;
// Driver code
int main()
{
return 0;
}