
#include
#pragma warning (disable:4996)
using namespace std;
class Score{
public:
Score(const char *the_course, const char *the_id, int the_normal, int the_midterm, int the_end_of_term)
: course(the_course), normal(the_normal), midterm(the_midterm) , end_of_term(the_end_of_term){
// ERROR **********found**********
strcpy(the_id,student_id);
}
const char *getCourse()const{ return course; } //返回课程名称
// ERROR **********found**********
const char *getID()const{ return &student_id; } //返回学号
int getNormal()const{ return normal; } //返回平时成绩
int getMidterm()const{ return midterm; } //返回期中考试成绩
int getEndOfTerm()const{ return end_of_term; } //返回期末考试成绩
int getFinal()const; //返回总评成绩
private:
const char *course; //课程名称
char student_id[12]; //学号
int normal; //平时成绩
int midterm; //期中考试成绩
int end_of_term; //期末考试成绩
};
//总评成绩中平时成绩占20%,期中考试占30%,期末考试占50%,最后结果四舍五入为一个整数
// ERROR **********found**********
int getFinal()const{
return (int)(normal*0.2+midterm*0.3+end_of_term*0.5+0.5);
}
int main(){
char English[]="英语";
Score score(English,"12345678",68,83,92);
cout<<"学号:"<
基本 *** 作 答案
#include
#pragma warning (disable:4996)
using namespace std;
class Score{
public:
Score(const char *the_course, const char *the_id, int the_normal, int the_midterm, int the_end_of_term)
: course(the_course), normal(the_normal), midterm(the_midterm) , end_of_term(the_end_of_term){
// ERROR **********found**********
strcpy(student_id,the_id);
}
const char *getCourse()const{ return course; } //返回课程名称
// ERROR **********found**********
const char *getID()const{ return student_id; } //返回学号
int getNormal()const{ return normal; } //返回平时成绩
int getMidterm()const{ return midterm; } //返回期中考试成绩
int getEndOfTerm()const{ return end_of_term; } //返回期末考试成绩
int getFinal()const; //返回总评成绩
private:
const char *course; //课程名称
char student_id[12]; //学号
int normal; //平时成绩
int midterm; //期中考试成绩
int end_of_term; //期末考试成绩
};
//总评成绩中平时成绩占20%,期中考试占30%,期末考试占50%,最后结果四舍五入为一个整数
// ERROR **********found**********
int Score::getFinal()const{
return (int)(normal*0.2+midterm*0.3+end_of_term*0.5+0.5);
}
int main(){
char English[]="英语";
Score score(English,"12345678",68,83,92);
cout<<"学号:"<
简单 *** 作 原题
//proj2.cpp
#include "shape.h"
#include
using namespace std;
//**********found**********
______________________________ // show函数的函数头(函数体以前的部分)
{
cout<<"此图形是一个" << shape->name()
<< ", 周长="<perimeter()
<< ", 面积="<area()<
//shape.cpp
#include "shape.h"
#include
double length(Point p1,Point p2)
{
return sqrt((p1.getX()-p2.getX())*(p1.getX()-p2.getX())+
(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));
}
double Triangle::perimeter()const
{ //一个return语句,它利用length函数计算并返回三角形的周长
//**********found**********
________________________________________________________________________ ;
}
double Triangle::area()const
{
double s=perimeter()/2.0;
return sqrt(s*(s-length(point1,point2))*
(s-length(point2,point3))*
(s-length(point3,point1)));
}
//shape.h
class Shape{
public:
virtual double perimeter()const { return 0; } //返回形状的周长
virtual double area()const { return 0; } //返回形状的面积
virtual const char* name()const { return "抽象图形"; } //返回形状的名称
};
class Point{ //表示平面坐标系中的点的类
double x;
double y;
public:
//**********found**********
Point (double x0,double y0):____________________{ }//用x0、y0初始化数据成员x、y
double getX()const{ return x;}
double getY()const{ return y;}
};
class Triangle: public Shape{
//**********found**********
_____________________________________ ; //定义三角形的三个顶点
public:
Triangle(Point p1,Point p2,Point p3):point1(p1),point2(p2),point3(p3){}
double perimeter()const;
double area()const;
const char* name()const{ return "三角形"; }
};
简单 *** 作 答案
//proj2.cpp
#include "shape.h"
#include
using namespace std;
//**********found**********
void show(Shape * shape) // show函数的函数头(函数体以前的部分)
{
cout<<"此图形是一个" << shape->name()
<< ", 周长="<perimeter()
<< ", 面积="<area()<
//shape.cpp
#include "shape.h"
#include
double length(Point p1,Point p2)
{
return sqrt((p1.getX()-p2.getX())*(p1.getX()-p2.getX())+
(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));
}
double Triangle::perimeter()const
{ //一个return语句,它利用length函数计算并返回三角形的周长
//**********found**********
return length(point1,point2)+length(point2,point3)+length(point1,point3);
}
double Triangle::area()const
{
double s=perimeter()/2.0;
return sqrt(s*(s-length(point1,point2))*
(s-length(point2,point3))*
(s-length(point3,point1)));
}
//shape.h
class Shape{
public:
virtual double perimeter()const { return 0; } //返回形状的周长
virtual double area()const { return 0; } //返回形状的面积
virtual const char* name()const { return "抽象图形"; } //返回形状的名称
};
class Point{ //表示平面坐标系中的点的类
double x;
double y;
public:
//**********found**********
Point (double x0,double y0):x(x0),y(y0){ }//用x0、y0初始化数据成员x、y
double getX()const{ return x;}
double getY()const{ return y;}
};
class Triangle: public Shape{
//**********found**********
Point point1,point3,point2; //定义三角形的三个顶点
public:
Triangle(Point p1,Point p2,Point p3):point1(p1),point2(p2),point3(p3){}
double perimeter()const;
double area()const;
const char* name()const{ return "三角形"; }
};
综合应用 原题
//main.cpp
#include "Array.h"
//交换数组a中前后位置对称的元素的值
template
void Array::Contrary() { //补充函数体
//********333********
//********666********
}
int main(){
int s1[5]={1,2,3,4,5};
double s2[6]={1.2,2.3,3.4,4.5,5.6,8.4};
Array d1(s1,5);
Array d2(s2,6);
int i;
d1.Contrary(); d2.Contrary();
cout<
//Array.h
#include
using namespace std;
template
class Array { //数组类
public:
Array(Type b[], int mm) { //构造函数
for(int i=0; i=m) {cout<<"下标越界!"<
综合应用 答案
//main.cpp
#include "Array.h"
//交换数组a中前后位置对称的元素的值
template
void Array::Contrary() { //补充函数体
//********333********
Type b[m];
for(int i=0;i d1(s1,5);
Array d2(s2,6);
int i;
d1.Contrary(); d2.Contrary();
cout<
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)