hey guy's iam a biggner at data structure n there z a program i did it bt everytime i run it doesn't work with me and i dono what is the wrong on it can somebody help me plz

#include <iostream>
#include <string>
using namespace std;
class student_grades{
private:
string name,n;
int Id,i;
double* grades[];
public:
student_grades();
student_grades(string,int);
student_grades(const student_grades&);
void set(string name,int Id){
cout<<"enter the name and the ID";
cin>>n>>i;
n=name;
i=Id;
}
void get(){
return i;
return n;
}
void student_grades (student_grades&opr){
name=name.opr;
Id=Id.opr;
grades[]=grades[].opr;
}
void student_info(){
cout<<"the name of the student is:"<<name;
cout<<"the id for the srudent is:"<<Id;
grades=new double[];
cout<<"the grades of the student is:"<<grades[]<<endl;
delete []grades;
}
};
student_grades::student_grades(string name,int Id){
name="n";
Id=0;}
student_grades::student_grades(const student_grades&copy){
name=copy.name;
Id=copy.Id;}
int main()
{
  student_grades std1;
  std1.set();
  cin>>std1.grades[5];
  std1.get();
  student_grades std2;
  std2.set();
  cin>>std2.grades[6];
  std2.get();
  student_grades std3;
  std3.set();
  cin>>std3.grades[4];
  std3.get();
  student_grades std4;
  std4.set();
  cin>>std4.grades[];
  std4.get();
  std1=std3;
  std2=std4;
  cout<<std1<<std2<<std3<<std4;

    return 0;
}

Recommended Answers

All 7 Replies

Welcome to daniweb and glad to see that you at least made an effort to try and add code tags but obviously it didn't work for you. To use code tags you simply press the button that says code when posting then paste you code between those two tags.

As per your question, c++ does not allow for dynamic arrays so for example line 5 should be double* grades[5]; . Then you will need to adjust the rest of your code to fix your array problem since unlike languages such as php, you can't append to an array simply be grades[]= or at least to my knowledge.

Welcome to daniweb and glad to see that you at least made an effort to try and add code tags but obviously it didn't work for you. To use code tags you simply press the button that says code when posting then paste you code between those two tags.

As per your question, c++ does not allow for dynamic arrays so for example line 5 should be double* grades[5]; . Then you will need to adjust the rest of your code to fix your array problem since unlike languages such as php, you can't append to an array simply be grades[]= or at least to my knowledge.

thank you so much but the wrong is showen when i ever try to run it in this statment

void student_grades(student_grades&paste){
name=name.paste;
Id=Id.paste;

and yaaa how the grade should b taken as grades* double[5]; and it z dynamic array and the dynamic array as i know from my studying that we can't set the size for the dynamic array it'z whenever the user want to set number it set it to it in the time he want not fixed in the memory as 5 this is wt i know i hope u help me n this n if iam wrong i would like that u tell me

instead of

void student_grades(student_grades&paste){
name=name.paste;
Id=Id.paste;

try

void student_grades(student_grades&paste){
name=paste.name;
Id=paste.Id;

also, you'd better follow some tutorials of how to write clean code and improve your writing style because you code layout is horrible(no offense)

instead of

void student_grades(student_grades&paste){
name=name.paste;
Id=Id.paste;

try

void student_grades(student_grades&paste){
name=paste.name;
Id=paste.Id;

also, you'd better follow some tutorials of how to write clean code and improve your writing style because you code layout is horrible(no offense)

k thanx for letting me know i'll make sure to work on this and i did wt u said but itz still the same didnt work i will work ma best on it till it works
note:the code i gave u is for operator overloading

instead of

void student_grades(student_grades&paste){
name=name.paste;
Id=Id.paste;

try

void student_grades(student_grades&paste){
name=paste.name;
Id=paste.Id;

also, you'd better follow some tutorials of how to write clean code and improve your writing style because you code layout is horrible(no offense)

it'z me again i solved the program and still i have some comments on them but i didn't understand where z the problem can anybody plz plz plz plz tell me

#include <iostream>
#include <string>
using namespace std;
class student_grades{
private:
string name,n;
int Id,size,id;
double* grades;
public:
student_grades();
student_grades(string,int);
student_grades(const student_grades&);
void setname(){
cout<<"enter the name";
cin>>n;
name=n;
}
string getname(){
return name;
}
void setId(){
cout<<"please enter the id";
cin>>id;
Id=id;
}
int getId(){
return Id;
}
void student_grades(student_grades&opr){
name=opr.name;
Id=opr.Id;
int size=grades=new// WRONG. we need the overloaded assignment(=) operator to solve this situation
}
void student_info(){
cout<<"the name of the student is:"<<name;
cout<<"the id for the srudent is:"<<Id;
cout<<"please enter the grades"<<endl;
cout<<"the grades of the student is:"<<grades<<endl;
}
};
student_grades::student_grades(string n,int id){
name=n;
Id=id;}
student_grades::student_grades(const student_grades&cpy){
name=cpy.name;
Id=cpy.Id;
size=cpy.size;
grades=new double[size];
for(int i=0;i<size;i++)
   // make the copy of cpy grades into current object's grades

}
int main()
{
  student_grades std1;
  std1.set();
  cin>>std1.grades[5];
  std1.get();
  student_grades std2;
  std2.set();
  cin>>std2.grades[6];
  std2.get();
  student_grades std3;
  std3.set();
  cin>>std3.grades[4];
  std3.get();
  student_grades std4;
  std4.set();
  cin>>std4.grades[0];
  std4.get();
  std1=std3;
  std2=std4;
  cout<<std1<<std2<<std3<<std4;
// delete all dynamic storage
    return 0;
}

Learn to use indentation (and space-out your code) and please write in correct English (i.e. "Do post in full-sentence English" it is really annoying to read things like "it z bt hr n dr i v prbs plz hlp" instead of "It's between here and there that I have problems, please help me.").

Learn to use indentation (and space-out your code) and please right in correct English (i.e. "Do post in full-sentence English" it is really annoying to read things like "it z bt hr n dr i v prbs plz hlp" instead of "It's between here and there that I have problems, please help me.").

ok sorry it's a bad habit on me ,but ok i will stop my abbreviations

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.