| faieq92 (150) | |
|
#include <iostream> #include <string> #include <math.h> #include <fstream> using namespace std; int main() { int i; string information[10][7]; //input cout << "\nWhich Slot would you like to store the informaton in ?(1-10)"; cin >> i; i--; for (int j=0;j<7;j++) { switch(j+1) {case 1: cout << "\nFirst Name: "; break; case 2: cout << "\nLast Name: "; break; case 3: cout << "\nAge: "; break; case 4: cout << "\nEmail: "; break; case 5: cout << "\nDoor Number: "; break; case 6: cout << "\nRoad Name: "; break; case 7: cout << "\nPost Code: "; break; default:;} cin >> information[i][j];} // output for (int j=0;j<7;j++) { switch(j+1) {case 1: cout << "\nFirst Name: "; break; case 2: cout << "\nLast Name: "; break; case 3: cout << "\nAge: "; break; case 4: cout << "\nEmail: "; break; case 5: cout << "\nDoor Number: "; break; case 6: cout << "\nRoad Name: "; break; case 7: cout << "\nPost Code: "; break; default:;} cout << information[i][j];} system("PAUSE"); return 0; } THIS is what I have done so far but apparently I should be creating this by using classes but I have no idea where to start. I know how to use classes and struct. But I have to create this program that allows me to enter user data and | |
|
|
|
| LowestOne (895) | |||
Your class is basically going to take the place of the second dimension of your array. Also, you will no longer have a string array, but a class array:
| |||
|
Last edited on
|
|||
| faieq92 (150) | |
|
whats the difference between the string array and the class array? and the 2nd dimension is the [7] right? | |
|
|
|
| faieq92 (150) | |
| where can I find an example of this? | |
|
|
|
| soranz (478) | |||||||
http://www.cplusplus.com/doc/tutorial/classes/
The simplest explanation I can think of is to think of a class as a datatype (like int, float, bool). You can create arrays of datatypes, store values into them, manipulate them etc. Classes are a special way for you to define exactly HOW you want to store/manipulate/retrieve your data. 'class array' might be a bit confusing because it is not actually an array of classes but rather an array of objects instantiated from a particular class (like an array of objects from the string class). For readability you might want to change this:
to
yes, note that element [0][0] is unused | |||||||
|
|
|||||||