how should sort them acsendig order by their total marks
and how shuld user to promt to number student in tthe class
struct student
{
char name[20];
int math;
int science;
int history;
int english;
int total;
}
I got a struture in c++ as follows how can i get the students marks limited it betwwen 0and100 marks and?
Well, a struct is just how a chunk of memory is to be used. In your program you will need to allocate some memory with this structure. Since this looks like a class assignment on structures then I would say you can use an array of students to get started.
Now since these are marked integers they are not limited to 0 and 100 so you are going to have to wrap that functionality in a function call. Create a function called add student that does the following (pseudo code):
//apologies for the quick and dirty response here
function int AddStudent (byref StudentArray, byref LastStudent, Name, math, science, history, english) {
if math %26lt; 0 or math %26gt; 100 then return -1
if science %26lt; 0 or math %26gt; 100 then return -1
if history %26lt; 0 or math %26gt; 100 then return -1
if english %26lt; 0 or math %26gt; 100 then return -1
//if you get this far then you know the values are within limits and it is ok to add the student to the array.
LastStudent ++
//now using your array assign your values to the array location, remember to sum or average the other scores to get your total
}
byref = pass by reference
StudentArray is an array of your student records
When using arrays be sure to check to make sure you don't go outside the limit. For example, don't add student 101 if you only alloc'd 100 array elements.
If you are in a C++ class then you will want to build a class/object of Students but that is a different solution all together.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment