Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Structure definitions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
crystal twix  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 00:06
Newsgroups: comp.lang.c++
From: crystal twix <jonwongfanc...@gmail.com>
Date: Sat, 7 Nov 2009 16:06:38 -0800 (PST)
Local: Sun 8 Nov 2009 00:06
Subject: Structure definitions
As part of a homework problem, I'm trying to declare a new struct
within the definition, but my new definition is an array, and I am
only to define some of the values.  For example:

#define STUDENTS 100

struct Test {
  int score;
  int grade;

} score[STUDENTS], ???

but I want to only initialize the first 5.  Thanks!

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Saeed Amrollahi  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 05:58
Newsgroups: comp.lang.c++
From: Saeed Amrollahi <amrollahi.sa...@gmail.com>
Date: Sat, 7 Nov 2009 21:58:47 -0800 (PST)
Local: Sun 8 Nov 2009 05:58
Subject: Re: Structure definitions
On Nov 8, 3:06 am, crystal twix <jonwongfanc...@gmail.com> wrote:

> As part of a homework problem, I'm trying to declare a new struct
> within the definition, but my new definition is an array, and I am
> only to define some of the values.  For example:

> #define STUDENTS 100

> struct Test {
>   int score;
>   int grade;

> } score[STUDENTS], ???

> but I want to only initialize the first 5.  Thanks!

Hi
Because it is a homework, I should give you just few hints:
1. Use const types rather than macros:
const int STUDENTS = 100;
2. The name of your array and one of its struct members are same:
score. use different names.
3. You can intialize the first 5 array elements using array
initilizers list
almost in the same way as initializing array of integers:
int a[100] = { 0, 1, 2, 3, 4 };

Good luck
  -- Saeed Amrollahi


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorgen Grahn  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 22:29
Newsgroups: comp.lang.c++
From: Jorgen Grahn <grahn+n...@snipabacken.se>
Date: 8 Nov 2009 22:29:32 GMT
Local: Sun 8 Nov 2009 22:29
Subject: Re: Structure definitions

On Sun, 2009-11-08, crystal twix wrote:
> As part of a homework problem, I'm trying to declare a new struct
> within the definition, but my new definition is an array, and I am
> only to define some of the values.  For example:

> #define STUDENTS 100

> struct Test {
>   int score;
>   int grade;
> } score[STUDENTS], ???

> but I want to only initialize the first 5.  Thanks!

I assume your homework is a C++ assignment since you are posting here.
Use std::vector<Test> instead of a C-style array, and make Test a
class with a constructor.

(And if your teacher is not aware of the standard containers,
quit the class and buy a good C++ book instead.)

/Jorgen

--
  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/     snipabacken.se>   O  o   .


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google