问答题已知考生的记录由学号和学习成绩构成,N名考生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最低的考生记录,通过形参返回主函数(规定只有一个最低分)。已给予出函数的首部,请完成该函数。 注意:部分源程序已存在文件test8_2.cpp中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 文件test8_2.cpp的内容如下: #include<iostream.h> #include<string.h> #include<conio.h> #define N 10 typedef struct ss char num[10]; int s; STU; void fun(STU a[],STU *s) void main( ) 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<<"***** The original date *****"<<endl; cout<<"The lowest :"<<m.num<<m.s<<endl;
问答题请使用VC6或使用[答题]菜单打开考生文件夹projl下的工程proj1,该工程含有一个源程序文件proj1. cpp。其中位于每个注释“//ERROR **** found ****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The value is 10 注意:只修改注释“//ERROR ***** found ****”的下一行语句,不要改动程序中的其他内容。 // proj1, cpp #include < iostream > using namespace std; class MyClass int value ; public : // ERROR ******** found ******** void MyClass(int val) : value(val) int GetValue() const return value; void SetValue(int val) ; ; //ERROR ******** found ******** inline void SetValue(int val) value = val; int main() MyClass obj (0) ; obj. SetValne(10) ; //ERROR ******** found ******** 下列语句功能是输出obj的成员value的值 cout << "The value is " << obj. value << endl; return 0 ;
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行有问题,请改正main函数中的错误,使程序的输出结果是:1 1 2 2 3 34 4 5 5 6 67 7 8 8 9 9注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//******error******的下面。#include<iostream.h>#include<iomanip.h>void main(){int a[3][3]={{1,2,3),{4,5,6},{7,8,9}};int*p,i;//********error********p=a;for(i=0;i<9;i++){cout<<setw(2)<<*(p+i);//********error********cout<<setw(2)<<*(a+i);if(i%3==2)cout<<endl;}}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(int x),该函数功能是将x的值转换成二进制数输出到屏幕,并且在函数中调用写函数WriteFile()将结果输出到modi2.txt文件中。
例如:x=13,13的二进制数字为1101,则输出到屏幕的为1101。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
#include
#include
#include
using namespace std;
void WriteFile(char*str)
{
ofstream outl;
outl.open(“modi2.txt”,ios—
base::binary | ios—base::app);
for(int i=0;str[i]!=0; i++)
out1.put(str[i]);
out1.close();
}
void fun(int x)
{
}
void ClearFile()
{
Ofstream out1;
out1.open(“modi2.txt”);
out1.close();
}
int main()
{
ClearFile();
fun(1 3);
return 0;
}
问答题使用VC++6.0打开
下的源程序文件3.cpp。其中定义的类不完整,按要求完成下列操作,将类的定义补充完整。
(1)在类TC中定义name为字符串类型,age为int型,请在注释1之后添加语句。
(2)设置类TC0的基类为TC类的定义,请在注释2后添加语句。
(3)在类TC的派生类TC0的公有成员中定义析构函数TC0,请在注释3后添加语句。
(4)设置类TC1的基类为 TC类的定义,请在注释4后添加语句。
程序输出结果为:
TC class constructor
TC0 class constructor
TC on class constructor
TC1 class constructor
TC1class constructor
TC class constructor
TC0 class constructor
TC class constructor
注意:增加或者修改代码的位置已经用符号表示出来,请不要修改其他的程序代码。
试题程序:
#include<iostream.h>
class TC
{
//********1********
public:
TC() {cout << "TC class constructor" <<endl;}
~TC() {cout << "TC class constructor" << endl;}
};
//********2********
{
char *departmert;
int level;
public:
TC0()
{cout << "TC0 class constructor" << endl;}
//********3********
{cout << "TC0 class constructor" << endl;}
};
//********4********
{
char *major;
float salary;
public:
TC1() {cout << "TC1 class constructor" <<endl;}
~TC1() {cout << "TC1 class constructor" << endl;}
};
void main()
{
TC0 s1;
TC1 t1;
}
问答题请使用VC6或使用【答题】菜单打开考生文件夹pmj2下的工程pmj2,其中有矩阵基类MatrixBase、矩阵类Matrix和单位阵UnitMatrix的定义,还有main函数的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:123452345634567100000010000001000000100000010000001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//,****found****”。#include<iostream>usingnamespacestd;//矩阵基础类,一个抽象类classMatrixBase{introws,cols;public:MatrixBase(introws,intcols):rows(rows),colS(colS){}intgetRows()const{returnrows;}//矩阵行数intgetCols()const{returncols;}//矩阵列数virtualdoublegetElement(intr,intC)const=0;//取第i个元素的值voidshow()const{//分行显示矩阵中所有元素for(inti=0;i<rows;i++){cout<<end1;for(intj=0;j<cols;j++)//**********found**********cout<<________<<"";}}};//矩阵类classMatrix:publicMatrixBase{double*val;public://**********found**********Matrix(introws,intcols,doublem[]=NULL):________{//**********found**********val=________;for(inti=0;i<rows*cols;i++)val[i]=(m=NULL?0.0:m[i]);}~Matrix(){delete[]val;}doublegetElement(intr,intC)const{returnval[r*getCols()+c];)};//单位阵(主对角线元素都是1,其余元素都是0的方阵)类classUnitMatrix:publicMatrixBase{public:UnitMatrix(introws):MatrixBase(rows,rows){}//单位阵行数列数相同doublegetElement(intr,intc)const{//**********found**********if(________)return1.0;return0.0;}};intmain(){MatrixBase*m;doubled[][5]={{1,2,3,4,5),{2,3,4,5,6),{3,4,5,6,7)};m=newMatrix(3,5,(double*)d);m->show();deletem;cout<<end1;m=newUnitMatrix(6);m->show();deletem;return0;}
问答题请使用VC6或使用【答题】菜单打开考生文件夹pmj3下的工程proj3,其中声明了一个单向链表类sLst。sList的成员函数Prepend的功能是在链表头部加入一个新的元素。请编写成员函数Prepend。在main函数中给出了一组测试数据,此时程序的输出应为:B->A-->###A->###A->###exitinginnerblockexitingouterblock注意:只在函数Prepend的“//**********333**********”和“//**********666**********”之间填入若干语句,不要改动程序中的其他内容。//SList.hstructsListItem{chardata;sListItem*next;};classsList{public:sList():h(0){}//0表示空链表~sList();voidPrepend(charc);//在链表前端加入元素voidDel();//删除链表首元素sListItem*First()const{returnh;}//返回链表首元素voidPrint()COnSt;//打印链表内容voidRelease();//销毁链表private:sListItem*h;//链表头};voidwriteTOFile(constchar*);//main.cpp#include<iostream>#include"sList.h"usingnamespacestd,sList::一sList(){Release();}voidsList::Prepend(charc){//********333********//********666********}voidsList::Del(){sListltem*temp=h;h=h->next;deletetemp;}voidsList::Print()const{sListItem*temp=h;while(temp!=0)//判断是否到达链表尾部{cout<<temp->data<<"->";temp=temp->next;}cout<<"\n###"<<end1;}voidsList::Release(){while(h!=0)Del();}intmain(){sList*ptr;{sListobj;obj.Prepend('A');obj.Prepend('B');obj.Print();obj.Del();obj.Print();ptr=&obj;ptr->Print();cout<<"exitinginnerblock"<<end1;}cout<<"exitingouterblock"<<end1;writeToFile("");return0;}
问答题简单应用题
请编写一个函数intCalcDigital(char*str),该函数可返回字符串str中数字字符(即“0”-“9”这10个数字)的个数,如字符串"olympic2008"中数字字符的个数为4。请用if条件判断语句与for循环语句来实现该函数。
注意:部分源程序已存在文件中。
请勿修改主函数main和其他函数中的任何内容,仅在函数find的花括号中填写若干语句。
文件kt9_2.cpp的内容如下:
#include
#include
intCalcDigital(char*str);
voidmain()
{ char*str;
str=newchar[255];
cout>str;
intnum=CalcDigital(str);
cout<
问答题简单应用题
请编写一个函数sortnum(intnum),参数num是一个三位的整数,该函数将num的百位、十位和个位的数字进行重排,并返回由上述的三个数字组成的最大的三位数。
注意:部分源程序已存在文件kt13_2.cpp中。
如输入456后,输出结果如下:
654
请勿修改主函数main和其他函数中的内容,仅在函数sortnum的花括号中填写若干语句。
文件kt13_2.cpp的内容如下:
#include
intsortnum(intnum)
{
}
voidmain()
{ intnum;
intresult=0;
cout>num;
cout<
问答题使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(intn)的功能是在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个,并作为参数返回。
注意:不能修改程序的其他部分,只能修改fun函数。
试题程序:
#include
#defineN100
inta[N][N];
intfun(intn)
{
}
voidmain()
{
intn;
cout>n;
for(inti=0;i for(intj=0;j {
cout>a[i][j];
}
eout<<"Theminofmaxnumbersis"< }
问答题使用VC6打开
下的源程序文件modi3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整。请按要求完成下列操作,将类Date的定义补充完成。
(1)定义私有数据成员year、month和day,分别用于表示年、月和日,它们都是int型的数据。请在注释//********1********之后添加适当的语句。
(2)完成默认构造函数Date的定义,使Date对象的默认值为:year=1,month=1,day=1,请在注释********2********之后添加适当的语句。
(3)完成重载构造函数Date(int y,int m,hat d)的定义,把数据成员year、month和day分别初始化为参数y、m和d的值,请在注释//********3********之后添加适当的语句。
(4)完成成员函数print()的类外定义,使其以“年-月-日”的格式将Date对象的值输出到屏幕上,例如:2008-8-8。请在注释//********4********之后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
#include <iostream.h>
class Date{
public:
//********2********
Date(int y, int m, int d)
{
//********3********
}
void print() const;
private:
//data member
//********1********
};
void Date::print() const
//********4********
}
int main(){
Date national_day(1949,10,1);
national_day.print();
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)完成类TestClass1的成员函数seta定义,定义seta对象x为int类型,请在注释//********1********后添加适当的语句。 (2)完成类TestClass1(共有)和类TestClass2(私有)派生类TestClass3的定义,请在注释//********2********后添加适当的语句。 (3)定义类TestClass3中的私有成员C为int,请在注释//********3********后添加适当的语句。 (4)完成setc中对基类的变量a的赋值,请在注释//********4********后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#include<iostream.h>class TestClass 1{ int a;public: //********1******** { return a=x; } void showa() { cout<<a<<end1; } }; class TeStClass2 { int b;public: void setb(int X) { b=x; } void showb() { cout<<b<<end1; }};//********2********{private: //********3********public: void setc(int x,int y,int z) { c=z; //********4******** setb(y); } void showc() { cout<<C<<end1; }};void main() { TestClass3 c; C.seta(5); C.showa(); C.setc(5,7,4); C.showc();}
问答题请使用VC6或使用【答题】菜单打开proj3下的工程proj3,其中定义的Matrix是一个用于表示矩阵的类。成员函数max_value的功能是求出所有矩阵元素中的最大值。例如,若有3×3矩阵则调用max_value函数,返回值为3。请编写成员函数max_value。要求:补充编制的内容写在“//*******333*******”与“//*******666*******”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//Matrix.h#include<iostream>#include<iomanip>usingnamespacestd;constintM=18;constintN=18;classMatrix{intarray[M][N];public:Matrix(){}intgetElement(inti,intj)const{returnarray[i][j];}voidsetElement(inti,intj,intvalue){array[i][j]=value;}intmax_value()const;voidshow(constchar*s)const{cout<<endl<<s;for(inti=0;i<M;i++){cout<<endl;for(intj=0;j<N;j++)cout<<setw(4)<<array[i][j];}}};voidreadFromFile(constchar*,MatrixvoidwriteToFile(char*,constMatrix//main.cpp#include"Matrix.h"#include<fstream>voidreadFromFile(constchar*f,Matrixif(infile.fail()){cerr<<"打开输入文件失败!";return;}intk;for(inti=0;i<M;i++)for(intj=0;j<N;j++){infile>>k;m.setElement(i,j,k);}}intMatrix::max_value()const{//********333********//********666********}intmain(){Matrixm;readFromFile("",m);m.show("Matrix:");cout<<endl<<"最大元素:"<<m.max_value()<<endl;writeToFile("",m);return0;}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,咀该程序运行时有错,请改正程序中的错误,使程序输出的结果为:
Numbe=8
注意:错误的语句在∥********error********的下面,修改该语句即可。
#include
class CMyClass
{
public:
∥********error********
void&Get()
{
return&Number;
}
void Set(int m)
{
Number=m;
}
void display()
{
cout<<"Number=”<
问答题使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明代码。函数num(char *str)用于返回字符串中非数字的个数。 例如:abc123abc45 返回值为:6 将函数num补充完整。 注意:请勿改动主函数。 试题程序: #include<iostream.h> int num(char *str) int main() char str[1024]; cout<<"please input a string:"<<end1; cin.getline(str,1024); cout<<"char number is"<<num(str)<<end1; return 0;
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(int i),实现以下功能:当i等于5时,则打印如下内容。
#
##
###
####
#####
注意:不能修改程序的其他部分,只能修改fun()函数。
#include
void fun(int n)
{
}
void main()
{
int n;
cout>n
if(n<1)
{
cout<<”输入的行数必须大于
0”<
问答题请使用VC6或使用[答题]菜单打开proj1下的工程
proj1。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
Name: Smith Age: 21 ID: 99999 CourseNum: 12
Record: 970
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespaee std;
class StudentInfo
{
protected:
//ERROR **********found**********
char Name;
int Age;
int ID;
int CourseNum;
float Record;
public:
StudentInfo(char*name, int Age, int ID, int courseNum, float record);
//ERROR **********found**********
void ~StudentInfo() {}
float AverageRecord() {
return Record/CourseNum;
}
void show()const {
cout<<"Name:"<<Name<<"Age:"<<Age<<"ID:"<<ID
<<"CourseNum:"<<CourseNum<<"Record:"<<Record<<endl;
};
//ERROR **********found**********
StudentInfo StudentInfo(char*Name, int Age, int ID, int CourseNum, float Record)
{
Name=name;
Age=age;
this->ID=ID:
CourseNum=courseNum;
Record=record;
}
int main()
{
StudentInfo st("Smith", 21,99999, 12,970);
st. show();
return 0;
}
问答题使用VC++6.0打开
下的源程序文件3.cpp。其中定义的类不完整,按要求完成下列操作,将类的定义补充完整。
(1)在类TC中定义name为字符串类型,age为int型,请在注释1之后添加语句。
(2)设置类TC0的基类为TC类的定义,请在注释2后添加语句。
(3)在类TC的派生类TC0的公有成员中定义析构函数TC0,请在注释3后添加语句。
(4)设置类TC1的基类为 TC类的定义,请在注释4后添加语句。
程序输出结果为:
TC class constructor
TC0 class constructor
TC on class constructor
TC1 class constructor
TC1class constructor
TC class constructor
TC0 class constructor
TC class constructor
注意:增加或者修改代码的位置已经用符号表示出来,请不要修改其他的程序代码。
试题程序:
#include<iostream.h>
class TC
{
//********1********
public:
TC() {cout << "TC class constructor" <<endl;}
~TC() {cout << "TC class constructor" << endl;}
};
//********2********
{
char *departmert;
int level;
public:
TC0()
{cout << "TC0 class constructor" << endl;}
//********3********
{cout << "TC0 class constructor" << endl;}
};
//********4********
{
char *major;
float salary;
public:
TC1() {cout << "TC1 class constructor" <<endl;}
~TC1() {cout << "TC1 class constructor" << endl;}
};
void main()
{
TC0 s1;
TC1 t1;
}
问答题使用VC6打开下的源程序文件modi2.cpp。完成函数fire(char*s,inta[]),其功能是把s中出现的数字转换成数字存储在a[]中,然后返回转换的个数。例如:s="1234abcdef567";则:a[]中存储着1234567返回:7注意:不能修改程序的其他部分,只能修改fun()函数。#include<iostream.h>intfun(char*s,inta[]){}intmain(){inta[1024];intlen=fun("1234abcdef567",a);for(inti=0;i<len;i++){couta[i]"";}coutendl;coutiendl;return0;}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示坐标的类TestClassl,但类TestClassl的定义并不完整,按要求完成下列操作,将类的定义补充完整。
(1)声明TestClass2类为TestClassl类的友元类,请在注释∥********1********后添加适当的语句。
(2)完成类的构造函数,分别对成员变量赋值,请在注释∥********2********后添加适当的语句。
(3)完成类的构造函数,分别对成员变量赋值,请在注释∥********3********后添加适当的语句。
(4)完成计算平面上两点之间的距离函数Distance,计算的方法如下:X坐标之差的平方与Y坐标之差的平方之和的开方。请在注释∥********4********后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
#include
#include
using namespace std;
C1ass TestClassl
{
∥********1********
public:
∥********2********
{
X=a;
Y=b:
}
∥********3********
{
X=a ;
Y=0 ;
}
void print()
{
cout<<“x=”<
