Sunday, 9 July 2017

HW Program 1

#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();
}

Program for a "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();
}

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...