请各位老师帮忙了

leebb4444 2007-05-11 09:02:18
第一题:定义一个Document类,包含成员变量name,从Document派生出Book类,增加PageCount变量。编写主函数测试这两个类
第二题:编写一个函数, 该函数返回给定字符串中大写字母字符的个数。例如:字符串“Chinese Computer World”中,大写字母字符的个数是3个。写出主函数,设计几个字符串,测试函数输出结果是否正确。函数首部参数要求用指向字符的指针,比如 int Fun(char *str)
谢谢谢谢
...全文
248 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyingpig4945 2007-05-12
  • 打赏
  • 举报
回复
不知道楼主有什么具体要求没,下面是胡乱写的一个eg
#include <iostream>
#include <string>
using namespace std;

class Document
{
public:
void SetValue(string temp);
void GetValue(void);
private:
string name;
};

class Book: public Document
{
public:
int PageCount;
};

void Document::SetValue(string temp)
{
name = temp;
}

void Document::GetValue(void)
{
cout<<name<<endl;
}

int main(void)
{
Document myDocument;
myDocument.GetValue();
myDocument.SetValue("happy");
myDocument.GetValue();

Book myBook;
myBook.GetValue();
myBook.SetValue("mine");
myBook.GetValue();
myBook.PageCount = 5;
cout<<myBook.PageCount<<endl;

system("pause");
return 0;
}
jixingzhong 2007-05-12
  • 打赏
  • 举报
回复
恩, 楼上的基本可以了, 稍微再根据要求改改
minioreo 2007-05-11
  • 打赏
  • 举报
回复
看c++ primer先
bargio_susie 2007-05-11
  • 打赏
  • 举报
回复
1.不熟悉C++;
2.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int Fun(char *str)
{
char *p = str;
int count = 0;
while ( *p != '\0' )
{
if ( isupper(*p) )
{
count++;
p++;
}
else
p++;
}
return count;
}
int main()
{
int n;
char *str = "Chinese Computer World";
n = Fun(str);
printf("%s include %d upper characters\n", str, n);

system("pause");
return 0;
}
星羽 2007-05-11
  • 打赏
  • 举报
回复
呼唤 jixingzhong(瞌睡虫·星辰) 大哥

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧