自学C++

 

#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;
using std::endl;

template< class T, class M>
class Math
{
public:
 M plus( T a, M b )
 {
  return ( a + b );
 };
private:
 T max;
 T min;
};

class Student
{
public:
 Student();
 Student( string num, float Eng );
 ~Student();

 Student operator +( Student &student );

 void Information();

 void setAddress( Student *N );
 Student * getAddress();
private:

 string number;
 float English;

 Student *next;
};

Student::Student()
{

}

Student::Student( string num, float Eng )
{
 number = num;
 English = Eng;
}

Student::~Student()
{

}

Student Student::operator +( Student &student )
{
 Student container;

 container.number = number + student.number;
 container.English = English + student.English;

 return container;
}

void Student::Information()
{
 cout<< "学号:"<< number<< "成绩:"<< English<< endl;
 cout<< "地址:"<< next<< endl;
}

void Student::setAddress( Student *N )
{
 next = N;
}

Student *Student::getAddress()
{
 cout<< "本对象地址:"<< next<< endl;
 return next;
}

void main()
{
 /*
 Student student1( "100323", 100.0 );
 Student student2( "100000", 90.0 );
 Student student3( "0", 0.0 );


 student1.Information();
 student2.Information();
 student3.Information();
 */

 Student *student1 = new Student( "100323", 140.0 );
 Student *student2 = new Student( "100000", 145 );
 Student *student3 = new Student( "0", 0 );

 //student2->setAddress( student1 );

 student1->getAddress();
 student2->getAddress();
 student3->getAddress();

 *student3 = *student1 + *student2;

 student3->Information();

 Math< int, char > math1;

 cout<< math1.plus( 12, 'A' )<< endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值