Search This Blog

Labels

c codes (6) c++ codes (1)

Tuesday, March 08, 2016

WAP for multiple inheritance of example staff


 Write program to create a base class staff and derived class teacher,typist,officer and a sub derived class regular casual.

In this program we have familiar with the classes in the c++. In this we have used the inheritance in c++.Inheritance means we have create parent class 
and child class of the parent class.parent class have the some properties we have to define by default similarly, child class have some properties and child and parent class don't have same properties but child class have all   the properties of the parent class and have the additional has we define,In this we define parent class as employee and child class as manager in this sub-manager is the child class of manager. This program is very helpful for c++ devlopers. 


Program Code:-

#include<iostream>
using namespace std;
class staff
{
public:
       int c;
       int sal;
      char name[30];
      void get_data()
      {
          cout<<"Enter code name and salary of staff:-";
          cin>>c>>name>>sal;
      }
      void display_data()
      {
          cout<<"code:\t"<<c<<endl<<"name:\t"<<name<<endl<<"salary:\t"<<sal<<endl;
     }
};
class teacher : public staff
{
    public:
           char sub[10];
           char pub[10];
};
class typist : public staff
{
    public:
                 int s;
};
class officer : public staff
{
    public:
              char g;
};
class regular : public typist
{
    public:

};
class casual : public typist
{
    public:
                 int dailywage;
};

int main()
{
    staff s;
    teacher t;
    typist ty;
    officer o;
    regular  r;
    casual c;
    int n;
do{
    cout<<"choose any option given below\n1.teacher\t2.typist\t3.officer:-";
    cin>>n;
    if(n==1)
    {
    cout<<"Enter teacher subject and publication:-";
    cin>>t.sub>>t.pub;
    s.get_data();
    s.display_data();
    cout<<"subject:\t"<<t.sub<<endl<<"publication:\t"<<t.pub<<endl;
    }
    if(n==2)
    {
    cout<<"choose any option given below\n.regular\t2.casual:-";
    cin>>n;
    cout<<"Enter speed of typist:-";
    cin>>ty.s;
    if(n==1)
    {
    s.get_data();
    s.display_data();
    cout<<"speed:\t"<<ty.s<<endl;
    }
    if(n==2)
    {
    s.get_data();
    s.display_data();
    cout<<"speed:\t"<<ty.s<<endl;
    }
    }
    if(n==3)
    {
    cout<<"Enter grade of officer:-";
    cin>>o.g;
    s.get_data();
    s.display_data();
    cout<<"grade:\t"<<o.g<<endl;
    }
    cout<<"choose any one option\n1.continue\t2.exit:-";
    cin>>n;
}while(n==1);
    return 0;
}

Output:-

In this output we ask the user to enter any one of the option given below.The following options are teacher , typist, officer.In this teacher , typist, officer have all the properties of the base class staff.
The staff as following properties as like code,name,salary , but the teacher s additional properties subject and publication.similarly for remaining officer and typist.In the typist we have again two sub classes regular and casual.similarly its above statement is applied for this also.

Saturday, February 20, 2016

WAP to take three sides of a triangle as input and print if the triangle is equilateral ,isosceles , scalene.





program code:
#include<stdio.h>
int main()
 {
  int a,b,c;
  printf("Enter a sides of triangle :\n");
  scanf("%d%d%d",&a,&b,&c);
  if((a==b) && (b==c))
   {
    printf( "\nThe triangle formed by %d,%d,%d  sides is equilateral",a,b,c);
   }
  else if((a==b) || (b==c) || (a==c))
   {
     printf( "\nThe triangle formed by %d,%d,%d  sides is isosceles",a,b,c);
   }
 else
    {
      printf( "\nThe triangle formed by %d,%d,%d  sides is scalene",a,b,c);
     }
return 0;
}

Output:-
cse@ubumtu:~$gcc triangle.c - o triangle
cse@ubuntu:~$./triangle
Enter a sides of triangle :
2
4
6
The triangle formed by 2,4,6  sides is scalene.
 Enter a sides of triangle :
2
2
2
The triangle formed by 2,2,2  sides is equilateral
Enter a sides of triangle :
2
2
3
The triangle formed by 2,2,3  sides is isosceles.

Screen shot:-


Saturday, February 06, 2016

c program to print sum of the digits of the given number



c program to print sum of the digits of the given number

 In this program we have to given input a number and we have to find the sum of the digits of the given number and show the result in the output screen. This program is basically used for basic concept who are not known in the c programming.   

program code:-
#include<stdio.h>
int main()
 {
  int n,r,sum,m;
  printf("Enter a number :\n");
  scanf("%d",&n);
  m=n;
  sum=0;
  while(n>0)
    {
      r=n%10;
      sum=sum+r;
      n=n/10;
    }
printf("\n sum of digits of %d is %d ",m,sum);
return 0;
}

Output:-
cse@ubuntu:~$gcc sumdig.c - o sumdig
cse@ubuntu:~$./sumdig
Enter a number : 356

sum of digits of 356 is 14


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.  

C PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE



PROGRAM TO PRINT RADIUS AND VOLUME OF SPHERE

Program code:-

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
 {
   float radius,sa,vol;
   printf("\nEnter radius of sphere:\n");
   scanf("%f",&radius);
   sa=4*PI*pow(radius,2);
   vol=(sa*PI*radius)/3;
   printf("\nvolume of sphere of %f radius is %f ",radius,vol);
   printf("\nsurface of sphere of %f radius is %f",radius,sa);
return 0;
}

Output:-

tsp@ubuntu:~$gccsphere.c - o sphere
tsp@ubuntu:~$./sphere
Enter radius:
2
volume of sphere of 2.000000 radius is 25.120001

surface area of sphere of 2.000000 radius is 50.240002   



In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Tuesday, February 02, 2016

C PROGRAM TO CHECK MATRIX IS UPPER OR LOWER OR TRIDIAGONAL MATRIX

C PROGRAM TO CHECK MATRIX IS UPPER OR LOWER OR TRIDIAGONAL MATRIX

#include<stdio.h>
#define n 4
int main()
{
int a[n][n],i,j,cnt=0,f=0,g=0,k=0,l=0,m=0;
float z=0;
printf("enter the elements of the matrix:-\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
cnt=cnt+1;
}
}
printf("%d\n",cnt);
z=(cnt*100)/(n*n);
printf("%f\n",z);
if(z>=(n*n)/2)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i<j) && a[i][j]!=0)
f=1;
else if((i>j) && a[i][j]!=0)
g=1;
}
}
if(f==1 && g!=1)
printf("lower triangular sparse matrix");
else if(f!=1 && g==1)
printf("upper triangular sparse matrix");
else
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i==j) && a[i][j]!=0)
k=1;
if((i+1==j) && a[i][j]!=0)
l=1;
if((i==j+1) && a[i][j]!=0)
m=1;
}
}
if(k==1 && l==1 && m==1)
printf("tridiagnol sparse matrix");
}
}
else printf("not a sparse matrix");
return 0;
}

OUTPUT:-





In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Monday, February 01, 2016

C PROGRAM FOR BOTH INSERTION AND DELETION




C PROGRAM FOR BOTH INSERTION AND DELETION

#include<stdio.h>
#define n 10
int main()
{
int a[n],i,b;
printf("A Tarun Sankar\tRoll No. 14115007\n");
printf("Enter elements of array:\n");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
printf("\n\nWhat do you want to do??\n1.Insertion\t2.Deletion:-");
scanf("%d",&i);
if(i==1)
{
int v;
printf("Where do you want to insert the new element?\n");
printf("1.Start\t2.Any position\t3.End:-");
scanf("%d",&i);
printf("Enter the element which you want to insert:-");
scanf("%d",&v);
if(i==1)
{
for(i=0;i>n-1;i++)
a[i+1]=a[i];
a[0]=v;
}
else if(i==2)
{
printf("Enter which postion you want to insert:-");
scanf("%d",&b);
for(i=b;i>n-1; i++)
a[i+1]=a[i];
a[b-1]=v;
}
else if(i==3)
a[n-1]=v;
printf("The array after insertion is:-\n");
for(i=0;i<n; i++)
printf("%d\t",a[i]);
}
else if(i==2)
{
printf("Which element you want to delete?\n1.tart\t2.any position\t3.End:-");
scanf("%d",&i);
if(i==1)
for(i=0;i<n; i++)
a[i]=a[i+1];
else if(i==2)
{
printf("Enter which postion you want to delete:-");
scanf("%d",&b);
for(i=b-1;i<n; i++)
a[i]=a[i+1];
}
printf("The array after deletion is:-\n");
for(i=0; i<n-1; i++)
printf("%d\t",a[i]);
}
return 0;
}
Output:-


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.

Pages

Powered By Blogger