C++ Programme using class serial to store and display serial's title,duration, number of episodes, serial code



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class serial
{
               int code;
               char title[20];
               float duration;
               int noe;
               public:
               serial()
               {
                              duration=30;
                              noe=103;
               }
               void newserial();
               void otherentries(int dur,int no);
               void displaydata();
};


void serial::newserial()
{
               cout<<"\n\nEnter the serial code:";
               cin>>code;
               cout<<"Enter the title:";
               gets(title);
}


void serial::otherentries(int dur,int no)
{
               duration=dur;
               noe=no;
}


void serial::displaydata()
{
               cout<<"\tSerial code is:"<<code<<endl;
               cout<<"\tTitle is:"<<title<<endl;
               cout<<"\tDurations is:"<<duration<<endl;
               cout<<"\tNo. of episodes are:"<<noe<<endl<<endl;
}


int main()
{
               clrscr();
               char ch='y';
               int i=0,dur,no;
               serial s1[10];
               while(ch=='y')
               {
                              s1[i].newserial();
                              cout<<"Enter the duration and the no. of episodes:";
                              cin>>dur>>no;
                              s1[i].otherentries(dur,no);
                              i++;
                              cout<<"\n\nDo you want to continue:";
                              cin>>ch;
               }
               cout<<"\n\nThe details you have entered are:"<<endl<<endl;
               for(int j=0;j<i;j++){
                              cout<<"Data of serial "<<j+1<<" is:"<<endl;
                              s1[j].displaydata();
               }
               return 0;
}

OUTPUT:

Imagine a ticket selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced at Rs. 2.50. The booth keeps track of the number of people that have visited the fair and of the total amount of money collected. Model this ticket selling booth with a class tick. Include a program to rest this class



#include<iostream.h>
#include<conio.h>
#include<process.h>

class tick
{
               int nop;
               float total;
               public:
               tick()
               {
                              nop=0;
                              total=0;
               }
               void inc();
               void display();
               void displaynop();
};



void tick::inc()
{
               nop++;
               total+=2.50;
               cout<<"\nThe no. of people and the total have beem incremented";
}

void tick::display()
{
               cout<<"\nThe number of people who have entered the fair are:"<<nop<<endl;
               cout<<"The total amount collected till now is:"<<total<<endl;
}


void tick::displaynop()
{
               cout<<"The no. of people who have visited so far are:"<<nop<<endl;
}



int main()
{
               char ch='y';
               int choice;
               tick t1;

               l1:cout<<"\n\n\n\n1.Increment person and total"<<endl;
               cout<<"2.Display no. of people and the amount collected till now"<<endl;
               cout<<"3.Display no. of people who entered"<<endl;
               cout<<"4.Exit"<<endl;
               cout<<"Enter your choice:";
               cin>>choice;
               switch(choice)
               {
                              case 1:t1.inc();
                                             goto l1;
                                             break;
                              case 2:t1.display();
                                             goto l1;
                                             break;
                              case 3:t1.displaynop();
                                             goto l1;
                                             break;
                              case 4:exit(0);
                                     break;

               }
               return 0;
}

OUTPUT:

C++ programme using a class student to calculate the percentage of marks obtained by him



#include<iostream.h>
#include<conio.h>

class student
{
               int roll_no;
               char name[20];
               char class_st[8];
               int marks[5];
               float percentage;
               float calculate();
               public:
               void readmarks();
               void displaymarks();
};


float student::calculate()
{
               percentage=0;
               for(int i=0;i<5;i++)
                              percentage+=marks[i];
               percentage=(percentage/5);
               return percentage;
}


void student::readmarks()
{
               cout<<"Enter the roll no.:";
               cin>>roll_no;
               cout<<"Enter the name:";
               cin>>name;
               cout<<"Enter the class studing in:";
               cin>>class_st;
               cout<<"Enter the marks:"<<endl;
               for(int j=0;j<5;j++){
                              cout<<"\tEnter mark "<<j+1<<":";
                              cin>>marks[j];
               }
}


void student::displaymarks()
{
               cout<<"Roll no:"<<roll_no<<endl;
               cout<<"Name:"<<name<<endl;
               cout<<"Class:"<<class_st<<endl;
               cout<<"Percentage:"<<calculate()<<endl;
}


int main()
{
               student s1;
               s1.readmarks();
               s1.displaymarks();
               return 0;
}

OUTPUT: