Visitors

Friday, August 8, 2008

C Programming Section B

C++ Programming Section B

C++ Programming


C++ Programming


//vowels.cpp
#include"iostream.h"
#include"conio.h"
#include"string.h"
int vo=0,cc=0;
class vowel
{
private:
char str[' '];

public:
void display();
void getdata()
{
int n;
cout<<"Enter the string for find the num of vowels and costraint\n";
cin.getline(str,80);
//cin>>str;
}

void findvowel()
{

strupr(str);
for(int i=0;str[i]!='\0';i++)
{
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
{
vo++;
}
else
if(str[i]!=' ')
{
cc++;
}
}
display();
}
};

void vowel::display()
{
cout<<"Num of vowels are "<<vo<<"\n";
cout<<"Num of costraint are "<<cc<<"\n";
}
void main()
{
clrscr();
vowel v;
v.getdata();
v.findvowel();
getch();
}


//zerosmaller.cpp
//Create a function to find the smallest of two numbers
# include<iostream.h>
# include <conio.h>
void main()
{
int a,b,c,d;
void zero_smaller(int &,int &);
clrscr();
cout<<"\nEnter any two numbers\n";
cin>>a>>b;
c=a;
d=b;
zero_smaller(a,b);
if(a==0)
cout<<"\n"<<c<<" is the smallest number";
else
if(b==0)
cout<<"\n"<<d<<" is the smallest number";
else
cout<<"\nBoth the numbers are same";
getch();
}
void zero_smaller(int &x,int &y)
{
if(x<y)
x=0;
else
if(y<x)
y=0;
}





//array.cpp
#include"iostream.h"
#include"conio.h"
#include"stdio.h"

class student
{
private:
char name[80];
int age;
float mark;

public:
void read()
{
cout<<"\n\nEnter name : ";
gets(name);
cout<<"\n\nEnter age and mark : ";
cin>>age>>mark;
}

void display()
{
cout<<"\n"<<"Name is "<<name;
cout<<"\n"<<"Age is "<<age;
cout<<endl<<"Mark is "<<mark;
}


};


void main()
{
student s[' '];
int n,i;
clrscr();
cout<<"Enter the num of object : ";
cin>>n;
for(i=0;i<n;i++)
s[i].read();
clrscr();
for(i=0;i<n;i++)
{
cout<<"\n\n\n\nstudent "<
<i+1<<" details : \n\n";
s[i].display();
}
getch();
}


//thispointer.cpp
#include <iostream.h>
#include <conio.h>

class student
{
private:
char na[10];
int age;
public:
void get_data()
{
cout<<"\nEnter Student Name := "; cin>>na;
cout<<"Enter Student Age := "; cin>>age;
}
void put_data()
{
cout<<na<<" age is = "<<age;
}
student grater(student);
};
student student::grater(student s)
{
if(age>=s.age)
return *this;
else
return s;
}
void main()
{
// clrscr();
student s1,s2;
cout<<"\nDemonstrate this Pointer.\n";
s1.get_data();
s2.get_data();

student s = s1.grater(s2);
cout<<"\n\nEldest Student ";
s.put_data();

getch();
}


//pointersort.cpp
#include <iostream.h>
#include <conio.h>
#include <string.h>
class sort
{
char na[10];
public:
void read()
{
cin>>na;
}
void write()
{
cout<<na;
}
char* ret()
{
return na;
}
};
void main()
{
// clrscr();
sort s[10];
sort *ps[10],*temp;
char ch;
int n=0;

cout<<"Pointer Sort.\n";
cout<<"\nEnter Names :\n";
do
{
s[n].read();
ps[n]=&s[n];
cout<<"Do you want continue [y/n] :- ";
cin>>ch;
n++;
}while(ch=='y');

for(int i=0;i<n;i++)
for(int j=1;j<n-i;j++)
if(strcmpi(ps[j-1]->ret(),ps[j]->ret())>0)
{
temp = ps[j-1];
ps[j-1] = ps[j];
ps[j] = temp;
}

cout<<"\nSorted Names are :\n";
for(i=0;i<n;i++)
{
ps[i]->write();
cout<<'\n';
}
getch();
}


//staticFunction.cpp
#include <iostream.h>
#include <conio.h>

class Number
{
private:
static int count;
int no;
public:
void Assign_no()
{
no = ++count;
}
void Display_no()
{
cout<<"\n\nObject Number = "<<no;
}
static void Display_count();
/* {
cout<<"\nNo of Objects Created = "<<count;
} */
};

void Number::Display_count()
{
cout<<"\nNo of Objects Created = "<<count;
}

int Number::count;

void main()
{
// clrscr();
cout<<"\t\tDemonstration of Static Function\n";
Number obj1;
obj1.Assign_no();
Number::Display_count();

Number obj2,obj3;
obj2.Assign_no();
obj3.Assign_no();
Number::Display_count();

obj1.Display_no();
obj2.Display_no();
obj3.Display_no();

getch();
}