- 首頁(yè)|
- 網(wǎng)校|
- 焚題庫(kù)|
- APP |
- 微信公眾號(hào)
五、程序分析題(本大題共2小題,每小題5分,共10分)
51.給出下面程序的輸出結(jié)果
#include <iostream>
using namespace std;
class base
{
int x;
public:
void setx( int a){x=a;}
int getx ( ){return x;}
} ;
void main ( )
{
int*p;
base a;
a.setx (15);
p= new int (a. getx( ));
cout < < * p;
}
52.給出下面程序的輸出結(jié)果
#include < iostream >
using namespace std;
class base
{
private:
int x;
public:
void setx (int a){x=a;}
int getx ( ){return x;}
} ;
void main ( )
{
base a,b;
a.setx (89);
b =a;
cout < < a.getx ( ) < < endl;
cout < < b.getx ( ) < < endl;
}
六、程序設(shè)計(jì)題(本大題共10分)
53.在字符串類string中實(shí)現(xiàn)一個(gè)判斷函數(shù),該函數(shù)功能是統(tǒng)計(jì)某一字符串類對(duì)象(僅有單詞和空格組成)有多少個(gè)單詞,同時(shí)保存所有單詞在字符串中的起始地址(設(shè)該字符串不超過(guò)100個(gè)單詞)
#include < iostream. h >
#include < string >
class str{
string s; int n,a [ 100 ],j ,1;
public:str ( string&a){s=a;n=0;j=0;l=0;}
....test (....);
int * geta ( ){ return a;}
} ;
請(qǐng)寫(xiě)出test函數(shù)的過(guò)程(如果需要形式參數(shù),請(qǐng)給出形參類型和數(shù)量,以及返回值類型)