A.iman
دوشنبه 28 اسفند 1391, 13:09 عصر
سلام دوستان.
من یه کلاس نوشتم که اسم و شماره و نمره 4 درسو میگیره و در یه کلاس ذخیره میکنه...
ولی یه error ای میده که اصلا برام قابل فهم نیس!
student.h
// student header file
#include <string>
class student
{
private:
double cours1,cours2,cours3,cours4,avg;
int stno;
std::string name[20];
public :
student();
void AVG();
void setname(std::string);
void setstno(int);
void print();
void setcours(double,double,double,double);
}
student .cpp :
#include<iostream>
#include<string>
#include"student.h"
#include<iomanip>
student::student()
{cours1=cours2=cours3=cours4=avg=0;
}
void student::setcours(double a,double b, double c, double d)
{cours1=a;
cours2=b;
cours3=c;
cours4=d;
}
void student::setname(std::string n)
{
name[20] = n;
}
void student::setstno(int e)
{
stno =e;
}
void student::AVG()
{
avg= (cours1+cours2+cours3+cours4)/4 ;
}
void student::print()
{
std::cout<<name<<std::setw(4)<<stno<<std::endl;
std::cout<<"cours1 :"<<cours1<<" cours2 :"<<cours2<<" cours3"<<cours3<<" cours4"<<cours4<<std::endl;
}
st1.cpp:
#include<iostream>
#include<string>
#include"student.h";
#include<iomanip>
int main()
{
int i,m,q[3];
std::string n[20];
student st;
std::cout<<"pleas enter the name of student ?"<<std::endl;
std::cin>>n[20];
st.setname( n[20]);
std::cout<<std::endl<<"pleas enter the number of student ?"<<std::endl;
std::cin>>m;
st.setstno( m);
for(i=0;i<4;i++)
{
std::cout<<"pleas enter the cours "<<i<<":"<<std::endl;
std::cin>>(q[i]);
}
st.setcours(q[0],q[1],q[2],q[3]);
st.AVG();
st.print();
}
من یه کلاس نوشتم که اسم و شماره و نمره 4 درسو میگیره و در یه کلاس ذخیره میکنه...
ولی یه error ای میده که اصلا برام قابل فهم نیس!
student.h
// student header file
#include <string>
class student
{
private:
double cours1,cours2,cours3,cours4,avg;
int stno;
std::string name[20];
public :
student();
void AVG();
void setname(std::string);
void setstno(int);
void print();
void setcours(double,double,double,double);
}
student .cpp :
#include<iostream>
#include<string>
#include"student.h"
#include<iomanip>
student::student()
{cours1=cours2=cours3=cours4=avg=0;
}
void student::setcours(double a,double b, double c, double d)
{cours1=a;
cours2=b;
cours3=c;
cours4=d;
}
void student::setname(std::string n)
{
name[20] = n;
}
void student::setstno(int e)
{
stno =e;
}
void student::AVG()
{
avg= (cours1+cours2+cours3+cours4)/4 ;
}
void student::print()
{
std::cout<<name<<std::setw(4)<<stno<<std::endl;
std::cout<<"cours1 :"<<cours1<<" cours2 :"<<cours2<<" cours3"<<cours3<<" cours4"<<cours4<<std::endl;
}
st1.cpp:
#include<iostream>
#include<string>
#include"student.h";
#include<iomanip>
int main()
{
int i,m,q[3];
std::string n[20];
student st;
std::cout<<"pleas enter the name of student ?"<<std::endl;
std::cin>>n[20];
st.setname( n[20]);
std::cout<<std::endl<<"pleas enter the number of student ?"<<std::endl;
std::cin>>m;
st.setstno( m);
for(i=0;i<4;i++)
{
std::cout<<"pleas enter the cours "<<i<<":"<<std::endl;
std::cin>>(q[i]);
}
st.setcours(q[0],q[1],q[2],q[3]);
st.AVG();
st.print();
}