Sunday 21 December 2014

Progrm-12

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Student
{
     private:
     int admin_no;
     char name[30];
     int cla;
     int roll_no;
     public:
     Student()
     {
 admin_no=0;
 cla=1;
 strcpy(name,"XYZ");
 roll_no=1;
     }
     void getdata()
     {
 cout<<"Enter name:";
 gets(name);
 cout<<"Enter admission number:";
 cin>>admin_no;
 cout<<"Enter class:";
 cin>>cla;
 cout<<"Enter roll number:";
 cin>>roll_no;
     }
     void showdata()
     {
 cout<<endl<<"Name:"<<puts(name);
 cout<<endl<<"Admission number:"<<admin_no;
 cout<<endl<<"Class:"<<cla;
 cout<<endl<<"Roll Number:"<<roll_no;
     }
};
void main()
{
     clrscr();
     Student S[10];
     int i=0;
     for(i=0;i<10;i++)
     {
cout<<"Enter data of Student No."<<i+1<<"->>>>>";
cout<<endl;
S[i].getdata();
     }
     for(i=0;i<10;i++)
     {
cout<<endl<<"Information of Student No."<<i+1<<"->>>>";
cout<<endl;
S[i].showdata();
     }
     getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int i=0;
float avg=0;
class Student
{
      private:
      char name[30];
      int roll_no;
      int marks[5];
      char stream[40];
      public:
      Student()
      {
 strcpy(name,"XYZ");
 roll_no=0;
 for(i=0;i<5;i++)
 {
    marks[i]=0;
 }
 strcpy(stream,"ABCD");
      }
      void getdata();
      void putdata();
      void ass_stream();
};
void Student::getdata()
{
      cout<<"Enter name:";
      gets(name);
      cout<<endl<<"Enter roll number:";
      cin>>roll_no;
      cout<<endl<<"Enter marks of five subject:";
      for(i=0;i<5;i++)
      {
 cin>>marks[i];
      }
}
void Student::putdata()
{
      cout<<endl<<"Name:"<<name;
      cout<<endl<<"Roll number:"<<roll_no;
      cout<<endl<<"Marks secured in five subject:";
      for(i=0;i<5;i++)
      {
 cout<<marks[i]<<'\t';
      }
      cout<<endl<<"Stream:"<<puts(stream);
}
void Student::ass_stream()
{
      int sum=0;
      for(i=0;i<5;i++)
      {
 sum=sum+marks[i];
      }
      avg=(sum/5)*100;
      if(avg>=96)
      strcpy(stream,"Computer Science");
      else if(avg>=91 && avg<96)
      strcpy(stream,"Electronics");
      else if(avg>=86 && avg<91)
      strcpy(stream,"Mechanical");
      else if(avg>=81 && avg<86)
      strcpy(stream,"Electrical");
      else if(avg>=75 && avg<81)
      strcpy(stream,"Chemical");
      else if(avg>=71 && avg<75)
      strcpy(stream,"Civil");
      else
      strcpy(stream,"Not available!Too low marks.");
}
void main()
{
      clrscr();
      Student S[20];
      for(i=0;i<20;i++)
      {
 S[i].getdata();
      }
      cout<<endl<<"Assigning stream:";
      for(i=0;i<20;i++)
      {
 S[i].ass_stream();
      }
      cout<<endl<<"List of students:";
      for(i=0;i<20;i++)
      {
 S[i].putdata();
      }
      getch();
}
Q.WAP to check whether given string is palindrone
or not.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,j,k,l=0;
    cout<<"Enter a number";
    cin>>i;
    j=i;
    do
    {
k=i%10;
l=k+l*10;
i=i/10;
    }while(i>0);
    cout<<endl<<"Reversed no. is"<<l;
    if(j==l)
    cout<<endl<<"Palindrone";
    else
    cout<<endl<<"Not a Palindrone";
    getch();
}

Q.WAp to input elements in a 2-D array and then display the sum
of main diagonal elements.

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int r,c,i=0,j=0,sum=0;
  int*ptr;
  cout<<"Enter row and column of a matrix";
  cin>>r>>c;
  ptr=new int[r*c];
  cout<<endl<<"Enter elements of the matrix";
  for(i=0;i<r;i++)
  {
  for(j=0;j<c;j++)
  {
  cin>>ptr[i*c+j];
  }
  }
  cout<<endl<<"Matrix form";
  cout<<endl;
  for(i=0;i<r;i++)
  {
  for(j=0;j<c;j++)
  cout<<ptr[i*c+j]<<'\t';
  cout<<endl;
  }
  for(i=0;i<r;i++)
  {
  for(j=0;j<c;j++)
  {
     if(i==j && i+j==r-1)
     sum=sum+ptr[i*c+j];
  }
  }
  sum-ptr[r/2*c/2+c/2];
  cout<<endl<<"The Sum of diagonal elements of a matrix:"<<sum;
  getch();
}
Q.WAP to input elements in a 2-D array and then display this
array in matrix form.

#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int ar[3][3],i,j,sumi=0,sumj=0;
     cout<<"Enter numbers:";
     for(i=0;i<3;i++)
     {
for(j=0;j<3;j++)
cin>>ar[i][j];
     }
     cout<<"Matrix form:";
     for(i=0;i<3;i++)
     {
for(j=0;j<3;j++)
cout<<ar[i][j]<<"\t";
cout<<endl;
     }
getch();
}

Q.WAP to input 10 elements in an array and then display these
elements in reverse order.

#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int arr[10];
     int i=0;
     for(i=0;i<10;i++)
     {
cout<<"Enter element no."<<i+1<<"=";
cin>>arr[i];
cout<<endl;
     }
     cout<<"Given array is:";
     for(i=0;i<10;i++)
     {
cout<<arr[i]<<" ";
     }
     cout<<endl<<"Array in reversed order:";
     for(i=9;i>=0;i--)
     {
cout<<arr[i]<<" ";
     }
     getch();
}
Q.WAP to input 10 elements in an array and then display
these elements.

#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int arr[10];
     int i=0;
     for(i=0;i<10;i++)
     {
cout<<"Enter element no."<<i+1<<"=";
cin>>arr[i];
cout<<endl;
     }
     cout<<"Given array is:";
     for(i=0;i<10;i++)
     {
cout<<arr[i]<<" ";
     }
     getch();
}

Q.WAP to read a string and print it after replacing each
of its capital alphabets by the corresponding small alphabet
and each small alphabet by its corresponding capital alphabet.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
clrscr();
char ch[30];
cout<<"Input a string:";
gets(ch);
cout<<"Original string is:";
puts(ch);
for(int i=0;ch[i]!='\0';i++)
{
  if(isupper(ch[i]))
  {
    ch[i]=tolower(ch[i]);
  }
  if(islower(ch[i]))
  {
    ch[i]=toupper(ch[i]);
  }

}
cout<<"Altered string is:";
puts(ch);
getch();
}
Q.WAP to read a syring and print out the following:
1]No. of capital alphabets.
2]No. of small alphabets.
3]No. of non-alphabets.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
clrscr();
char ch[30];
int m=0,n=0,o=0;
cout<<"Input a string:";
gets(ch);
for(int i=0;ch[i]!='\0';i++)
{
  if(isupper(ch[i]))
  m++;
  if(islower(ch[i]))
  n++;
  if(isdigit(ch[i]))
  o++;
}
cout<<endl<<"Number of capital alphabets:"<<m;
cout<<endl<<"Number of small alphabets:"<<n;
cout<<endl<<"Number of digits:"<<o;
getch();
}
Q.Write a menu driven program to calculate the TSA and volume of a
cube,cuboid and cylinder depending upon user's choice.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char ch[20];
float vol,area;
cout<<"Enter the desired shape:(D....)";
cin>>ch;
if(strcmp(ch,"Cube")==0)
{
  int l;
  cout<<"Enter length of the cube:";
  cin>>l;
  vol=l*l*l;
  cout<<"The volume is:"<<vol;
  area=6*l*l;
  cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cuboid")==0)
{
  int l,b,h;
  cout<<"Enter length,breadth and height of the cube:";
  cin>>l>>b>>h;
  vol=l*b*h;
  cout<<"The volume is:"<<vol;
  area=2*(l*b+b*h+h*l);
  cout<<"The surface area is:"<<area;
}
else if(strcmp(ch,"Cylinder")==0)
{
  int r,d;
  cout<<"Enter height and radius of the cylinder:";
  cin>>d>>r;
  vol=3.14*r*r*d;
  cout<<"The volume is:"<<vol;
  area=2*3.14*r*r+3.14*r*r*d;
  cout<<"The surface area is:"<<area;
}
else
{
  cout<<"Invalid choice";
}
getch();
}
Q>WAP to input day number of a week and display the corresponding
day name.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"Enter day number of the week (1-7):";
cin>>num;
switch(num)
{
     case 1:
     {
     cout<<"Monday";
     break;
     }
     case 2:
     {
     cout<<"Tuesday";
     break;
     }
     case 3:
     {
     cout<<"Wednesday";
     break;
     }
     case 4:
     {
     cout<<"Thursday";
     break;
     }
     case 5:
     {
     cout<<"Friday";
     break;
     }
     case 6:
     {
     cout<<"Saturday";
     break;
     }
     case 7:
     {
     cout<<"Sunday";
     break;
     }
     default:
     cout<<"Invalid choice";
}
getch();
}
Q.WAP to input two numbers m and n and display first m
multiples of n.

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int m,n;
 cout<<"Enter two numbers:";
 cin>>m>>n;
 for(int i=0;i<=m;i++)
 {
      cout<<n<<"*"<<i<<"="<<n*i;
      cout<<endl;
 }
 getch();
}

Triangle program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=5;i>=1;i--)
{
for(j=5-i;j>=0;j--)
cout<<" ";
for(k=1;k<=i;k++)
cout<<"* ";
cout<<endl;
}
getch();
}

Mathematics Table

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a,b;
cout<<"Enter a number:";
cin>>a;
for(i=1;i<=10;i++)
{
b=a*i;
cout<<endl<<a<<"*"<<i<<"="<<b;
}
cout<<endl<<"Your Required Table";
getch();
}

Prime number

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a;
cout<<"Enter any number:";
cin>>a;
for(i=2;i<a/2;i++)
if(a%i==0)
{
cout<<"Not a Prime number";
}
cout<<"Prime number";
getch();
}

Pattern (name)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
int i=0,j=0;
char str[20];
char *ptr;
strcpy(str,"KABEER");
ptr=str;
for(i=6;i>0;i--)
{
for(j=0;j<i;j++)
cout<<*(ptr+j)<<'\t';
cout<<endl;
}
getch();
}

Palindrome

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char *ptr;
int i=0,j=0,k=0,len=0;
char str1[20];
cout<<"Enter a string:";
gets(str1);
cout<<endl<<"Original string is:";
puts(str1);
ptr=str1;
for(i=0;*(ptr+i)!='\0';i++)
{
      len++;
}
for(i=0,j=len-1;i<=len/2;i++,j--)
{
     if( *(ptr+i)==*(ptr+j) )
     k=1;
}
if(k==1)
cout<<endl<<"Palindrone";
else
cout<<endl<<"Not a Palindrone";
getch();
}

Greatest number of three input numbers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter three number";
cin>>a>>b>>c;
if(a>b && a>c)
{
cout<<endl<<a;
}
else if(b>c && b>a)
{
cout<<endl<<b;
}
else
{
cout<<endl<<c;
}
getch();
}

Factorial

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a;
cout<<"Enter any number:";
cin>>a;
i=a-1;
while(i>0)
{
a=a*i;
i--;
}
cout<<a;
getch();
}

Diamond Pattern

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,l,m,n;
for(i=1;i<=5;i++)
{
for(j=5-i;j>=1;j--)
cout<<" ";
for(k=1;k<=i;k++)
cout<<"# ";
cout<<endl;
}
for(l=4;l>=1;l--)
{
for(m=5-l;m>=1;m--)
cout<<" ";
for(n=1;n<=l;n++)
cout<<"# ";
cout<<endl;
}
getch();
}

Calculator

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,g;
cout<<"Enter two number:";
cin>>a>>b;
cout<<"Enter your choice:";
cin>>c;
switch(c)
{
case 1:
d=a+b;
cout<<d;
break;
case 2:
e=a-b;
cout<<e;
break;
case 3:
f=a*b;
cout<<f;
break;
case 4:
g=a/b;
cout<<g;
break;
default:
cout<<"Invalid Operator";
}
getch();
}

Pattern

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
char k='A';
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
cout<<char(k);
cout<<endl;
k++;
}
getch();
}

Friday 19 December 2014

Q.Create a class student with data members name,class,section,roll no. and function
members getdata(),printdata(),and promoted().From this class derive a class 'Sr_std'
with additional data member stream.Also include another function member change_stream().

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
char ch[5];
class Student
{
    private:
    char name[30];
    int cla;
    char section[2];
    int roll_no;
    public:
    Student()
    {
     strcpy(name,"ABCD");
     cla=1;
     strcpy(section,"A");
     roll_no=1;
    }
    void getdata()
    {
     cout<<"Enter name:";
     gets(name);
     cout<<endl<<"Enter class:";
     cin>>cla;
     cout<<"Enter section:";
     cin>>section;
     cout<<"Enter roll number:";
     cin>>roll_no;
    }
    void print()
    {
     cout<<endl<<"Name:";
     puts(name);
     cout<<endl<<"Class:";
     cout<<cla;
     cout<<endl<<"Section:";
     cout<<section;
     cout<<endl<<"Roll number:";
     cout<<roll_no;
    }
    protected:
    void promote()
    {
     cout<<"Congratulation!!! Promoted to:"<<cla+1;
     cla=cla+1;
    }
};
class Sr_std:public Student
{
    private:
    char stream[5];
    public:
    Sr_std()
    {
     strcpy(stream,"PCM");
    }
    void getdata()
    {
     Student::getdata();
     cout<<"Enter stream:";
     gets(stream);
    }
    void print()
    {
     Student::print();
     cout<<endl<<"Stream:"<<stream;
    }
    void change_stream()
    {
     cout<<"Enter desired stream:";
     gets(ch);
     strcpy(stream,ch);
    }
    void promote()
    {
     Student::promote();
    }
};
void main()
{
    clrscr();
    char str;
    Sr_std A;
    A.getdata();

    cout<<endl<<"Want to change stream:(Y/N)";
    cin>>ch;
    if(strcmp(ch,"Y")==0)
    {
    A.change_stream();
    A.print();
    }
    else
    A.print();
    int marks;
    cout<<endl<<"Enter % marks obtained:";
    cin>>marks;
    if(marks>40)
    A.promote();
    else
    cout<<"Fail!!!!";
    getch();
}
 Q.WAP using the above class to define an array of 10 points and input
the data in the array.Then for each point tell if it lies on any axis
(x-axis or y-axis).

#include<iostream.h>
#include<conio.h>
#include<math.h>
int i;
class Point
{
     private:
     int x,y;
     public:
     Point()
     {
    x=0;
    y=0;
     }
     void getinfo()
     {
    cout<<"Enter co-ordinates of the point:";
    cin>>x>>y;
     }
     void print()
     {
    cout<<"("<<x<<","<<y<<")";
     }
     int return_X()
     {
    return x;
     }
     int return_Y()
     {
    return y;
     }
};
void main()
{
     clrscr();
     Point P[10];
     for(i=0;i<10;i++)
     {
      P[i].getinfo();
     }
     for(i=0;i<10;i++)
     {
    if(P[i].return_Y()==0)
    {
       cout<<endl<<"Point:";
       P[i].print();
       cout<<endl<<"Lie on x-axis.";
    }
    if(P[i].return_X()==0)
    {
       cout<<endl<<"Point:";
       P[i].print();
       cout<<endl<<"Lie on y-axis.";
    }
    if(P[i].return_X()==0 && P[i].return_Y()==0)
    {
       cout<<endl<<"Origin";
    }
     }
     getch();
}
Q.Define a point class for 2-D points(x,y).Include a default constructor , a copy constructor ,
a negate() function to transform the point into its negative , a norm() function to return the
point's distance from the point's distance from the origin(0,0),and a print() function besides
the functions to input and display the co-ordinates of the point.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class Point
{
     private:
     int x,y;
     public:
     Point()
     {
    x=0;
    y=0;
     }
     Point(Point&Q)
     {
    x=Q.x;
    y=Q.y;
     }
     void negate()
     {
    x=-1*x;
    y=-1*y;
     }
     float norm()
     {
    float num;
    num=sqrt(x*x+y*y);
    return num;
     }
     void getinfo()
     {
    cout<<"Enter co-ordinates of the point:";
    cin>>x>>y;
     }
     void print()
     {
    cout<<"("<<x<<","<<y<<")";
     }
};
void main()
{
     clrscr();
     Point P;
     P.getinfo();
     Point(P);
     cout<<endl<<"Co-ordinate of the point:";
     P.print();
     float t=P.norm();
     cout<<endl<<"Distance from the origin:"<<t;
     P.negate();
     cout<<endl<<"The negative of the co-ordinates:";
     P.print();
     getch();
}