问答题已知考生的记录由学号和学习成绩构成,N名考生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最低的考生记录,通过形参返回主函数(规定只有一个最低分)。已给予出函数的首部,请完成该函数。
注意:部分源程序已存在文件kt8_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件kt8_2.cpp的内容如下:
#include
#include
#include
#defineN10
typedefstructss
{charnum[10];
ints;
}STU;
voidfun(STUa[],STU*s)
{
}
voidmain()
{STU
a[N]={{"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}},m;
fun(a,
cout
cout
问答题简单应用题
请编写一个函数int Count(double a[], int n),统计出具有n个元素的一维数组中大于等于所有元素平均值的元素个数并返回这个值。注意:请使用for循环实现该函数。
注意:部分源程序已存在文件test12_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数Count的花括号中填写若干语句。
文件test12_2的内容如下:
#include
int Count(double a[], int n)
{
}
void main()
{
double a[5];
cout>a[i];
}
int result=Count(a,5);
cout<<"大于等于所有元素平均值的元素个数:"<
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: Number=7 Number=12 注意:错误的语句在//******error******的下面,修改该语句即可。#include<iostream.h>class CMyClass{public: //********error******** CMyClass(int i):Number=i { //********error******** return Number; } void Set(int i) { Number=i; } void display() { cout<<"Number="<<Number<<endl; }private: int Number;};void main(){ //********error******** CMyClass *p=new CMyClass; P->display(); P->set(12); P->display(); return;}
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正错误,使得程序正常运行。并使程序输出结果为: ABCDEF ABCDEF ABCDEF 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//********error********的下面。#include<iostream.h>Void main(){ //********error******** char s1[]="ABC "DEF"; //********error******** char s2[]="ABCDEF"; //********error******** char s3[]="ABC"+ "DEF"; cout<<s1<<endl; cout<<s2<<endl; tout<<s3<<endl; return;}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。完成fun()函数,其功能是:将两个从小到大有序数组a和b,复制合并出一个有序整数序列c,其中形参n和m分别是数组a和b的元素个数。
注意:不能修改程序的其他部分,只能修改fun()函数。
#include
void fun (int a[],int n,int
b[],int m,int *c)
{
}
void main()
{
int A[]={3,5,7,9,11,18,21};
int B[]={6,15,19,21,39};
int C[15],i;
for(i=0;i<25;i++) c[i]=0;
cout<< "A[]=";
for(i=0;i<7;i++)
tout<
问答题请使用VC6或使用[答题]菜单打开
proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数operator=,以实现深层复制。
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”之间。不得修改程序的其他部分。
注意:程序最后将结果输出到文件out. dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//CDeepCopy. h
#icloude<iostream>
#include<string>
using namespace std;
class CDeepCopy
{
public:
int n;//动态数组的元素个数
int *P;//动态数组首地址
CDeepCopy(int);
~CDeepCopy();
CDeepCopy//赋值运算符函数
};
void writeToFile(char *);
//main. cpp
#include"CDeepCopy. h"
CDeepCopy::~CDeepCopy() {delete[]P;}
CDeepCopy::CDeepCopy(int k) {n=k; P=new int[n];}//构造函数实现
CDeepCopy
a. p[0]=1; d. p[0]=666;//对象a, d数组元素的赋值
{
CDeepCopy b(3);//调用赋值运算符函数
a. p[0]=88; b=a;
cout<<b. p[0];//显示内层局部对象的数组元素
}
cout<<d. p[0];//显示d数组元素a. p[0]的值
cout<<"d fade away;/n";
cout<<a. p[0];//显示a数组元素a. p[0]的值
writeToFile(" ");
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(hat N[4])的功能是用4个数字,组成互不相同且无重复数字的三位数,并将满足所有条件的数字输出到屏幕,并且每输出一个三位数字就换一行。
程序分析:可填在百位、十位、个位的数字都是1、2、3、0。组成所有的排列后再去掉不满足条件的排列。如果判定第一个数字是0则也去掉。
#include
void fun(int N[4])
{
}
int main()
{
int N[4]={1,2,3,0};
fun(N);
return 0;
}
问答题综合应用
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中包含主程序文件main.cpp和用户定义的头文件Array.h,整个程序包含有XArray类的定义和main主函数的定义。请在主程序文件中写出成员函数XArray::sort()的定义,经补充后运行程序,得到的输出结果为:
3 6 5 4 16 10 20 15
3 4 5 6 10 15 16 20
注意:只能在"//********333********"和"//********666********"之间填入若干语句,不得改动程序中的其他部分。
//Array.h
#include
#include
using namespace std;
class XArray { //数组类
int *a;
int size;
public:
XArray(int b[], int len): size(len) //构造函数
{
if(len100) {cout<<"参数值不当!/n"; exit(1);}
a=new int[size];
for(int i=0; i
问答题请编写一个函数int fun (int nFirst, int nSecond),求两个数的最小公倍数并返回这个值。
注意:部分源程序已存在文件test13_2.cpp中。如输入7和8时,结果是56。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test13_2的内容如下;
#include<iostream.h>
int fun(int nFirst,int nSecond);
void main()
{
int nFirst,nSecond;
cout<<"Please input the first one";
cin>>nFirst;
cout<<" Please input the second one";
cin>>nSecond;
cout<<"最小公倍数:"<<fun(nFirst,nSecond)<<endl;
}
int fun(int nFirst,int nSecond)
{
}
问答题试题源程序文件清单如下://proj3.cpp#include<iostream>usingnamespacestd;classPersonchar*idcardno;//用动态空间存储的身份证号char*name,//用动态空间存储的姓名boolismale;//性别:true为男,false为女public:Person(constchar*pid,constchar*pname,boolpmale);~Person()//**1************found**********(1);constchar*getIDCardNO()constreturnidcardno;constchar*getName()constreturnname;voidrename(constchar*new_name);boolisMale()constreturnismale;;classStaff:publicPersonchar*department;doublesalary;public:Staff(constchar*id_card_no,constchar*p_name,boolis_male,constchar*dept,doublesal);~Staff()delete[]department;constchar*getDepartment()constreturndepartment;voidsetDepartment(constchar*d);doublegetSalary()constreturnsalary,voidsetSalary(doubles)salary=s;;Person::Person(constchar*id_card_no,constchar*p_name,boolis_male):ismale(is_male)idcardno=newchar[strlen(id_card_no)+1];strcpy(idcardno,id_card_no);name=newchar[strlen(p_name)+1];strcpy(name,p_name);voidPerson::rename(constchar*new_name)delete[]name;//**2************found**********(2);strcpy(name,new_name);Staff::Staff(constchar*id_card_no,constchar*p_name,boolis_rnalc,//**3************found**********constchar*dept,doublesal):(3)deparlment=newchar[strlen(clept)+1];strcpy(department,dept);salary=sal;voidStaff::setDepartment(conslchar*dept)delete[]department;department=newchar[strlen(dept)+1];strcpy(department,dept);intmain()StaffZhangsan("123456789012345","张三",false,"人事部",1234.56);Zhangsan.rename("张小丽");cout<<Zhangsan.getName()<<Zhangsan.getIDCardNO()<<endl;return0;
问答题*
问答题请使用VC6或使用【答题】菜单打开
proj1下的工程proj1,其中有点类Point和线段类Line和主函数main的定义,程序中位于每个“// ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出应为:
p1=(8,4)p2=(3,5)
注意:只修改两个“// ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
#include <cmath>
using namespace std;
class Point {
double x, y;
public:
Point (double x = 0.0, double y = 0.0)
// ERROR *******found*******
{x=x; y=y;}
double getX() const {return x;}
double getY() const {return y;}
// ERROR *******found*******
void show() const {cout <<"<<x<<","<<y<<")"}
};
class Line{
Point p1,p2;
public:
Line (Point pt1, Point pt2)
// ERROR *******found*******
{pt1 = p1; pt2 = p2;}
Point getP1() const {return p1;}
Point getP2() const {return p2;}
};
int main() {
Line line (Point(8, 4), Point(3,5));
cout << "p1 =";
line.getP1(). show();
cout << "p2 =";
line.getP2(). show();
cout << endl;
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(char*s,char*s1,char*s2)中形参字符串s1和s2有相同的字符个数,且s1中各字符互不相同。该函数实现将已知字符串s中所有在字符串s1中也存在的字符,都用字符串s2中的对应位置的字符代替。
例如:设字符串s、s1和s2分别为:
s[]=“ABCABC”,
s1[]=“AC”,
s2[]=“ZX”
则s2中的字符z和X分别对应s1中的字符C和A,函数调用fun(s,s1,s2)将字符串s的内容变为“ZBXZBX”。
注意:不能修改程序的其他部分,只能修改fun()函数。
#include
void fun(char*s,char*s1,char
*s2)
{
}
void main()
{
char s[]=“ABCABC”;
fun(s,“AC”,“ZX”);
std::cout<
问答题使用VC++6.0打开
下的源程序文件3.cpp,其中定义的类不完整,按要求完成下列操作,将类的定义补充完整。
(1)定义类CPoint的带有两个参数的构造函数,两个变量为x、y,都为int型,且缺省值为0。请在注释1后添加适当的语句。
(2)完成类CReetangle的构造函数,给point1和point2赋值。请在注释2后添加适当的语句。
(3)完成类CRectangle的函数GetArea,用来计算矩形面积。请在注释3后添加适当的语句。
(4)定义CRectangle类,它拥有两个私有对象point1和point2,类型为Point,请在注释4后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
试题程序:
#include<iostream.h>
#include<cmath>
class CPoint
{
public:
//********1********
{
x=i;
y=j;
}
int GetX()
{
return x;
}
int GetY()
{
return y;
}
private:
int x,y;
};
class CRectangle
{
public:
//********2********
{
}
int GetArea()
{
//********3********
int height=point1.GetY()—point2.GetY();
return(width * height)?width * height:—width * height;
}
private:
//********4********
CPoint point2;
};
int main()
{
CRectangle rect(0,0,1,1);
cout<<rect.GetArea()<<endl;
return 0;
}
问答题使用VC6打开
下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使该程序的输出结果为:
100
注意:错误的语句在//******error******的下面,修改该语句即可。
#include<iostream.h>
static int x=50;
int t=0;
int *func(int x, int y, int z)
{
t=t+x+y+z;
//******error******
return t;
};
void main()
{
int y=30;
int x=10;
int z=20;
//******error******
x=x;
//******error******
cout
func(x,y,z)
endl;
}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错误,请改正程序中的错误。 本题的功能是:从键盘输入字符串S,然后输出字符串S中的字符个数。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//*******error*******的下面。#include <iostream>int main(){∥*******error******* cout<<“please input a s tring:”<<endl;∥*******error******* namespace std; char S[2 5 6]; cin.getline(S,256); cout<<Strlen(S)<<endl; return 0;}
问答题使用VC6打开
下的源程序文件modi2.cpp。请完成以下函数:
int factorial (int n):求出n的阶乘,必须使用递归调用。
如果n小于1则返回0。
注意:不能修改函数的其他部分。
#include <iostream.h>
#include <ctype.h>
int factorial(int n)
{
}
void main()
{
cout
factorial(1)
endl;
cout
factorial(5)
endl;
cout
factorial(0)
endl;
return;
}
问答题使用VC6打开考生文件夹proj2下的工程proj2,其中有两个类:一是销售类(Sale),用于表示按照一件商品的基本价格进行销售;另一个是打折销售类(DiscountSale),用于表示在基本价格基础上按一个折扣比例进行销售。DiscountSale类继承了sale类。类的主要数据成员的含义和成员函数的功能要求在程序注释中有说明。请在程序中的横线处填写适当的代码,然后删除横线,完成程序的功能。此程序的正确输出结果应为: Discount item is cheaper. Saving is 0.1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。#include<iostream>using namespace std;class Sale{ public: Sale();//默认构造函数,将price初始化为0 Sale(double the_price);//构造函数,用the_price初始化price virtual double bill()const;//返回当前商品的价格(基本价) double savings(const SaleDiscountSale:: DiscountSale ( ):discount(0){}DiScountSale::DiscountSale(doublethe_price,double the_discount) :Sale(the_price),discount(thediscount){)double DiscountSale::bill()const{ double fraction=discount/100 ; // ******found******________;//返回本对象打折以后的实际售价}bool operator<(const Sale}
问答题使用VC6打开
下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。函数convert(char *des,char* str)实现的功能是,如果字符串str里面有空格或者不可打印字符,则全部去掉,将转化后的字符串放在字符串des里,然后返回该字符串。
注意:不能修改程序的其他部分,只能补充convert ()函数。
#include <iostream.h>
#include <ctype.h>
#define MAXLEN 1024
char* convert(char *des,char* str)
{
}
void main()
{
char dest[MAXLEN];
char* str =" Ab cDeF hJ K";
cout
convert(dest, str)
endl;
return;
}
问答题使用VC6打开考生文件夹下的源程序文件modi2.epp。阅读下列函数说明和代码,补充空出的代码。函数conveX(char*des,char*str)实现的功能是,如果字符串s仃里面有空格或者不可打印字符,则全部去掉,将转化后的字符串放在字符串des里,然后返回该字符串。
注意:不能修改程序的其他部分,只能补充
convert()函数。
#include
#include
#define MAXLEN 1024
char*convert(char*des,char*
str)
{
}
void main()
{
char dest[MAXLEN];
char*str:” Ab cDeF hJ K”;
cout<