Pages

Write a program in C++ to get employee name and its salary and print employee name, salary and grand salary(total salary+10% of salary) [Updated]

Monday, 22 April 2013


#include <iostream.h>
class employee
{
     char firstName[50];
     char lastName[50];
     int salary;
     public:
            employee()
            {
                strcpy(firstName, "NULL");
                strcpy(lastName, "NULL");
                salary=0;    
            }
            void setfn()
            {
                 cout<<"Enter First Name of Emplyee: ";
                 cin>>firstName;
            }
            void setln()
            {
                 char ln;
                 cout<<"Enter Last Name of Emplyee: ";
                 cin>>lastName;
            }
            void sets()
            {
                 int s;
                 cout<<"Enter salary of "<<firstName<<" "<<lastName<<": ";
                 cin>>s;
                 if(s<0){s=0;}
                 salary=s;
            }
            void dfn()
            {
                 cout<<"First Name is: "<<firstName<<endl;
            }
            void dln()
            {
                 cout<<"Last Name is: "<<lastName<<endl;
            }
            void dsalary()
            {
                 cout<<"Salary of "<<firstName<<" "<<lastName<<" of one year is: "<<salary*12<<endl;
                 cout<<"Salary with 10% of "<<firstName<<" "<<lastName<<" is: "<<((salary*10)/100)+salary<<endl;
            }
};
int main()
{
    char a;
    employee e1;
    again:
    e1.setfn();
    e1.setln();
    e1.sets();
    e1.dfn();
    e1.dln();
    e1.dsalary();
    cout<<"Would you like to put data of new employee: ";
    cin>>a;
    if(a=='y' || a=='Y'){goto again;}
}

Write a program to in C++ to get student name and age and print it on screen using OOP technique.


#include<iostream>
using namespace std;
class student{
char name;
int age;
public:
void setname(char newname,int newage)
{
name=newname;
age=newage;
}
void display()
{
    cout<<"your name is "<<name<<"\nYour age is "<<age<<endl;
}
};
int main()
{
student data;
data.setname('ammar',12);
data.display();
system("pause");
}

Write a program to print bill in C++ using oop


#include <iostream.h>
class bill
{
    char name[50];
    int unit, p_unit, c_unit;
    float price_unit, tbill, tax;
    public:
           bill()
           {
                price_unit=3.80;
           }
    void setname()
    {
       cout<<"Enter customar name: ";
       gets(name);
    }
    void setunits()
    {
        again:
        cout<<"Enter previous units: ";
        cin>>p_unit;
        cout<<"Enter current units: ";
        cin>>c_unit;
        if(c_unit<p_unit)
        {
             cout<<"Enter Valid data(Units)."<<endl;
             goto again;          
        }
        unit=c_unit-p_unit;
    }
    void make_bill()
    {
         float temp;
        if(unit<=100)
        {
                  temp=price_unit*unit;
                  tax=(temp*8)/100;
                  tbill=temp+35+tax;
        }
        else if(unit>100 && unit<=200)
        {
             temp=unit*(price_unit+3);
             tax=(temp*12)/100;
             tbill=temp+35+tax;
        }
        else
        {
            temp=unit*(price_unit+6);
             tax=(temp*14)/100;
             tbill=temp+35+tax;
        }
    }
    void display_bill()
    {
         int counter=0, i;
         for(i=1; i<=4; i++)
         {
                  cout<<"***********************************"<<endl;
                  counter++;
                  if(counter==2)
                  {
                                cout<<"Name: "<<name<<endl;
                                cout<<"Your total units are: "<<unit<<endl;
                                cout<<"You total bill is: R.s "<<tbill<<endl;
                  }
         }
    }
    void detail()
    {
         if(unit<=100){price_unit=3.80;}
         else if(unit>100 && unit<=200){price_unit=6.80;}
         else{price_unit=9.80;}
         cout<<"Total Units consumed: "<<unit<<endl;
         cout<<"PTV fee: R.s 35"<<endl;
         cout<<"Price Per unit at "<<unit<<" units is"<<price_unit<<endl;
         cout<<"Tax: "<<tax<<endl;
       
    }
};
main()
{
      char a, d;
      bill c;
      next:
      c.setname();
      c.setunits();
      c.make_bill();
      c.display_bill();
   
      cout<<"Press \"D\" or\"d\" to get detail of you bill"<<endl;
         cin>>d;
         if(d=='D' ||d=='d')
         {
                   c.detail();
         }
      cout<<"You want to calculate bill of next customar? Y/N ";
      cin>>a;
      if(a=='y' ||a=='Y')
      {
                cout<<"***********************************"<<endl;
                goto next;
      }
}

Write a program to get first n prime numbers

#include <stdio.h>

#include <conio.h>
int main()
{
       int a, b, counter=0, limit=0, num;
       printf("Enter number: ");
       scanf("%d", &num);
       for(a=1; a<=100000; a++)
       {
                counter=0;
                for(b=2; b<a; b++)
                {
                         if ((a%b)==0)
                         {
                            counter++;
                         }  
                }
                if(counter==0)
                {
                              printf("%d \n", a);
                              limit++;          
                }
             if(limit==num)
             {
                       break;      
             }    
       }
       getch();
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *