constructor and destructor problem

Hi guys, i am new in the forum and i need your help for this exercise:
(I thing i am on the rigth side.Sorry if it is too long ).

To create the class student with the following private data:
• the number of the student (int) (from 1 to 9999)
• The name of the student (char *) (up to 40 characters)
• The number of courses has given (int) (from 1 to 8)
• The score for each subject (float *) (from 1.0 to 10.0)
• Ti aggregate score (average) collected (float)
• The number of courses passed and those who cut (int)
• The minimum and maximum points (float)
As members of the pubic student, define the following:
• The functions for initialization and import prices in each of the four first data class (data problem). To place the necessary control data entry and if given invalid values, functions to set some defaults (default) (eg set "No_name" for the name, and zero values ​​for all other cases).
• The functions to initialize, calculate and award values ​​to other data class (request the problem).
• The function to print the total data of the student.
• The constructor initializes which will make and set appropriate values ​​in the data class and the corresponding destructor.
The function main () will define objects of class and then use the print function to display the results as shown in the example below (the initial prices will be given by the main () and not the user):

Name: James Statbk
Id: 1510
Subjects Given: 5
Grades taken: 7.0, 3.0, 6.0, 10.0, 4.0
Passed in 3 Subjects, Failed in 2 Subjects
Average Grade: 6
Minimum Grade: 3.0
Maximum Grade: 10.0


code:
#include<iostream>
using namespace std;

class student{
private:
int ID;//identity
char *NAME;//name
int SUB;// subjects
float *GR_PER;//grade per subject
float AV;//average
int PS;//passed subjects
int FS;//failed subjects
float MAX;// max grade
float MIN;//min grade

public:
student(int sub,float gr_per)//here is a problem
{

int N;
set_SUB;
N=get_SUB;
gr_sub=new float[n];
if(gr_sub!=0)//sucessful dynamic allocating memory
{
for(int i=0;i<N;i++);
GR_PER[i]=gr_sub[i];*/
// }
}//constructor
// ~student(){delete ????}//destructor


void set_ID(int id);
void set_NAME(char name);
void set_SUB(int sub);
void set_GR_PER(float gr_per);
void set_AV();
void set_PS_FS();
void set_MAX_MIN();
void set_MIN();

int get_ID(){return ID;}
char get_NAME(){return NAME;}
int get_SUB(){return SUB;}
float get_GR_PER(){return GR_PER;}
float get_AV(){return AV;}
int get_PS(){return PS;}
int get_FS(){return get_SUB()-get_PS;}
float get_MAX(){return MAX;}
float get_MIN(){return MIN;}

void print();
}

void student::set_ID(int id)
{
if(id<1 || id>99)
ID=id;
else
ID=0;
}

void student::set_NAME(char *name)
{ if(name<0 || name>40 )
strcpy(NAME,name);
else
strcpy(NAME,"NO NAME");
}

void student::set_SUB(int sub)
{
if(int sub<1 || sub>8)
SUB=sub;
else
SUB=0;
}
void student::set_GR_SUB(float gr_sub )
{
if(gr_sub<1 || gr_sub>10)
GR_SUB= gr_sub;
else
GR_SUB=0;
}
void student::set_AV()
{ float av=0;
for(int i=0;i<get_SUB();i++)
{
av=av+gr_per[i];
}

AV=av/get_SUB();}

void student::set_PS_FS()
{ int ps=0;
int fs=0;
for(int i=0;i<get_SUB();i++)
{ float *grades=get_GR_PER();//can i do that
if(grades[i]>=5)
{
ps++;
}
}
PS=ps;}

void student::set_MAX()
{ float max=0;
for(int i=0;i<pl;i++)
{
float *grades=get_GR_PER();//can i do that
if(grades[i]>=max)
{
max=v[i];
}
}
if(max!=0)
{MAX=max;}
}
void student::set_MIN()
{ float min=10;
for(int i=0;i<pl;i++)
{ float *grades=get_GR_PER();
if(v[i]<min)
{
min=v[i];
}
}
if(min!=10)
{MIN=min;}
}
void student::print()
{ cout<<"Name:"<<get_NAME()<<"\n";
cout<<"Id: "<<get_ID()<<"\n";
cout<<"Subjects Given:"<<get_SUB()<<"\n";
cout<<"Grades taken:"<<get_GR_PER()<<"\n";
cout<<"Passed in "<<get_PS<<"Subjects, Failed in:"<<get_FS<<"Subjects"<<"\n";
cout<<"Average Grade:"<<get_AV<<"\n";
cout<<"Minimum Grade:"<<get_MAX<<"\n";
cout<<"Maximum Grade:"<<get_MIN<<"\n";}
//------------
int main()
{
student s1;
char name[]='James Statbk';
int id=1510,sub_per=5;
float g[]={7.0, 3.0, 6.0, 10.0, 4.0};
// int num=sizeof(B)/sizeof(float);
// student s1(num,B)//


s1.set_NAME(name);
s1.set_ID(id);
s1.set_SUB_PER(sub_per);
s1.set_G(g);

s1.set_AV();
s1.set_PS_FS();
s1.set_MAX();
s1.set_MIN();

s1.print();


}
Is there a question?
im dont know how to define the constructor in this programma
(public:
student(int sub,float gr_per)//here is a problem)
1
2
3
4
student::student(int sub, float gr_per)
{
  // code in here to do something with sub and gr_per
}
I want to make an array with name gr_per and withdimension sub and
i dont know if thw code below is ok
1
2
3
4
5
6
7
8
9
10
11
12
student::student(int sub, float gr_per)
int N;
set_SUB();
N=get_SUB();
gr_sub=new float[N];
if(gr_sub!=0)//sucessful dynamic allocating memory
{
for(int i=0;i<N;i++);
GR_PER[i]=gr_sub[i];
}
}//constructor
 

Topic archived. No new replies allowed.