Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,126 people online right now. Registration is fast and FREE... Join Now!




function for class_avg

3 Pages V  1 2 3 >  
Reply to this topicStart new topic

function for class_avg

hlabrams
29 Aug, 2006 - 06:40 AM
Post #1

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
What did I do wrong with this function?

CODE
void Sort_Table(STUDENT_STRUCT student_table[], int num_students);
     cout << endl << endl;
     cout << "The table sorted alphabetically by last name is:";

void Display_Student_Table(STUDENT_STRUCT student_table[], int num_students);
    cout << endl << endl;
    cout << setw(14) << left << "Last Name"
         << setw(14) << left << "First Name"
         << setw(14) << left << "Final Exam"
         << setw(14) << left << "Quiz Average"
         << setw(14) << left << "Final Grade" << endl;
        
    for(row=0; row<num_students; ++row);

}

}


This post has been edited by Dark_Nexus: 29 Aug, 2006 - 06:42 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Function For Class_avg
29 Aug, 2006 - 06:45 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Well that depends on what you want it to do. What you have posted here is not actually a function. There is a call to two functions, but niether has been defined. Also, the for loop provided executes no code except it's own incrementing. Additionally, the return type identifier is not required for a function call. Can I assume that actually wish to have this code represent the definition of the Sort_Table function, and in that function, you wish to call the Dsiplay_Table function?
User is offlineProfile CardPM
+Quote Post

hlabrams
RE: Function For Class_avg
29 Aug, 2006 - 06:51 AM
Post #3

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
QUOTE(Amadeus @ 29 Aug, 2006 - 07:45 AM) *

Well that depends on what you want it to do. What you have posted here is not actually a function. There is a call to two functions, but niether has been defined. Also, the for loop provided executes no code except it's own incrementing. Additionally, the return type identifier is not required for a function call. Can I assume that actually wish to have this code represent the definition of the Sort_Table function, and in that function, you wish to call the Dsiplay_Table function?


All I know is that after I enter my "made-up" students and all their data, I have to be able to display the table in alphabetical order using last names.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Function For Class_avg
29 Aug, 2006 - 07:17 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Well, we can certainly help with that...but is this code meant to be the fucntion itself, or have you already written the sort function?
User is offlineProfile CardPM
+Quote Post

hlabrams
RE: Function For Class_avg
29 Aug, 2006 - 07:36 AM
Post #5

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
QUOTE(Amadeus @ 29 Aug, 2006 - 08:17 AM) *

Well, we can certainly help with that...but is this code meant to be the fucntion itself, or have you already written the sort function?



It doesn't have to be a function, but I wrote it that way....or tried to write it that way. Here it is with the other functions:

CODE
};

int Load_Student_Table(STUDENT_STRUCT[], int);
void Display_Student_Table(STUDENT_STRUCT[], int);
double Calc_Quiz_Avg(STUDENT_STRUCT[], int);
int Calc_Final_Grade(STUDENT_STRUCT s[], int num_students);
int Calc_Class_Avg(int, int);
void Sort_Table(STUDENT_STRUCT[], int);
  
    const int TABLE_SIZE = 25;
    
int main()
{


This post has been edited by Dark_Nexus: 29 Aug, 2006 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Function For Class_avg
29 Aug, 2006 - 07:48 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Functions themselves should be structured as follows:
CODE

//prototype - above the main function
void SortTable(param1,param2);

//function definition - below the main function
void SortTable(param1,param2)
{
   //your code here
}

As for the actual sorting, you would like to do so by last name, is that correct? And the last name is held in a character array, is that correct?

Final question, as I know this is for an assignment and depth of understanding will dictate how the solution is presented. Have you, during your course, been given lessons on any sorting methodology or algorithms?
User is offlineProfile CardPM
+Quote Post

hlabrams
RE: Function For Class_avg
29 Aug, 2006 - 10:24 AM
Post #7

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
QUOTE(Amadeus @ 29 Aug, 2006 - 08:48 AM) *

Functions themselves should be structured as follows:
CODE

//prototype - above the main function
void SortTable(param1,param2);

//function definition - below the main function
void SortTable(param1,param2)
{
   //your code here
}

As for the actual sorting, you would like to do so by last name, is that correct? And the last name is held in a character array, is that correct?

Final question, as I know this is for an assignment and depth of understanding will dictate how the solution is presented. Have you, during your course, been given lessons on any sorting methodology or algorithms?


Yes, I want to sort by last name and yes, it is a char array. My course is all done online, so I don't receive any direct "lessons". My professor sucks and is no help at all. I've seen a bubble sort in my textbook, but that's all.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Function For Class_avg
29 Aug, 2006 - 10:38 AM
Post #8

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
Well to sort alphabetically, you need to compare the ASCII values of the first letters and have them follow each other from least to highest.

If you don't want to change your display_table (which I think would be the best solution) you'd have to permute the tables so that Abc is in row 1 and Bca in row 2.
User is offlineProfile CardPM
+Quote Post

hlabrams
RE: Function For Class_avg
29 Aug, 2006 - 10:47 AM
Post #9

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
QUOTE(DeeViLiSh @ 29 Aug, 2006 - 11:38 AM) *

Well to sort alphabetically, you need to compare the ASCII values of the first letters and have them follow each other from least to highest.

If you don't want to change your display_table (which I think would be the best solution) you'd have to permute the tables so that Abc is in row 1 and Bca in row 2.


That sounds confusing and I don't know how to do that. If you're able to walk me through it, I'd be happy to try it. How did you learn so much at such a young age? That's amazing!
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Function For Class_avg
29 Aug, 2006 - 11:06 AM
Post #10

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Sorting can sound very confusing at first to learn, but once you understand the concept it is actually quite simple in most cases.

Not to say that there aren't some sort methods that really make you sweat.

Anyhow, I think you will love the following link. It is the coolest thing I've come across concerning sorting demonstrations on the web for C++.

When the page loads you will see a drop down of different sorting algorithms. Pick the one you would like to see and a java applet will load giving you an example of the code for that type of sort.

After you enter an array of integers you watch a graphical demonstration of the sort in action showing each line of code as it executes. Check it out, this will walk you through it step by step.

http://www.cs.pitt.edu/~kirk/cs1501/animations/Sort1.html
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Function For Class_avg
29 Aug, 2006 - 11:19 AM
Post #11

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
QUOTE(jayman9 @ 29 Aug, 2006 - 12:06 PM) *

Check it out, this will walk you through it step by step.

http://www.cs.pitt.edu/~kirk/cs1501/animations/Sort1.html


Omg, that is exactly what I'm trying to achieve xD
Wasn't finished my function but it almost looks the same as the bubble sort thingy ^^

QUOTE
How did you learn so much at such a young age? That's amazing!


Lol only 15 and I rock xD
I read through half of Stroustrup's 1000 page book, I keep answering you guys' question, I love me computer ^^.

I amaze myself too doing this selftaught at 15. Maybe at 20 I can bez winnar like Videege combine chaos mathematics and fractals to create a random image and maybe creating an algorithm of my own instead of the Mandelbrot one.
How hot would that be? ^^

EDIT : =0 I feel 3 times happier finding out I was helping a 36 year old man happy.gif

This post has been edited by DeeViLiSh: 29 Aug, 2006 - 11:22 AM
User is offlineProfile CardPM
+Quote Post

hlabrams
RE: Function For Class_avg
29 Aug, 2006 - 11:31 AM
Post #12

D.I.C Head
**

Joined: 17 Aug, 2006
Posts: 66


My Contributions
QUOTE(DeeViLiSh @ 29 Aug, 2006 - 12:19 PM) *

QUOTE(jayman9 @ 29 Aug, 2006 - 12:06 PM) *

Check it out, this will walk you through it step by step.

http://www.cs.pitt.edu/~kirk/cs1501/animations/Sort1.html


Omg, that is exactly what I'm trying to achieve xD
Wasn't finished my function but it almost looks the same as the bubble sort thingy ^^

QUOTE
How did you learn so much at such a young age? That's amazing!


Lol only 15 and I rock xD
I read through half of Stroustrup's 1000 page book, I keep answering you guys' question, I love me computer ^^.

I amaze myself too doing this selftaught at 15. Maybe at 20 I can bez winnar like Videege combine chaos mathematics and fractals to create a random image and maybe creating an algorithm of my own instead of the Mandelbrot one.
How hot would that be? ^^

EDIT : =0 I feel 3 times happier finding out I was helping a 36 year old man happy.gif


You should be amazed. You've been a huge help to me. I'm a 35 year old mom of 5 and this programming stuff is killing me!


Uuuuugh!!! That site didn't help because I need to sort alphabetically.....last names. All I could find were sorts that involved integers. What kind of a sort is an alphabetical one anyway??
User is offlineProfile CardPM
+Quote Post

3 Pages V  1 2 3 >
Reply to this topicStart new topic
Time is now: 12/5/08 02:48AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month