C++ Array of Objects

Description

C++ Array of Objects

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

class Employee/*from  w w  w .j  a  v a  2  s .co m*/
{
  public:
    int  workHour;
    double salary;
    double addWork(int hours, double grade){
        return 0.0;
    }
};

void myFunction()
{
    Employee s[10];

    s[4].salary = 4.0;
    s[4].workHour = 32;

    s[4].addWork(3, 0.0);
}

int main(int nNumberofArgs, char* pszArgs[])
{
    myFunction();
    cout<< "done."
    return 0;
}
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;

class NameLinkedList{
  public:/*from  w  w  w.  jav a2 s  .c o m*/
    char firstName[128];
    char lastName[128];
    int  creditCard;
};

int main(int nNumberofArgs, char* pszArgs[])
{
    const int MAX = 25;
    NameLinkedList nds[MAX];

    cout << "Read name/credit card information\n" << "Enter 'exit' to quit" << endl;
    int index = 0;
    for(;index < MAX; index++){
        cout << "\nEnter first name:";
        cin  >> nds[index].firstName;

        if (strcmp(nds[index].firstName, "exit") == 0){
            break;
        }

        cout << "Enter last name:";
        cin  >> nds[index].lastName;

        cout << "Enter credit card number:";
        cin  >>nds[index].creditCard;
    }

    cout << "\nEntries:" << endl;

    for (int i = 0; i < index; i++){
        cout << nds[i].firstName  << " "
             << nds[i].lastName   << "/"
             << nds[i].creditCard << endl;
    }
    return 0;
}



PreviousNext

Related