GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Mar-2004, 17:43
madlynzz madlynzz is offline
Awaiting Email Confirmation
 
Join Date: Mar 2004
Location: New York
Posts: 1
madlynzz is on a distinguished road

Creating 2d array


I'm new to C++ and I want learn how to create a 2d array to store numbers and names. Let's say I have an art class of 5 students, I want to create an array to store their names and ages. Then I want to create a function to return only their names. I'm having a hard time figuring out where to start. Here's what I have so far. Am I down the right path?

CPP / C++ / C Code:
class art
{
private:
	int studentage;
	string studentname;
	string artclass[];

public:
art (int studentage, string studentname) // constructor
{
	studentage=studentage;
	studentname=studentname;
}

art (art &s1) // copy constructor
{
	s1.studentage=studentage;
	s1.studentname=studentname;
}

void getartclass(s1,s2,s3, s4,s5) //returns 
{
}


};
Last edited by JdS : 21-Mar-2004 at 07:15. Reason: please use the [c]your c code[/c] syntax highlighter
  #2  
Old 20-Mar-2004, 20:15
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
Hi, i think it would be easier for you if u made a student class which only stores name and age, and then make an array of student objects, which are in the art classroom. and then you can maybe have a function which returns array[studentnum].age or array[studentnum].name. remember a function can only return 1 variable or an object,and it can't return arrays. a void function like the one you have can't return anything. so you can put in the ampersand & in front of your parameters that you are passing to it so that any changes you make to the function parameters are actually made to the parameters that were passed to your function when it was called. By the way, it would be a good idea to get a c++ book and then after each chapter do a few problems.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Speed up C++ code about 3d array! Truong Son C++ Forum 0 16-Mar-2004 21:52
throwing an struct(with an array) through a function knakworstje C Programming Language 5 15-Feb-2004 16:20
c: array comparison jack C Programming Language 7 26-Jan-2004 11:21
Sorting a 2D array c++ mike3340 C++ Forum 4 15-Dec-2003 13:35
Extra null element in an array samtediou MySQL / PHP Forum 2 11-Dec-2003 11:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:33.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.