C++ examples for Class:object
Store associated data in an array of objects
#include <cstdio> #include <cstdlib> #include <iostream> #include <string.h> using namespace std; class NameLinkedList{ public:// ww w . j a v a 2 s .com 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; }