Love Programming

Welcome to the world of learning

Love Programming

Welcome to the world of learning

Love Programming

Welcome to the world of learning

Love Programming

Welcome to the world of learning

Love Programming

Welcome to the world of learning

Thursday, 20 July 2017

Class Student(Using all types of constuctors)

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class student
 { private:
   int id;
   char name[30];
   int marks[5];
   int avg;
   public:
   student();
   student(student &si);
   void readstudent();
   void calcavg();
   void display();
 };

void student::student()         //Default Constructor (Outline)
 { id=0;
   strcpy(name,"AAA");
   for(int i=0;i<5;i++)
      { marks[i]=0;
      }
   avg=0;
 }

void student::student(student &si) // Copy constructor (outlined)
 { id=si.id;
   strcpy(name,si.name);
   for(int i=0;i<5;i++)
      { marks[i]=si.marks[i];
      }
   avg=si.avg;
 }

void student::readstudent()
 { cout<<"Enter Student ID ";
   cin>>id;
   cout<<"Enter Student name ";
   gets(name);
   cout<<"Enter students' marks in 5 subjects ";
   for(int i=0;i<5;i++)
      { cin>>marks[i];
      }
 }

void student::calcavg()
 { for(int i=0;i<5;i++)
      { avg+=marks[i];
      }
   avg=avg/5;
 }

void student::display()
     { cout<<"Name :";
       puts(name);
       cout<<"Id : \t "<<id;
       cout<<"\n Average marks = "<<avg;
     }
void main()
{ clrscr();
  student s1,s2;
  s1.readstudent();
  s1.calcavg();
  student(s2)=s1;
  s1.display();
  s2.display();
  getch();
}

Movie Counter

#include<iostream.h>
#include<conio.h>
class movcount
{ private:
   int tp;
   int tpass;
   long tamount;
   int tticket;
  public:
   void counter();
   void showdetail();

};
void movcount::counter()
{ char x;
  int count=0,pass=0;
  long amount=0;
  cout<<"Enter 't' ( with ticket ) \n 'p' ( with pass ) \n Or any other key to Calculate ";
  start:
  cin>>x;
  if (x=='t'||x=='p')
     { if (x=='t')
   { amount=amount+250;
     count++;
   }
       else if (x=='p')
   { count++;
     pass++;
   }
       goto start;
     }
  else
     { tamount=amount;
       tp=count;
       tpass=pass;
       tticket=count-pass;
     }
}
void movcount::showdetail()
{ cout<<"Total number of people visited = "<<tp<<"\n";
  cout<<"Total amount collected = "<<tamount<<"\n";
  cout<<"Total number of people with pass = "<<tpass<<"\n";
  cout<<"Total number of people with tickets ="<<tticket;
}
void main()
{ clrscr();
  movcount m1;
  m1.counter();
  m1.showdetail();
  getch();
}