Urgent, need help on hw assignment...

C

corpuszero

i'm having problems with my hw assignment, i've been trying for so many days
and still haven't found a way to code according to the instructor's
checklist
----------------------------------------------------------------------------
----------------------------------------------

enum

Use the follow for this problem:

enum status{freshman, sophomore, junior, senior};

struct student

{

char name[20];

status year;

int major;

long ssn;

float gpa;

};



in your program create a structure variable of the above type and initialize
it at the time the variable is create. then change the status and gpa of the
structure variable by using the assignment operator. Make sure to display
the contents of all 5 data members before and after the changes are make.

checklist:

1. there is no input in this problem, only initialization and assignment
using the assignment operator.

2. initialization means placing value(s) into a variable at the time the
variable is create.

3. right after initialization display the contents of the entire variable.
that means the value for name, year, major, ssn, and gpa with proper labels.

4. then assign values to the year and gpa data members of the structure
variable.

5. right after the assignment display the contents of the entire variable
with proper labels.

6. use const char* const statusDesc[ ] = {"freshman", "sophomore", "junior",
"senior"} to translate the year from a number to a word.

7. to display the contents of the structure variable use a separate
function. As a result steps 3 and 5 are performed by calling the display
function.

----------------------------------------------------------------------------
----------------------------------------------

Here's what i have:

#include<iostream>
using namespace std;

enum status{freshman, sophomore, junior, senior};

struct student
{
char name[20];
status year;
int major;
long ssn;
float gpa;
};

int main()
{
student doan = {"Doan", sophomore, 13, 123456789, 3.5};
cout<<"Name: "<<doan.name<<endl
<<"Year: "<<doan.year<<endl
<<"Major: "<<doan.major<<endl
<<"SSN#: "<<doan.ssn<<endl
<<"GPA: "<<doan.gpa<<endl<<endl;

const char *const statusDesc[]={"freshman", "sophomore", "junior",
"senior"};

cout<<"Name: "<<doan.name<<endl
<<"Year: "<<doan.year<<endl
<<"Major: "<<doan.major<<endl
<<"SSN#: "<<doan.ssn<<endl
<<"GPA: "<<doan.gpa<<endl<<endl;

return 0;
}
 
M

Mike Wahler

corpuszero said:
i'm having problems with my hw assignment, i've been trying for so many days
and still haven't found a way to code according to the instructor's
checklist

You're not all that far off, you simply did only part of it
and didn't organize the code as instructed.

What have you tried for parts not shown here, and what problems
did you encounter with it?
Use the follow for this problem:

enum status{freshman, sophomore, junior, senior};

struct student

{

char name[20];

Aside:
I think if you're being taught to use arrays of
characters for strings instead of the std::string
type, you're being taught poorly. But whatever...
More below.
status year;

int major;

long ssn;

float gpa;

};



in your program create a structure variable of the above type and initialize
it at the time the variable is create.
then change the status and gpa of the
structure variable by using the assignment operator. Make sure to display
the contents of all 5 data members before and after the changes are make.

checklist:

1. there is no input in this problem, only initialization and assignment
using the assignment operator.

2. initialization means placing value(s) into a variable at the time the
variable is create.

3. right after initialization display the contents of the entire variable.
that means the value for name, year, major, ssn, and gpa with proper labels.

4. then assign values to the year and gpa data members of the structure
variable.

5. right after the assignment display the contents of the entire variable
with proper labels.

6. use const char* const statusDesc[ ] = {"freshman", "sophomore", "junior",
"senior"} to translate the year from a number to a word.

7. to display the contents of the structure variable use a separate
function. As a result steps 3 and 5 are performed by calling the display
function.

------------------------------------------------------------------------

This is a better specification for an assignment
than many I've seen from instructors. :)
Here's what i have:

#include<iostream>
using namespace std;

enum status{freshman, sophomore, junior, senior};

struct student
{
char name[20];
status year;
int major;
long ssn;
float gpa;
};

int main()
{
student doan = {"Doan", sophomore, 13, 123456789, 3.5};

OK so far.
cout<<"Name: "<<doan.name<<endl
<<"Year: "<<doan.year<<endl

Note: You were not asked to output the value of 'year',
but the 'translation' of it to text (using the 'statusDesc[]' array)
(item 6 in instructions). But this is OK for a first iteration.

When you do use the 'translation' the definition of 'statusDesc'
below needs to happen before this point, so the 'translation'
has the array available to it (it does not exist yet at this
point).


<<"Major: "<<doan.major<<endl
<<"SSN#: "<<doan.ssn<<endl
<<"GPA: "<<doan.gpa<<endl<<endl;

Also you were told to do this output in a separate function.
(item 7 in instructions). I suspect this is in order for
you to show you can pass a parameter to a function.
(this also prevents the need to write it twice like you've
done here -- the more code, the more chance for errors).
Again, this is OK for a first iteration. BUt don't
forget to go back and meet specification.
const char *const statusDesc[]={"freshman", "sophomore", "junior",
"senior"};

Here's where you need to change the values of 'status'
and 'gpa'.
cout<<"Name: "<<doan.name<<endl
<<"Year: "<<doan.year<<endl
<<"Major: "<<doan.major<<endl
<<"SSN#: "<<doan.ssn<<endl
<<"GPA: "<<doan.gpa<<endl<<endl;

Again, this should be done in a separate function (use
the same one for here and above. Also, you still need
to do the 'translation'.

I suspect you might get extra points if you also have
a separate function perform this 'translation' (would
show understanding of not only parameter passing, but
also returning a value from a function. (But you never
know, I'd check with instructor before doing it --
doing the translation in a separate function, that is.)
return 0;
}

To summarize:

1. You did not follow the instructions for the parts you did do.

2. Some parts were completely omitted. We won't add them for you.
Try them, then if stuck, post what you've tried, and we'll
point out the problems and offer more hints and suggestions.

3. Advice: Don't try to do it all at once. One Step At A Time.
Don't add subsequent steps until what you have works properly.

E.g. Write code to create and initialize your struct, display
it (ok to do it all in main() at first), then STOP. Compile it.
If errors, fix them (ask for help here if stuck with that).
If it does compile, then run it. If the output is not what
you expect, try to figure out why and fix it. If you can't
figure out why, post the code here and ask for help. If the
output is correct, proceed to the next step. Here, the next
step would be to move the output code into its own function,
as per instructions. Use the same 'code/compile/debug/test'
cycle. Then move to the next step. Then when something goes
wrong, you know *exactly* where to look -- the last portion
of code you added. This is the way the professionals do it,
and so should you.

4: Hints:

enum {/* etc */};

struct student
{
/* etc */
};

/* return type */ display( /* parameters */ )
{
const char *const statusDesc[]= { /* etc */ };
/* translation of 'year' from numeric to text */
/* output statements */
}

int main()
{
struct student doan = { /* etc */ };
/* call a function here */
/* assign new values to struct members here */
/* call a function here */
return 0;
}


Hope I didn't do too much of the work for you. :)

Give it a shot, and post back if still stuck. Good luck!

HTH,
-Mike
 
C

corpuszero

Hey tkx, i was unable to correctly finish the assignment yesterday and turn
it in, but surely i will try to correctly do it to learn it for the exam on
monday.
 
G

glen stark

....
Hope I didn't do too much of the work for you. :)

Give it a shot, and post back if still stuck. Good luck!

HTH,
-Mike
Hey Mike. Way to go. That was a really nice advice. You took a lot of
time to give helpful advice. I'm impressed.
 
M

Mike Wahler

glen stark said:
...
Hey Mike. Way to go. That was a really nice advice. You took a lot of
time to give helpful advice. I'm impressed.

Thanks. A single recognition from someone like you
more than makes up for the dozens who name me an
'anal pr*ck', when I suggest they confront reality.

I spend time here for a few reasons:

1.
I feel that far too many CS curricula are producing graduates
who are misinformed, or graduating them without really determining
if they actually learned. Perhaps one day I must work with them,
and spending time correcting and teaching them on the job is
impractical.

2.
I don't like to see students or their sponsors paying
good money and not getting what they paid for. (However,
the clarity and completeness of the instructions the OP
posted makes be believe his instructor/course is one of
the imo few exceptions to 1. above.)

3.
I have the 'selfish' motive that I simply enjoy helping.

4.
Like anyone, I'm not perfect, and when I post something here,
my own errors and/or misunderstandings will be quickly
identified and explained, which benefits me and anyone
else I might help in the future.

5.
While perusing messages here, when I see a question I cannot
answer, I read the replies of those more knowledgable than I,
so I get to learn as well.

6.
I truly enjoy programming, and like to talk about it.


Thanks again.

To "corpus zero": I did see your thank you note and
appreciate it.

-Mike
 
W

WW

Mike said:
Like anyone, I'm not perfect
~~~~~~~~~~~

Don't rush to conclusions. ;-)

Just joking. I think you have very very nicely summarized what are decent
motives to post here. IMO I am driven by the same, although I am sometimes
(some too many times) are switched to hellfire mode by some mentally
challenged trolls...

The interesting is that intelligence (I mean what we might percieve as one)
seems to have nothing to do with the ability to communicate. On the way
that some people who does not seem to be complete morons as undertsanding of
quite complex topics go can show up the level of a hysteric 4 years old when
it comes to communication.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top