Hello guys. I'm not very good at at programing but i need to do one program which should do this:
Write a program with objects which stores student marks of exam. All the information is read. It must be realized:
a. I enter all students marks;
b. and see whose marks and subject screen ;
c. count evry student average mark

But where is a problem in this program. when i put all marks and subjects for 2 maybe more students the marks are being showed in screen only from last student. so all students have the same marks like the last one.
and counting average mark also it dont work :(. Sorry for my english i'm from lithuania.

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

class student
{
public:
    int subjectmark,sk,i,sum,mark[100];
    int average[100];
    int amount;
    char name[100];
    char surname[100];
    char subject[100];
    void read();
    void to_screen();
    void averagek(); 
                       
};
void student::read ()
{
{

    cout << "Please enter students number:" << endl;
    cin >> sk;
    
    cout << "Please enter students subjects number:" << endl;
    cin >> amount;

   if (sk <= 0)
      {
      cout << "Bad number. program closes." << endl;
      cin >> sk;
       system("PAUSE");
      {exit (1);};
      }

    cout << endl;
    cout << "Enter names,surnames ect." << endl << endl;
      
    for (int i=0; i<sk; i++)
    {
    cout<<"Enter student name and surname:"<<endl;
    cin>>name;
    cin>>surname;
    for (int j=0; j<amount; j++)
    {
    cout<<"Enter subject name "<<endl;
    cin>>subject;
    cout<<"Enter subject mark "<<endl;
    cin>>mark[100];
}}}}
void student::to_screen ()
{

    cout << "-----------------------------------------------------------------------" << endl;
    cout << "Name \t\t | surname\t | subject\t\t| Mark.|" << endl;
    cout << "-----------------------------------------------------------------------" << endl;

    for(int i=0; i<sk; i++)
{
    for (int j=0; j<amount; j++)
    {
    cout << name << "\t\t | " << surname << "\t | " << subject << "\t\t | " << mark[100] << " \t| " << endl;
    cout << "------------------------------------------------------------------------" << endl;
    cout << endl;

    cout << "Average mark for student : " << average[100] << endl << endl;
}}}
void student::averagek()
{
    sum=0; 
    average[100]=0;
     for (int j=0; j<amount; j++)     
    sum+=mark[100];
    average[100] = sum/amount;
}
int main()
{
    student z;
     z.read();
     z.to_screen();
     z.averagek();
    system("PAUSE");
    return 0;
}

Edited 6 Years Ago by TheCur3: n/a

I will appreciate any help. so i added that code tag. is it ok now?

Comments
Better, make sure you use them in the future.

You seem to have the correct idea for your student class definition and individual member function algorithms. The issue is you only have 1 student object. Try creating a vector<student>. Once you can do that, expand main() to complete the requirements of the assignment.

Edited 6 Years Ago by Fbody: n/a

:( i not very good in understanding vector<student> because i did everything what i learned in university but where was no such a thing vector. but i tried it on google to find out this and after that i have done sth like this

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

class student
{
public:
    int subjectmark,sk,i,sum;
    int average[100];
    int amount;
    char name[100];
    char surname[100];
    char subject[100];
    void read();
    void to_screen();
    void averagek(); 
                       
};
  vector<double> mark;
void student::read ()
{
{ 

    cout << "Please enter students number:" << endl;
    cin >> sk;
    
    cout << "Please enter students subjects number:" << endl;
    cin >> amount;

   if (sk <= 0)
      {
      cout << "Bad number. program closes." << endl;
      cin >> sk;
       system("PAUSE");
      {exit (1);};
      }

    cout << endl;
    cout << "Enter names,surnames ect." << endl << endl;
for ( i=0; i<sk; ++i) 
{
    cout<<"Enter student name and surname:"<<endl;
    cin>>name;
    cin>>surname;
    for (int j=0; j<amount; j++)
    {
    cout<<"Enter subject name "<<endl;
    cin>>subject;
    cout<<"Enter subject mark "<<endl;
    cin>>mark[j];
}}}}
void student::to_screen ()
{

    cout << "-----------------------------------------------------------------------" << endl;
    cout << "Name \t\t | surname\t | subject\t\t| Mark.|" << endl;
    cout << "-----------------------------------------------------------------------" << endl;

    for(int i=0; i<sk; i++)
{
    {
              for (int j=0; j<amount; j++)
    {
    cout << name << "\t\t | " << surname << "\t | " << subject << "\t\t | " << mark[j] << " \t| " << endl;
    cout << "------------------------------------------------------------------------" << endl;
    cout << endl;

    cout << "Average mark for student : " << average[100] << endl << endl;
}}}}
void student::averagek()
{
    sum=0; 
    average[100]=0;
     for (int j=0; j<amount; j++)     
    sum+=mark[j];
    average[100] = sum/amount;
}
int main()
{
    student z;
     z.read();
     z.to_screen();
     z.averagek();
    system("PAUSE");
    return 0;
}

Edited 6 Years Ago by TheCur3: n/a

>>i not very good in understanding vector<student> because i did everything what i learned in university but where was no such a thing vector.
A vector is like an array, but more versatile. If you are not familiar with them, create an appropriately-sized array of student objects instead.

One thing I just noticed: student::average is an integer array. This is not correct, it should be a non-array double.

Edited 6 Years Ago by Fbody: n/a

i have to chck the clock time after execution.means the clock time should continue in the execution prog.can anybody hlp me plzzzz.

Comments
Ditto
Start your own thread. Don't hijack.

You have threads to your name, I can see them on your profile, so don't give me that. The button is at the bottom of the thread listing now, not the top. Did you even look? It's huge, you can't miss it.

Edited 6 Years Ago by Fbody: n/a

no i hvnt looked it.there is nothing like that.i accessed it by clicking that u had typed.type it f0r only 1 more time.i will not disturb u again
regards

You can't see this? It's at the bottom of the thread listing. Not the bottom of this thread.

Edited 6 Years Ago by Fbody: n/a

Comments
Helping out the noobs :P
Attachments StartNewThread.jpg 49.53 KB

sorry, i just drop by to say that i was doing this type of program before, which is using linklist, it was better to organized i guess...

This article has been dead for over six months. Start a new discussion instead.