Computer Practical File
Computer Practical File
10
Program will read the words which starts from
vowels stored in a file.
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
main()
{
char ch[80];
int cnt=0;
clrscr();
ifstream f1(''emp'');
ofstream f2(''emp'');
while(!f1.eof())
f1>>ch;
cout<<ch<<"\n'';
if(ch[0]=='a' || ch[0]=='o' || ch[0]=='i' || ch[0]=='u')
f2<<"\n''<<ch;
}
f1.close();
f2.close();
cout<<"\n\nName start with vowels\n\n'';
f1.open(''temp''.ios::in);
while(f1) //while(!f1.eof())
{
f1>>ch;
cout<<"\n''<<ch;
if(f1.eof())
break;
}
f1.close();
getch();
}
Output no.10:
Program no.11
Program to store the basic information of employee.
a.Emp Id
b. Emp Name
c. Emp Address
d. Emp Dept (Admin/Sales/Production/IT)
e. Emp Phone
f. Emp Age-
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cstdlib>
#include<fstream>
using namespace std;
char empfile[30] = "Employee.txt";
char ITfile[20] = "IT.txt";
char Adminfile[25] = "Admin.txt";
char Prodfile[30] = "Production.txt";
char Salesfile[30] = "Sales.txt";
class emp
{
int empid;
char name[30];
char address[60];
int age;
public:
char dept[15];
void get();
char *getdept()
{
return dept;
}
};
void emp::get()
{
cout<<"\nEmployee Id : ";
cin>>empid;
cout<<"\n Enter Name : ";
cin>>name;
cout<<"\n Enter Address : ";
cin>>address;
cout<<"\n Enter Department Name:(Admin/Sales/IT/Production) : ";
cin>>dept;
cout<<"\nEnter Age : ";
cin>>age;
}
void insert()
{
emp e;
ofstream fout;
fout.open("Employee.txt",ios::in | ios::out | ios::binary | ios::app | ios::ate);
if (fout.fail())
{
cout<<"\n Unable to Open the File!!!";
goto err;
}
e.get(); // accepting the details from the user.
fout.write((char *)&e,sizeof(e));
if(fout.tellp()%sizeof(e)==0)
{
cout<<"\nRecord Inserted !!!"<<endl;
}
else
{
cout<<"\n Insertion Failed !!!";
goto err;
}
err:
fout.close();
}
void sort() // This function will insert the record according to department in
respective file.
{
emp e;
ofstream adm,sal,pro,it;.
ifstream fin;
adm.open(Adminfile, ios::out | ios::binary | ios::app);
sal.open(Salesfile, ios::out | ios::binary | ios::app);
pro.open(Prodfile, ios::out | ios::binary | ios::app);
it.open(ITfile, ios::out | ios::binary | ios::app);
fin.open(empfile, ios::in | ios::binary);
while(fin.read((char *)&e,sizeof(e)))
{
if(strcmp(e.getdept(),"Admin")==0)
{
adm.write((char *)&e,sizeof(e));
cout<<"\n Record Inserted into ADMIN File!!!";
}
else if(strcmp(e.getdept(),"Sales")==0)
{
sal.write((char *)&e,sizeof(e));
cout<<"\n Record Inserted into SALES File!!!";
}
else if(strcmp(e.getdept(),"IT")==0)
{
it.write((char *)&e,sizeof(e));
cout<<"\nRecord cord Inserted into IT File!!!";
}
else if(strcmp(e.getdept(),"Production")==0)
{
pro.write((char *)&e,sizeof(e));
cout<<"\nRecord cord Inserted into Production File!!!";
}
else
cout<<"\nRecord insert Correct Record!!!";
}
fin.close();
adm.close();
sal.close();
it.close();
pro.close();
}
int main()
{
int n;
cout<<"\n Enter No. of Records You Want? : ";
cin>>n;
for(int i=0; i<n; i++)
{
insert();
}
sort();
return 0;
}
Output no.11:
Program no.12
Deleting the information of employee by entering the
employee number.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#includee<stdio.h>
class abc
{
private:
int empno;
char n[20];
int age;
float sal;
public:
void getdata()
{
cout<<"\nEnter employee no'';
cin>>empno;
cout<<"\nEnter name'';
cin>>n;
cout<<"\nEnter age '';
cin>>age;
cout<<"\nEnter salary'';
cin>>sal;
}
void putdata()
{cout<<"\n\n''<<empno<<"\t''<<n<<"\t''<<age<<"\t<<sal;
}
int get_empno()
{
return empno;
}};
main()
{
abc p,p1;
clrscr();
ifstream f1(''emp5.txt'',ios::in|ios::binary);
ofstream f2(''temp'',ios::out|ios::binary);
int i,emp;
cout<<"\n\nNAME\tAGE\tSALARY;
f1.clear();
f1.seekg(0);
//for(i=0;i<4;i++)
while(!f1.eof())
{
f1.read((char*)&p1,sizeof(p1));
if(f1.eof())
break;
if(emp!=p1.get_empno())
f2.write((char*)&p1,sizeof(p1));
}
f1.close();
f2.close();
remove(''emp5.txt'');
rename(''temp'',''emp5.txt'');
f1.open(''emp5.txt'',ios::in|iost::binary);
cout<<"\n\nNAME\tAGE\tSALARY;
f1.seekg(0);
//for(i=0;i<3;i++)
while(!f1.eof())
{
f1.read((char*)&p1,sizeof(p1));
if(f1.eof())
break;
p1.putdata();
}
f1.close();
getch();
}
Output no.12:
Program no.13
Enter any number and its power and the output will
the power of the number.
#include<iostream.h>
#include<math.h>
#define CUBE(a,) pow(a,b)
//a>b?a:b
main(){
int x, y,z;
cout<<"\nEnter base value'';
cin>>x;
cout<<"\nEnter power'';
cin>>y;
z=CUBE(x,y);
cout<<"\n"<<z;
getch();}
Output no.13:
Program no.14
Enter 3 strings and the output will show the longest
string and the shortest string.
#include<iostream.h>
#include<string.h>
main(){
char n[20],n1[20],n2[20;
int 11,12,13;
cout<<"\nEnter string1'';
cin>>n1;
cout<<''\nEnter string2";
cin>>n2;
11=strlen(n);
12=strlen(n1);
13=strlen(n2);
(11>12 && 11>13)?cout"\nLong:"<<n:(12>11&&12>13)?cout<<"\
nLong:"<<n1:cout<<"\nLong:"<<n2;
(11<12 && 11<13)?cout"\short:"<<n:(12<11&&12<13)?cout<<"\
nshort:"<<n1:cout<<"\nshort:"<<n2;
getch();}
Output no.14:
Program no.15
Enter any number and the output will be all the prime
numbers up to that number.
#include<iostream.h>
#include<conio.h>
main(){
int n,i,j,p;
clrscr();
cout<<"\nEnter no of N";
cin>>n;
for(i=1;i<=n;i++)
{p=0;
for(j=2;j<2;j++)
if(i%j==0)
p=1;
if(p==0)
cout<<" "<<i;}
getch()}
Output no.15:
Program no.16
Program for selection sort.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],i,j,t,min,p;
cout<<"\n Enter no of elements in A";
cin>>n;
for(i=0;i<n;i++)
{cout<<"\nEnter no";
cin>>a[i];
// Processing
}
cout<<"\n\n'';
for(i=0;i<n;i++)
cout<<'' ''<<a[i];
{
min=a[i];
p=i;
for(j=i;i<n;i++)
{
if(a[j]<min)
{
min=a[j];
p=j;
}
}
t=a[i];
a[i]=a[p];
x[p]=t;
} // end of i for loop
// output phase
cout<<"\n\n"
for(i=0;i<n;i++)
cout<<" "<<a[i];
getch();
}
Output no.16:
Program no. 17
Using loop concept the program will give the output of
numbers making a right triangles.
#include<iostream.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=0;i<=4;i++)
{
cout<<"\n\n'';
for(j=1;j<=i;j++)
cout<<'' ''<<i;
}
getch();
}
Output no.17:
Program no.18
Create a C++ class for player object with the following
attributes player no., name, number of matches and
number of goals done in each match. The number of
matches varies for each player. Write parameterized
constructor which initializes player no., name, number of
subjects and creates array for number of goals and number
of matches dynamically,
#include<iostream>
using namespace std;
class Player
{
int player_no, no_of_matches;
char player_name[100];
int *goals;
public:
Player()
{
int i;
cout<<"\n Enter Player No. : ";
cin>>player_no;
cout<<"\n Enter Player Name : ";
cin>>player_name;
cout<<"\n Enter No. of Matches : ";
cin>>no_of_matches;
goals=new int [no_of_matches];
for(i=0; i<=no_of_matches - 1; i++)
{
cout<<"\n Enter No. of Goals in Match "<<i+1<<" : ";
cin>>goals[i];
}
}
void display()
{
int i;
cout<<"\n --------------------------------";
cout<<"\n Player No. : "<<player_no;
cout<<"\n Player Name : "<<player_name;
cout<<"\n No. of Matches Played : "<<no_of_matches;
for(i=0; i<=no_of_matches - 1; i++)
{
cout<<"\n Match "<<i+1<<" Goals : "<<goals[i];
}
}
};
int main()
{
Player P;
P.display();
return 0;
}
Output no.18:
Program no.19
Program for insertion sort.
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
void main()
{
clrscr();
int a[20],n,i,j,t;
// input
cout<<"Enter no of elements in A";
cin>>n;
for(i=0;i<n;i++)
{cout<<"\nEnter no'';
cin>>a[i];
}
// Processing
cout<<"\n\n'';
for(i=1;i<n;i++)
{cout<<'' ''<< a[i];
for(i=1;i<n;i++)
for(j=1;j<n;j++)
if(a[i]>a[j])
t=a[i];
a[i]=a[j];
a[j]=t;
}
// output
cout<<"\n\n'';
for(i=0;i<n;i++)
cout<<'' ''<<a[i];
getch();
}
Output no.19:
Program no.20
Write a C++ program to add two complex numbers using
operator overloaded by a friend function.
Following program is demonstrating operator overloading
by using friend function.
#include<iostream>
using namespace std;
class Complex
{
int num1, num2;
public:
void accept()
{
cout<<"\n Enter Two Complex Numbers : ";
cin>>num1>>num2;
}
//Overloading '+' operator using Friend function
friend Complex operator+(Complex c1, Complex c2);
void display()
{
cout<<num1<<"+"<<num2<<"i"<<"\n";
}
};
Complex operator+(Complex c1, Complex c2)
{
Complex c;
c.num1=c1.num1+c2.num1;
c.num2=c1.num2+c2.num2;
return(c);
}
int main()
{
Complex c1,c2, sum; //Created Object of Class Complex i.e c1 and c2
c1.accept(); //Accepting the values
c2.accept();
sum = c1+c2; //Addition of object
return 0;
}
Output no.20:
Program no.21
Program to demonstrating function overloading .
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
float calarea(float a, float b, float c)
{ float s, are;
s = (a+b+c)/2;
are = sqrt(s*(s-a)*(s-b)*(s-c));
return are;
}
float calarea(float a,
float b)
{
return a*b;
}
float calarea(float a)
{
return a*a;
}
void main()
{ clrscr();
int choice, s1, s2, s3, a;
do { cout<<"\nArea Calculation Main Menu\n";
cout<<"1.Triangle\n"; cout<<"2.Square\n";
cout<<"3.Rectangle\n"; cout<<"4.Exit\n";
cout<<"Enter your choice (1-4): ";
cin>>choice;
cout<<"\n";
switch(choice)
{ case 1: cout<<"Enter three sides: ";
cin>>s1>>s2>>s3;
a = calarea(s1, s2, s3);
cout<<"Area = "<<a;
break;
case 2: cout<<"Enter a side: "; cin>>s1;
a = calarea(s1);
cout<<"Area = "<<a;
break;
case 3: cout<<"Enter length and breadth: ";
cin>>s1>>s2;
a = calarea(s1, s2);
cout<<"Area = "<<a;
break;
case 4: cout<<"Exiting...press any key...";
getch();
exit(1);
default:cout<<"Wrong choice..!!";
} cout<<"\n";
}
while(choice>0 && choice<=4);
getch();
}
Output no.21:
Program no.22
Program for Constructors .
#include<iostream.h>
#include<conio.h>
class SUBJECT
{ int days;
int subjectno;
public:
SUBJECT(int d=123, int sn=101);
void printsubject(void)
{
cout<<"Subject No"<<subjectno<<"\n";
cout<<"Days: "<<days<<"\n";
} };
SUBJECT::SUBJECT(int d, int sn)
{
cout<<"Constructing SUBJECT\n";
days=d; subjectno=sn;
}
class STUDENT
{
int rollno;
float marks;
public: STUDENT()
{ cout<<"Constructing STUDENT\n";
rollno=0;
marks=0.0;
}
void getvalue(void)
{ cout<<"Enter roll number and marks: ";
cin>>rollno>>marks;
}
void print(void)
{
cout<<"Roll No: "<<rollno<<"\n";
cout<<"Marks: "<<marks<<"\n";
} };
class ADMISSION
{ SUBJECT sub;
STUDENT stud;
float fees;
public:
ADMISSION()
{
cout<<"Constructing ADMISSION\n";
fees=0.0;
}
void print(void)
{ stud.print();
sub.printsubject();
cout<<"Fees: "<<fees<<"\n";
} };
void main()
{ clrscr();
ADMISSION adm;
cout<<"\nBack to main()\n";
getch();
}
Output no.22:
Program no.23
Program for inheritance.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class EMPLOYEE
{ private:
char name[30];
unsigned long enumb;
public:
void getdata()
{
cout<<"Enter name: ";
gets(name);
cout<<"Enter Employee Number: ";
cin>>enumb;
}
void putdata()
{
cout<<"Name: "<<name<<"\t";
cout<<"Emp. No: "<<enumb<<"\t"; cout<<"Basic Salary: "<<basic;
}
protected:
float basic;
void getbasic()
{ cout<<"Enter Basic: ";
cin>>basic;
} };
class MANAGER:private EMPLOYEE
{
private:
char title[30];
public:
void getdata()
{
EMPLOYEE::getdata();
getbasic();
cout<<"Enter Title: ";
gets(title);
}
void putdata()
{
EMPLOYEE::putdata();
cout<<"\tTitle: "<<title<<"\n";
} };
void main()
{ clrscr();
MANAGER mng1, mng2; cout<<"Manager 1\n";
mng1.getdata();
cout<<"\nManager 2\n";
mng2.getdata();
cout<<"\n\t\tManager 1 Details\n";
mng1.putdata();
cout<<"\n\t\tManager 2 Details\n";
mng2.putdata();
getch();
}
Output no.23:
Program no.24
Program for data abstraction.
#include<iostream.h>
#include<conio.h>
class ADD{
public:
ADD(int i=0) {
tot=i; }
void addnumber(int num)
{ tot=tot+num; }
int gettotal() {
return tot; } private: // hidden from outside the world int tot;
};
void main()
{ clrscr();
ADD aob;
int a, b, c;
cout<<"Enter any three numbers: ";
cin>>a>>b>>c;
aob.addnumber(a);
aob.addnumber(b);
aob.addnumber(c);
cout<<"Total = "<<aob.gettotal();
getch(); }
Output no.24:
Progam no.25
Program for insertion in an array queue .
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int insert_in_queue(int [], int);
void display(int [], int, int);
const int SIZE = 50;
int queue[SIZE];
int front=-1;
int rear=-1;
void main()
{ clrscr();
int item, check;
char ch='y';
while(ch=='y' || ch=='Y')
{ cout<<"Enter item for insertion: ";
cin>>item;
check = insert_in_queue(queue, item);
if(check == -1)
{ cout<<"\nOverflow..!!..Aborting..!!..Press a key to exit..\n";
getch();
exit(1); }
cout<<"Item inserted successfully..!!\n";
cout<<"\nNow the Queue (Front...to...Rear) is:\n";
display(queue, front, rear);
cout<<"\nWant to insert more ? (y/n).. ";
cin>>ch; }
getch(); }
int insert_in_queue(int queue[], in elem)
{
if(rear == SIZE-1)
{
return -1; }
else if(rear == -1)
{
front = rear = 0;
queue[rear] = elem;}
else
{ rear++;
queue[rear] = elem; }
return 0;
}
void display(int queue[], int front, int rear) {
if(front == -1)
{
return; }
for(int i=front; i<rear; i++)
{
cout<<queue[i]<<" <- "; }
cout<<queue[rear]<<"\n"; }
Output no.25:
Program no.26
Program for random function .
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ clrscr();
int i;
for(i=0; i<100; i++)
{
cout<<rand()<<"\t";
}
getch();
}
Output no.26:
Program no.27
Program for transpose of matrix in array elements.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[3][3], i, j, arrt[3][3];
cout<<"Enter 3*3 Array Elements : ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>arr[i][j];
}}
cout<<"Transposing Array...\n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{ arrt[i][j]=arr[j][i];
}}
cout<<"Transpose of the Matrix is :\n";
for(i=0; i<3; i++)
{ for(j=0; j<3; j++)
{
cout<<arrt[i][j];
}
cout<<"\n";
}
getch();
}
Output no.27:
Program no.28
Program for binary search.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n, i, arr[50], search, first, last, middle; cout<<"Enter total number of
elements :";
cin>>n;
cout<<"Enter "<<n<<" number :";
for (i=0; i<n; i++)
{
cin>>arr[i];}
cout<<"Enter a number to find :";
cin>>search;
first = 0;
last = n-1;
middle = (first+last)/2;
while (first <= last)
{
if(arr[middle] < search)
{
first = middle + 1; }
else if(arr[middle] == search)
{
cout<<search<<" found at location "<<middle+1<<"\n";
break;
}
else
{
last = middle - 1; }
middle = (first + last)/2;
}
if(first > last)
{ cout<<"Not found! "<<search<<" is not present in the list.";
}
getch();
}
Output no.28:
Program no.29
Program for polymorphism.
#include<iostream.h>
#include<conio.h>
class JEXAMPLE{
protected:
int wid, hei;
public:
JEXAMPLE(int a=0, int b=0)
{ wid=a;
hei=b;
}
int area()
{ cout<<"Parent class area\n"; return 0;
} };
class RECTANGLE:public JEXAMPLE
{
public:
RECTANGLE(int a=0, int b=0):JEXAMPLE(a, b)
{}
int area()
{ cout<<"Rectangle class area\n";
return(wid*hei);
} };
class TRIANGLE:public JEXAMPLE {
public:
TRIANGLE(int a=0, int b=0):JEXAMPLE(a, b) { }
int area() { cout<<"Triangle class area\n";
return(wid*hei/2);
} };
void main()
{
clrscr();
JEXAMPLE *sh;
RECTANGLE rec(10, 7);
TRIANGLE tri(10, 5);
sh = &rec;
sh->area();
sh = &tri;
sh->area();
getch();
}
Output no.29:
Program no.30
Program to Store information into the file in
.#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{ ofstream fout;
char fname[20];
char rec[80];
clrscr();
cout<<"Enter file name: ";
cin>>fname;
fout.open(fname, ios::out);
cout<<"Enter a word: ";
cin>>rec;
fout<<rec;
cout<<"Data inserted successfully..!!"; fout.close();
getch();
}
Output no.30:
Program no.31
Program of Objects as Function Arguments
with constructor and desructor.
#include<iostream.h>
#include<conio.h>
class Sample {
int x;
public:
Sample(int i) // constructor
{ x = i;
cout<<"Constructing Object with "<<i<<"\n"; }
~Sample() // destructor
{ cout<<"Destroying Object having "<<x<<"\n"; }
void put_x(int i) { x = i; }
int get_x(void)
{ return x;
} };
void afunc(Sample S1)
{ S1.put_x(2) ; // change value of x in the object cout<<"This is x local to
afunc()\n";
cout<<"x = "<<S1.get_x()<<"\n";}
void main()
{ clrscr();
Sample S(1); // create object with value 1
cout<<"This is the x in main()\n"; cout<<"x = "<<S.get_x()<<"\n";
afunc(S);
cout<<"Back in main()\n";
cout<<"x = "<<S.get_x()<<"\n";
getch(); }
Output no.31:
Program no.32
Program demonstrates about invoking the functions
by * passing the references .
#include<iostream.h>
#include<conio.h>
void swap(int &, int &);
void main()
{ clrscr();
int a, b;
cout<<"Enter any two numbers: ";
cin>>a>>b;
cout<<"\nOriginal Values:\n";
cout<<"a = "<<a<<"\tand\tb = "<<b<<"\n";
swap(a, b);
cout<<"\nValues after swapping:\n";
cout<<"a = "<<a<<"\tand\tb = "<<b<<"\n";
getch(); }
void swap(int &x, int &y)
{ int temp;
temp = x;
x = y;
y = temp; }
Output no.32:
Program no.33
Program for Mathematical Functions.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
short int si = 100;
int i = -1000;
long int li = 1300;
float f = 230.47;
double d = 200.347;
cout<<"sqrt(si): "<<sqrt(si)<<endl; cout<<"pow(li, 3): "<<pow(li, 3)<<endl;
cout<<"sin(d): "<<sin(d)<<endl; cout<<"abs(i) : "<<abs(i)<<endl;
cout<<"floor(d): "<<floor(d)<<endl; cout<<"sqrt(f): "<<sqrt(f)<<endl;
cout<<"pow(d, 2): "<<pow(d, 2)<<endl; getch();
}
Output no.33:
Program no.34
Program of Passing Structure to Function - Call by
Value .
#include<iostream.h>
#include<conio.h>
struct distance
{ int feet; int inches;
};
void prnsum(distance l1, distance l2);
// function prototype
void main()
{ clrscr();
distance length1, length2;
cout<<"Enter length 1:\n";
cout<<"Feet: ";
cin>>length1.feet;
cout<<"\nInches: ";
cin>>length1.inches;
cout<<"\n\nEnter length 2:\n";
cout<<"Feet: ";
cin>>length2.feet;
cout<<"\nInches: ";
cin>>length2.inches;
prnsum(length1, length2);
getch();
}
void prnsum(distance l1, distance l2)
{ distance l3; // new structure
l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;
// 1 feet=12 inches l3.inches=(l1.inches+l2.inches)%12;
cout<<"\n\nTotal Feet: "<<l3.feet<<"\n";
cout<<"Total Inches: "<<l3.inches;
}
Output no.34:
Program no.35
Program Dynamic Memory Allocation Example .
#include<iostream.h>
#include<stdlib.h>
void main()
{ int size, i;
cout<<"How many elements for the array ? ";
cin>>size;
rollno = new int[size];
Marks = new float[size];
{ cout<<"Out of Memory..!!..Aborting..!!\n"; cout<<"Press any key to exit..";
getch();
exit(1);
for(i=0; i<size; i++)
{ cout<<"Enter rollno and marks for student "<<(i+1)<<"\n";
cin>>rollno[i]>>marks[i]; }
cout<<"\nRollNo\t\tMarks\n";
for(i=0; i<size; i++)
{ cout<<rollno[i]<<"\t\t"<<marks[i]<<"\n"; }
delete[]rollno;
getch();}
Output no.35:
Program no.36
Program to Generate Armstrong Numbers .
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int num1, num2, i, n, rem, temp, count=0;
cout<<"Enter Starting Number : ";
cin>>num1;
cout<<"Enter Ending Number : ";
cin>>num2;
for(i=num1+1; i<num2; i++)
{ temp=i; n=0; while(temp!=0)
{ rem=temp%10;
n = n + rem*rem*rem;
temp=temp/10;
}
if(i==n)
{ if(count==0)
{ cout<<"Armstrong numbers between the given interval are : \n";
}
cout<<i<<" ";
count++; } }
if(count==0)
{ cout<<"Armstrong number not found between the given interval";
}
getch();
}
Output no.36:
Program no.37
Program for auto Storage Class .
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
auto int counter;
int a;
auto int b;
cout<<"Enter any two number: ";
cin>>a>>b;
cout<<"\nPrinting these two number, 10 times:\n";
for(counter=0; counter<10; counter++) {
cout<<a<<"\t"<<b<<"\n";
}
getch();
}
Output no.37:
Program no.38
Program of C++ Stack * This C++ program
demonstrates the concept * of Popping from the
linked-stack in C++ .
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
node *next;
}
*top, *newptr, *save, *ptr;
node *create_new_node(int);
void push(node *);
void pop();
void display(node *);
void main()
{ clrscr();
int inf;
char ch='y';
top=NULL;
while(ch=='y' || ch=='Y')
{ cout<<"Enter information for the new node.. ";
cin>>inf;
newptr = create_new_node(inf); if(newptr == NULL)
{ cout<<"\nSorry..!!..Cannot create new node..!!..Aborting..!!\n";
cout<<"Press any key to exit..\n";
getch();
exit(1);
}
push(newptr);
cout<<"\nWant to enter more ? (y/n).. ";
cin>>ch;
}
clrscr();
do
{
cout<<"The Stack now is: \n";
display(top);
cout<<"\nWant to pop an element ? (y/n).. ";
cin>>ch;
if(ch=='y' || ch=='Y')
{ pop();
}
cout<<"\n";
}
while(ch=='y' || ch=='Y');
getch();
}
node *create_new_node(int x)
{ ptr = new node;
ptr->info = x;
ptr->next = NULL;
return ptr; }
void push(node *n)
agg{ if(top==NULL)
{ top=n;
}
else { save = top;
top = n;
n->next = save;
}}
void pop()
{ if(top==NULL)
{ cout<<"\nUnderflow..!!..Press any key to exit..\n";
getch();
exit(2);
}
else
{ ptr = top;
top = top->next;
delete ptr; } }
void display(node *n)
{
while(n != NULL)
{ cout<<n->info<<" -> ";
n = n->next;
}
cout<<"!!\n";
}
Output no.38:
Program no.39
Program to count string.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{ clrscr();
char str[80];
int len;
int countword=0, i;
cout<<"Enter about yourself in one line: ";
cin.getline(str, 80);
len=strlen(str);
for(i=0; i<len; i++)
{ if(str[i] == ' ')
{ countword++;
} } cout<<"\nAbout Us:\n\t"<<str<<endl;
cout<<"\nTotal Number of Words\n\t"<<countword+1<<" words";
getch();
}
Output no.39:
Program no.40
Program for calculating airthmetic progression.
include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int n, i, arr[50], sum=0;
cout<<"How many number you want to enter ?\n";
cin>>n;
cout<<"Enter "<<n<<" Numbers :";
for(i=0; i<n; i++)
{
cin>>arr[i];
sum=sum+arr[i];
} int armean=sum/n;
cout<<"Arithmetic Mean = "<<armean;
getch();
}
Output no.40: