C++ primer plus(第六版)编程练习答案 第14章 C++中的代码重用

一、程序清单

studentc.h

// studentc.h -- defining a Student class using containment
#ifndef STUDENTC_H_
#define STUDENTC_H_

#include <iostream>
#include <string>   
#include <valarray>
class Student
{
private:
	typedef std::valarray<double> ArrayDb;
	std::string name;       // contained object
	ArrayDb scores;         // contained object
	// private method for scores output
	std::ostream & arr_out(std::ostream & os) const;
public:
	Student() : name("Null Student"), scores() {}
	explicit Student(const std::string & s)
		: name(s), scores() {}
	explicit Student(int n) : name("Nully"), scores(n) {}
	Student(const std::string & s, int n)
		: name(s), scores(n) {}
	Student(const std::string & s, const ArrayDb & a)
		: name(s), scores(a) {}
	Student(const char * str, const double * pd, int n)
		: name(str), scores(pd, n) {}
	~Student() {}
	double Average() const;
	const std::string & Name() const;
	

猜你喜欢

转载自blog.csdn.net/qq_43445867/article/details/129781851