slip 25

/* Slip no : 25_1 Create a class Clock that contains integer data members as hours, minutes and seconds. Write a C++ program to perform following member functions:
   void setclock(int, int, int ) to set the initial time of clock object.
   void showclock() to display the time in hh:min:sec format.
   Write a function tick( ) which by default increment the value of second by 1 or according to user specified second. The clock uses 24 hours format.         */

#include<iostream.h>
#include<conio.h>
class Clock
{
                int h,m,s,sec;
                public :
                void setclock(int hr,int min,int sec)
                {
                                h=hr;
                                m=min;
                                s=sec;
                }
                void showclock()
                {
                                cout<<"\n"<<h<<":"<<m<<":"<<s;
                }
                void tick()
                {
                                cout<<"\n Enter sec to be incremented : ";
                                cin>>sec;
                                s=s+sec;
                                if(s>=60)
                                {              m=m+s/60;
                                                s=s%60;
                                                if(m>=60)
                                                {
                                                                h=h+m/60;
                                                                m=m%60;
                                                }

                                }
                }
};

void main()
{
                Clock c;
                int hr,min,sec;
                cout<<"\n Enter hr : ";
                cin>>hr;
                cout<<"\n Enter min : ";
                cin>>min;
                cout<<"\n Enter sec : ";
                cin>>sec;
                c.setclock(hr,min,sec);
                c.showclock();
                c.tick();
                c.showclock();
                getch();

}











/* Slip no : 25_2 Create a class Person that contains data members as Person_Name, City, Mob_No. Write a C++ program to perform following functions:
To accept and display Person information
To search the mobile number of a given person
To search the Person details of a given mobile number
(Use Function Overloading)        */

#include<conio.h>
#include<iostream.h>
#include<string.h>
class person
 {
     char name[10],city[10],mno[12];
     public:
     void accept()
     {
                cout<<"\n Enter name : ";
                cin>>name;
                cout<<"\n Enter city : ";
                cin>>city;
                cout<<"\n Enter mob no : ";
                cin>>mno;
     }

     void display()
     {
                cout<<"\n Name of person = "<<name;
                cout<<"\n city = "<<city<<"\n mobile no = "<<mno;
                cout<<"\n=======================================";
     }

     int display(char a[])
     {
                if(strcmp(name,a)==0)
                 { cout<<"mno="<<mno;
                   return 1;
                 }
                   return 0;
     }


     int display(char mbno[],int no)
     {
                if(strcmp(mno,mbno)==0)
                 {
                                display();
                   return 1;
                 }
                   return 0;
                }

};

void main()
 {
    int n,i,cnt=0,ans;
    char sname[20],mbno[12];
    person ob[20];
    clrscr();
    cout<<"\n Enter no of persons : ";
    cin>>n;
    for(i=0;i<n;i++)
     {
                ob[i].accept();
     }

    for(i=0;i<n;i++)
     {
                ob[i].display();
     }

    cout<<"\n Enter name of person to be search : ";
    cin>>sname;
    for(i=0;i<n;i++)
     {
                ans=ob[i].display(sname);
                if(ans==1)
                cnt++;
     }
      if(cnt==0)
      cout<<"\n person not found\n ";

   cout<<"\n Enter mobile no to be search : ";
    cin>>mbno;
                cnt=0,ans=0;
    for(i=0;i<n;i++)
     {
                 ans=ob[i].display(mbno,1);
                 if(ans==1)
                 cnt++;
     }
       if(cnt==0)
       cout<<"\n person not found\n";


   getch();
}
slip 25 slip 25 Reviewed by Dinesh Varal on January 31, 2018 Rating: 5

No comments:

Powered by Blogger.