SY_BCA_CPP_SLIP 1_1



/Slip no : 1 Write a C++ program to create a class Worker with data members as Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member functions to calculate and display the salary of worker. (Use default value for Pay_Rate)           */

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class worker
{
                char name[10];
                int hr;
                public:
                void accept()
                {             
                                cout<<"enter name";
                                cin>>name;
                                cout<<"enter hours";
                                cin>>hr;
                }

                void calculate(int rate=50)
                {
                                cout<<"salary of worker is Rs."<<(hr*30)*rate;
                }
};

void main()
{
                worker ob;
                clrscr();
                ob.accept();
                ob.calculate();
                getch();
}

5 comments:

  1. what is the output of this program

    ReplyDelete
  2. In cpp main function always return 0 or 1 to the operating system hence it always holds int return datatype.
    Correct me if I am wrong.

    ReplyDelete
    Replies
    1. You used int main then return value is compulsory otherwise no...

      Delete