问答题

请编写一个函数fun(),该函数的功能是:返回给定字符串中大写字母字符的个数。 如字符串"Hello World"中,大写字母的个数为2个。 注意:部分源程序已存在文件PROC5.CPP中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。 文件PROC5.cpp的内容如下: //PROC5.cpp #include<iostream> #include<string> using namespace std; int fun(char *str); int main() { char str[ ]="Chinese Computer World"; cout<<fun(str)<<end; return 0; } int fun(char *str) { //********** }

【参考答案】

下面是函数fun()函数体的一种实现: int fun(char *str) { int num=0; //用于......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
使用VC6打开考生文件夹下的工程MyProj5。此工程包含一个源程序文件 MyMain5.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整。请按要求完成下列操作,将类Date的定义补充完成:①定义私有数据成员length、width和labe1,其中length、width是int型,labe1是类point的对象。它们分别表示长方形的长、宽以及坐标点。请在注释“ **1**”之后添加适当的语句。②完成构造函数square的定义,使square对象的默认值为:length=0,width=0, label(0,0),请在注释“ **2**”之后添加适当的语句。③完成重载构造函数square(int l,int w,int x,int y)的定义,把数据成员length、width和对象labe1分别初始化为参数l、w、x和y的值,请在注释“ **3**”之后添加适当的语句。④完成成员函数get_area()的类外定义,此函数的功能是返回此长方形的面积,及返回length*width的值。请在注释“ **4**”之后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件MyMain5.cpp清单如下: MyMain5.cpp#include<iostream>using namespace std;class point{private:int x,y;public:void set (int i,int j){x=i;y=j;}int get_y (){return y;}};class square{ * * 1 * *public: * * 2 * *square(int l,int w, int x, int y){ * * 3 * *}void set(int l,int w){length=1;width=w;}int get_area() const{return length*width;}};int square::get_area() const{ * * 4 * *}int main(){square small(2,4,1,35);cout<<small.get_area()<<end1;return 0;}