友元函数的使用

来源:互联网 发布:矩阵初等变换 编辑:程序博客网 时间:2024/04/28 16:15

</pre><pre code_snippet_id="370939" snippet_file_name="blog_20140530_3_7022893" name="code" class="cpp">
#include<iostream>#include<cstring>using namespace std;class change{char a[1005];public:change(char b[]){          strcpy(a,b);}friend void changes(change &p);    friend ostream&operator<<(ostream&out,change p);};ostream&operator<<(ostream&out,change p){out<<p.a;return out;}void changes(change &p)//这里必须为引用{int i;for(i=0;i<strlen(p.a);i++){if(p.a[i]>=97&&p.a[i]<=122){p.a[i]=p.a[i]-32;}}}int main(){char b[1005];cin.getline(b,1005);change t(b);changes(t);cout<<t<<endl;}


2113: 将字符串转换成大写

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 134  Solved: 64
[Submit][Status][Web Board]

Description

定义一个字母转换类,实现将输入的一串字符中的小写字符转换成大写,转换函数使用友元机制实现。

Input

一串字符,可以包含空格、特殊字符、数字

Output

这串字符的小写

KeyWord(s) that Must be Used

friend

Sample Input

I Love You!

Sample Output

I LOVE YOU!

0 0
原创粉丝点击