问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是: 两个数据表: 1,2,3,4,5,6 3,4,5,6,7,8 两个数据表之和: 4,6,8,10,12,14 要求: 补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为0bj文件,并且在本程序中调用。 //DataList,h #include<iostream> using namespace std; class DataList{//数据表类 int fen; double*d;public: DataList(int len,double data[]=NULL); DataList(DataList return 0; }
问答题请使用VC6或使用【答题】菜单打开
proj3下的工程prog3,其中声明了ValArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写ValArray类的复制构造函数。在main函数中给出了一组测试数据,此种情况下程序的输出应该是:
ValArray v1={1,2,3,4,5}
ValArray v2={2,2,2,2,2}
要求:
补充编制的内容写在“// *******333*******”与“// *******666*******”之间。不要修改程序的其他部分。
注意:
相关文件包括:main.cpp、ValArray.h。
程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。
//ValArray.h
#include <iostream>
using namespace std;
class ValArray{
int * v;
int size;
public:
ValArray (const int * p, int n) : size(n)
{
v = new int[size];
for (int i = 0; i < size; i ++)
v[i] = p[i];
}
ValArray (const ValArray
~ValArray() {delete[] v;}
void setElement(int i, int val)
{
v[i] = val;
}
void print(ostream
for (int i = 0; i < size - 1; i ++)
out << v[i] << ",";
out << v[size-1] << "}";
}
};
void writeToFile(const char *);
//main.cpp
#include "ValArray.h"
ValArray:: ValArray (const ValArray
ValArray v1(a, 5);
ValArray v2(v1);
for (int i=0; i<5; i++)
v2.setElement(i,2);
cout << "ValArray v1 = ";
v1.print(cout);
cout << endl;
cout << "ValArray v2 = ";
v2.print(cout);
cout << endl;
writeToFile("");
return 0;
}
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程prog3,其中声明的MyString类是一个用于表示字符串的类。成员函数endsWith的功能是判断此字符串是否以指定的后缀结束,其参数s用于指定后缀字符串。如果参数S表示的字符串是MyString对象表示的字符串的后缀,则返回true;否则返回false。注意,如果参数s是空字符串或等于MyString对象表示的字符串,则结果为true。
例如,字符串“cde”是字符串“abcde”的后缀,而字符串“bde”不是字符串“abcde”的后缀。请编写成员函数endsWith。在main函数中给出了一组测试数据,此种情况下程序的输出应为:
s1=abcde
s2=cde
s3=bde
s4=
s5=abcde
s6=abcdef
s1 endsWith s2:true
s1 endsWith s3:false
s1 endsWith s4:true
s1 endsWith s5:true
s1 endsWith s6:false
要求:
补充编制的内容写在“//********333********”与“//********666********”之间。不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中,输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//Mystring.h
#include <iostream>
#include <string.h>
using namespace std;
class MyString {
public:
MyString(const char* s)
{
size = strlen(s);
str = new char[size + 1];
strcpy(str, s);
}
~MyString() { delete [] str;}
bool endsWith(const char* s) const;
private:
char* str;
int size;
};
void writeToFile(const char * );
//main.cpp
#include "MyString.h"
bool MyString::endsWith (const char* s) const
{
//******** 333********
//******** 666********
}
int main ()
{
char s1[] = "abcde";
char s2[] = "cde";
char s3[] = "bde";
char s4[] = "" ;
char s5[] = "abcde";
char s6[] = "abcdef";
MyString str (s1);
cout << "s1 = " << s1 << endl
<< "s2 = " << s2 << endl
<< "s3 = " << s3 << endl
<< "s4 = " << s4 << endl
<< "s5 = " << s5 << endl
<< "s6 = " << s6 << endl;
cout << boolalpha
<< "s1 endsWith s2 :" << str.endsWith(s2) << endl
<< "s1 endsWith s3 :" << str.endsWith(s3) << endl
<< "s1 endsWith s4 :" << str.endsWith(s4) << endl
<< "s1 endsWith s5 :" << str.endsWith(sS) << endl
<< "s1 endsWith s6 :" << str.endsWith(s6) << endl;
writeToFile ("");
return 0;
}
问答题试题源程序文件清单如下:#include<iostream>#include<iornanip>usingnamespacestd;classMiniString{public:friendostreamreturnoutput;}friendistream//用于输入的临时数组temp[0]='/0';//初始为空字符串input>>setw(100)>>temp;intinten=strlen(temp);//输入字符串长度if(inten!=0){s.length=inten;//赋长度if(s.sPtr!=0)delete[]s.sPtr;//避免内存泄露s.sPtr=newchar[s.length+1];strcpy(s.sPtr,temp);//如果s不是空指针,则复制内容}elses.sPtr[0]='/0';//如果s是空指针,则为空字符串returninput;}//*************333***********//*************666***********private:intlength;//字符串长度(不超过100个字符)char*sPtr;//指向字符串的起始地址};//proj3.cpp#include<iostream>#include<iomanip>usingnamespacestd;#include"proj3.h"intmain(){voidwriteToFile(char*);MiniStringstrl("Happy");cout<<strl<<"/n";writeToFile("K://K01//61010002/");return0:}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:
Hello
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构, 错误的语句在
∥********error********的下面。
{}include
void main()
f
∥********error********
typedef BOOL bool;
∥********error********
BOOL a=FALSE;
int i=0X80000000;
∥********error********
a=!i;
if(a)
{
cout<<“Hello”<
问答题使用VC6打开考生文件夹下的工程test32_3。此工程包含一个test32_3.cpp,其中定义了复数类complex,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。
(1)定义复数类complex的私有数据成员real和image,用来分别表示复数的实部和虚部,它们都是double型的数据。请在注释“//**1**”之后添加适当的语句。
(2)添加复数类complex的带一个参数的构造函数,分别将real和image赋值为参数r的值和0.0,请在注释“//**2**”之后添加适当的语句。
(3)完成复数类complex的“+”运算符重载成员函数的定义,两个复数相加是将复数的实部和虚部分别进行相加,请在注释“//**3**”之后添加适当的语句。
(4)完成复数类complex的友元函数isequal(complex *cl,complex *c2)的定义,如果复数c1与c2相等即c1与c2的实部和虚部分别相等,则返回1,否则返回0。请在注释“//**4**”之后添加适当的语句。
程序输出结果如下:
36+0i=36+0i
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test32_3.cpp清单如下:
#include <iostream.h>
class complex
{
//** 1 **
public:
complex(){real=image=O.O;}
complex(double r)
{
//** 2 **
}
complex operator+(const complex
friend bool isequal(complex *c1,complex *c2
void display();
};
complex complex::operator+(const complex
temp.image=image+c.image;
return temp;
}
bool isequal(complex *c1,complex *c2)
{
/ /** 4 **
return 1;
else
return 0;
}
void complex:: display()
{
cout<<real;
if (image>=0) cout<<"+"<<image<<"i";
else if (image<0) cout<<image<<"i";
}
void main()
{
complex c1,c2(36.0);
c1=c1+c2;
c1.display();
if (isequal(
else coat<<"<>";
c2.display();
cout<<end1;
}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(char*str,char ch),本函数采用二分法,在已按字母次序从小到大排序的字符数组str中,查找字符ch,若ch在数组中,函数返回字符ch在数组中的下标,否则返回-1。 二分法查找的思想是:初始查找区间的下界为0,上界为len-1,查找区间的中后,k=(下界+上界)/2:若list[k]等于ch,查找成功;若list[k]>ch,则新的查找区间的下界不变,上界改为k-1;否则新的查找区间的下界改为k+1,上界不变。在新区间内继续用二分法查找。 注意:请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。#include<iostream.h>int fun(char*str,char ch){}void main(){ char str[]={'a','b','c','d','e','f','g','h','i','j','k',0}; char ch; cout<<"请输入一个字符:"<<endl; cin>>ch; cout<<"输入数字的位置是:"<<fun(str,ch)<<endl; return;}
问答题使用VC6打开考生文件夹pmjI下的工程pmjI,其中定义了一个CD类。程序中位于每个//ERROR************found**********下的语句行有错误,请加以更正,不得修改程序的其他部分。更正后程序的输出应该是: 歌唱祖国30 义勇军进行曲95 注意:只能修改每个//ERROR**********found***********下的那一行,不要改动程序中的其他内容。#include<iostream>#include<CString>usinq namespace std;clasS CD{ char name[20], int number;public: void init(char*aa,int bb) { //ERROR*****found***** name=aa; number=bb; } char*getName(){ //ERROR*****found***** return*name; } int getNumber(){return number;) void output(){ //ERROR*****found***** cout<<name[20] <<’’<<num—ber<<endl; } }; void main() { CD dx,dy; dx.init(”歌唱祖国”,30); dy.init(”义勇军进行曲”,3*dx.getNumber()+5); dx.output(); dy.output(); }
问答题使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示雇员的Employee类,但类Em-ployee的定义并不完整。请按要求完成下列操作,将类TC的定义补充完整。
(1)定义私有数据成员name、street、city、zipcode和age分别用于表示姓名、街道、城市、邮编、年龄,除年龄是整型外,其余都是char型的数据。请在注释1之后添加适当的语句。
(2)完成默认构造函数TC的定义,使其把参数传递给私有数据成员name、streel、city、zipcode和age。请在注释2之后添加适当的语句。
(3)完成成员函数aherName(char*newName)的定义。请在注释3之后添加适当的语句。
(4)完成成员函数IsEqual(char*ename)的定义,实现当name相等时返回真,否则返回假的功能。请在注释4之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
试题程序:
#include
#include #defineMAXLEN20
classTC
{
private:
//********、********
intage;
public:
TC(char*newName,char*newStreet,char*
newCt,char*newZp,intnewAge);
voidalterName(char*newName);
voiddisplay();
boolIsEqual(char*ename);
};
TC::TC(char*newName,char*newStreet,char*
newCt,char*newZp,intnewAge)
{
//********2********
age=newAge;
}
voidTC::alterName(char*newName)
{
//********3********
}
boolTC::IsEqual(char*ename)
{
//********4********
}
voidTC::display()
{
cout< cout< }
voidmain(void)
{
TCemployee[4]=
{
TC("张三","海淀区复兴路l号","北京","000001",18),
TC("李四","海淀区复兴路2号","北京","000002",19),
TC("王五","海淀区复兴路3号","北京","000003",20),
TC("赵六","海淀区复兴路4号","北京","000004",21)
};
for(inti=0;i<4;i++)
employee[i].display();
cout<<"\n修改\"李四\"的名字为\"李小四\"\n"< for(intj=0;j<4;j++)
{
if(employee[j].IsEqual("李四"))
{
employee[j].aherName("李小四");
employee[j].display();
break;
}
}
}
问答题使用VC6打开
proj3下的工程proj3,其中声明了MyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abcde”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数据,此情况下程序的输出应该是:
This is a string
gnirts a si sihT
注意:只需在函数reverse的//********333****和//****666****之间填入若干语句,不要改动程序中的其他内容。
//MyString.h
#include<iostream>
using namespace std;
char*dup(const char*);
class MyString{
char*str;
public:
MyString(const char*s=" "):str(dup(s)){}
MyString(const MyString)
void reverse();
void show(ostream}
};
inline ostream
return os;
}
void writeToFile(const char*path);
//MyString.cpp
#include"MyString.h"
char*dup(const char*s){
char*p=new char[strlen(s)+1];
strcpy(p,s);
return p;
}
void MyString::reverse(){
//********333********
//********666********
}
void writeToFile(const char*path);
//writetoFile.cpp
#include<fstream>
#include"MyString.h"
void writeToFile(const char*path){
char full[50];
strcpy(full,path);
strcat(full,"out.dat");
ofstream outfile(full);
if(outfile.fail()){cerr<<"打开输出文件失败!";return;)
MyString m1="This is another string";
MyString m2("字符串反转演示");
outfile<<m1<<m2;
m1.reverse();
m2.reverse();
outfile<<m1<<m2;
outfile.close();
}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示人基本信息的类CHumanlnfo,但类CHumanln的定义并不完整。请按要求完成下列操作,将类CHumanInfo的定义补充完成:
(1)定义私有数据成员bloodType用于表示血型, 血型为char型的数据。请在注释“∥********1********之后添加适当的语句。
(2)完成构造函数的定义,要求具有缺省值,缺省值为身高175,体重70,血型A。请在注释“∥********2********之后添加适当的语句。
(3)完成类外CHumanlnfo成员函数Setlnfo的定义。请在注释“∥********3********”之后添加适当的语句。
(4)在主函数中调用成员函数SetInfo,把对象d2的三个私有数据成员分别设定为身高170,体重64,血型为B。请在注释“∥********4********,,之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include
Class CHumanInfo
{
private:
int height;
int weight;
∥********1********
public:
∥********2********
:height(ht),weight(wt),
bloodType(bt){};
CHumanlnfo(CHumanInfo&hi):
height(h1.height),
weight(h1.weight),
bloodType(h1.bloodType){);
int GetHeight()
{
return height;
}
int GetWeight()
{
return welght;
}
int GetBloodType()
{
return bloodType;
}
void SetInfo(int ht,int
wt,char bt);
void Di splay();
};
∥********3********
{
height=ht;
weight=wt;
bloodType=bt;
}
void CHumanInfo::Display()
{
cout<<“HumanInfo:”;
cout<
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中声明IntSet是一个用于表示正整数集合的类。IntSet的成员函数Intersection的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在main函数中给出了一组测试数据,此时程序的输出应该是:
求交集前:
1 2 3 5 8 10
2 8 9 11 30 56 67
求交集后:
1 2 3 5 8 10
2 8 9 11 30 56 67
2 8
要求:
补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//Intset.h
#include <iostream>
using namespace std;
const int Max=100;
class IntSet
{
public:
IntSet()
//构造一个空集合
{
end=-1;
}
IntSet(int a[], int size) //构造一个包含数组a中size个元素的集合
{
if (size>=Max)
end =Max-1;
else
end=size-1;
for(int i=0; i<=end; i++)
element[i]=a[i];
}
bool IsMemberOf (int a)
//判断a是否为集合中一个元素
{
for(int i=0; i<=end; i ++)
if(element[i]==a)
return true;
return false;
}
int GetEnd() {return end; }
int GetElement (int i) {return element[i]; }
//返回下标为i的元素
IntSet Intersection(IntSet
//求当前集合与集合set的交
void Print ()
//输出集合中的所有元素
{
for(int i=0; i<=end; i++)
if((i +1)% 20==0)
cout<<element[i]<<endl;
else
cout<<element[i]<<'';
cout<<endl;
}
private:
int element[Max];
int end;
};
void writeToFile (const char *);
//main.cpp
#include "IntSet.h"
IntSet IntSet::Intersection(IntSet
//********333********
//********666********
return IntSet (a, size);
}
int main ()
{
int a[]={1, 2, 3, 5, 8, 10};
int b[]={2, 8, 9, 11, 30, 56, 67};
IntSet set1 (a,6), set2 (b,7), set3;
cout <<"求交集前:"<<endl;
set1. Print ();
set2. Print ();
set3. Print ();
set3 = set1. Intersection (set2);
cout<<endl<<"求交集后:"<<endl;
set1. Print ();
set2. Print ();
set3. Print ();
writeToFile ("");
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)利用define定义常量TRUE为1,定义常量FALSE为0,请在注释//********1********后添加适当的语句。 (2)在类A2前增加A1的声明,请在注释//********2********后添加适当的语句。 (3)在类C1中声明友元函数bool func(A2& a,A1&b),请在注释//********3********后添加适当的语句。 (4)实现函数bool time(A2&obj1,Alaobj2)功能,检查两个类的值都为TRUE,则返回TRUE,请在注释//********4********后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#include<iostream.h>//********1******** #define FALSE 0//********2********Class A2{private: bool m A2; friend bool func(A2&obj1,A1&obj2);public: A2() { m A2=FALSE; }public: Void SetA2(bool n) { m A2=n; } }; Class A1 { private: ool m A1; //********3*********public: A1() { m A1=TRUE; }public: Void setAl(bool n) { m A1=n; } }; bool func(A2& obj1,A1& obj2) { //********4******** return } int main() { A2 obj0; A1 obj1; cout<<func(obj 0,obj1)<<endl; obj0.setA2(TRUE); obj1.setA1(TRUE); cout<<func(obj0,obj1)<<endl; return 0;}
问答题使用VC6打开考生文件夹下的工程RevProj4。此工程包含一个源程序文件RevMain4.cpp,但该程序运行有问题。请改正主函数中的错误,使之输出结果为: x=20 源程序文件RevMain4.cpp的清单如下: //RevMain4.cpp #include<iostream> using namespace std; class MyClass public: MyClass(int a) x=a; void setX(int a) x=a; void print() cout<<"x="<<x; private: int x; ; int main() const MyClass obj (10); / ************found**************/ obj.setX(20); / ************found**************/ obj.print(); return 0;
问答题使用VC6打开考生文件夹下的源程序文件modi1.clap,该程序运行时有错误,请改正错误,使得程序输出: Hello test 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//******error******的下面。#include<iostream>//********error********template<T>void fun(T t){ std::cout<<''test''<<std::endl;}//********error********template<bool>void fun(bool t){ std::cout<<(t?''Hello'':''Hi'')<<std::endl;}int main(){ //********error******** bool flag=TRUE; fun(flag);fun((int)flag); return 0;}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)完成类MyArrayClass的构造函数,申请数组的大小,请在注释//********1********后添加适当的语句。 (2)完成类MyArrayClass的析构函数,释放数组,请在注释//********2********后添加适当的语句。 (3)完成重载运算符“[]”,用来获得指定下标的数据,请在注释//********3********后添加适当的语句。 (4)完成函数SetElement(),用来设置指定下标的数据。如果数据没有超出范围,则设置数据,并返回1,否则返回0,请在注释//********4********后添加适当的语句。注意:除在指定的位置添加语句外,并不要更改程序中的其他语句。#include<iostream.h>template<class T>class MyArrayClass{private: T* data; int length;public: MyArrayClass(int len) { length=fen; //********1******** } ~MyArrayClass() { //********2******** } T&operator[](int i) { //********3******** } bool SetElement(int i,T t) { //********4******** if() { data[i]=t; return true; } return false; }};int main(){ MyArrayClass<int>obj(5); obj[3]=1; cout<<obj.SetElement(5,2)<<end1; cout<<obj.SetElement(4,2)<<end1; return 0;}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。函数sum(int n)计算在n范围内,能被7和1l整除的所有整数的和(包括n在内)。
注意:不能修改程序的其他部分,只能补充sum()函数。
#include
double sum(int n)
{
}
void msin()
{
cout<
问答题请使用VC6或使用【答题】菜单打开
proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Door(“门”)和主函数main的定义。程序中位于每个“// ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
打开503号门...门是锁着的,打不开。
打开503号门的锁...锁开了。
打开503号门...门打开了。
打开503号门...门是开着的,无须再开门。
锁上503号门...先关门...门锁上了。
注意:只修改每个“//ERROR ********found********”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class Door{
int num; //门号
bool closed; //true表示门关着
bool locked; //true表示门锁着
public:
Door(int num){
// ERROR *******found*******
num = this -> num;
closed = locked = true;
}
bool isClosed() const {return closed;}
//门关着时返回true,否则返回false
bool isOpened() const {return! closed;}
//门开着时返回true,否则返回false
bool isLocked() const {return locked;}
//门锁着时返回true,否则返回false
bool isUnlocked() const {return! locked;}
//门未锁时返回true,否则返回false
void open() { //开门
cout << endl << "打开" << num << "号门...";
// ERROR *****found*****
if (closed)
cout << "门是开着的,无须再开门。";
else if(locked)
cout << "门是锁着的,打不开。";
else{
closed = false;
cout << "门打开了";
}
}
void close() { //关门
cout << endl << "关上" << num << "号门...";
if(closed)
cout << "门是关着的,无须再关门。";
else{
closed = true;
cout << "门关上了。";
}
}
// ERROR *******found*******
void lock() const { //锁门
cout << endl << "锁上" << num << "号门...";
if(locked)
cout << "门是锁着的,无须再锁门。";
else{
if(! closed) {
cout << "先关门...";
closed = true;
}
locked = true;
cout << "门锁上了。";
}
}
void unlock() { //开锁
cout << endl << "开" << num << "号门的锁...";
if(! locked)
cout << "门没有上锁,无须再开锁。";
else{
locked = false;
cout << "锁开了。";
}
}
};
int main() {
Door door(503);
door.open();
door.unlock();
door.open()
door.open();
door.lock();
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)定义复数类CComplex的私有成员变量real和imaginary,分别用来表示复数的实部和虚部,都是double类型的变量。请在注释//********1********后添加适当的语句。(2)添加复数类CComplex的带一个参数的构造函数,分别将real和imaginary赋值为参数r和0。请在注释//********2********后添加适当的语句。(3)完成对运算符“+”的重载,分别对复数的实部和虚部相加。请在注释//********3********后添加适当的语句。(4)完成复数的友元函数Equal(CComplex&c1,CComplex&c2)的定义,如果两个数的实部和虚部都相等,则返回1,否则返回0,请在注释//********4********后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#include<iostream.h>class CComplex{private://********1********publiC:CComplex(){real=imaginary=0;}CComplex(double r){//********2********}CComplex operator+(CComplex&c1){//********3********temp.real=real+c1.real;temp.imaginary=imaginary+c1.imaginary;return temp;}void Set(int re,int imag){real=re;imaginary=imag;}friend bool Equal(CComplex&c1,CComplex&c2);};bool Equal(CComplex&c1,CComplex&c2){//********4********}int main(){CComplex complex1(5);CCompiex complex2;cout<<Equal(complex1,complex2)<<endl;complex2.Set(5,0);cout<<Equal(complex1,complex2)<<endl;return0;}
问答题使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(int n)的功能是在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个,并作为参数返回。
注意:不能修改程序的其他部分,只能修改fun函数。
试题程序:
#include<iostream.h>
#define N 100
int a[N][N];
int fun(int n)
{
}
void main()
{
int n;
cout<<"please input N:"<<end1;
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
cout<<"please input a Number:"<<end1;
cin>>a[i][j];
}
cout<<"The min of max numbers is"<<fun(n)<<end1;
}