C++ struct Returning Structures from a function

Description

C++ struct Returning Structures from a function

#include <iostream>
#include <iomanip>
using namespace std;
struct Employee      // declare a global data type
{
   int id;/*  w  w  w .j av a 2 s  .co  m*/
   double payRate;
   double hours;
};
Employee getVals();  // function prototype
int main()
{
   Employee emp;
   emp = getVals();
   cout << "ID:" << emp.id << "\npay rate:$" << emp.payRate << "\nhours:" << emp.hours << endl;
   return 0;
}
Employee getVals()  // return an Employee structure
{
   Employee next;
   next.id = 6789;
   next.payRate = 16.25;
   next.hours = 38.0;
   return next;
}



PreviousNext

Related