63,594
社区成员




char* add(char* a, char* b)
{
return strcat(a,b);
}
#include <iostream>
#include <string.h>
using namespace std;
#define BUF_LEN 100
int add(int a, int b)
{
return a+b;
}
struct fraction
{
int son;
int mum;
};
void add(struct fraction *a,struct fraction *b)
{
a->son = (b->son * a->mum) + (a->son * b->mum);
a->mum *= b->mum;
}
void getLine(char* p_data) //读入字符串函数
{
char char_buf[BUF_LEN];
int len=1;
cout <<"Type a line,press enter to end:\n";
cin>>char_buf;
cout<<char_buf<<endl;
len += strlen(char_buf);
if(p_data == NULL)
{
cout <<"Not enough memory from the heap.\n";
return;
}
strcpy(p_data,char_buf);
}
void add(char *a,char *b) //连接字符串
{
strcat(a,b);
}
void main()
{
int a,b;
char p_string1[100],p_string2[100];
struct fraction struct1,struct2,*p_struct1,*p_struct2;
cout <<"input your integer numbers!\n";
cin>>a;
cin>>b;
cout <<add(a,b) <<endl;
p_struct1 = &struct1;
p_struct2 = &struct2;
cout <<"input two fractions!\n";
cin>>p_struct1->son;
cin>>p_struct1->mum;
cin>>p_struct2->son;
cin>>p_struct2->mum;
add(p_struct1,p_struct2);
cout <<"the sum of the fractions is " <<((float)p_struct1->son/p_struct1->mum) <<endl;
getLine(p_string1);
cout <<"p_string1: "<<p_string1 <<endl;
getLine(p_string2);
cout <<"P_string2: "<<p_string2 <<endl;
add(p_string1,p_string2);
cout <<p_string1 <<endl;
}
int add(int a,int b)
{
return a+b;
}
double add(int sa, int ma, int sb, int mb)
{
return (double)sa/(double)ma + (double)sb/(double)mb;
}
string add(string a, string b)
{
return a+b;
}
int main()
{
int ia,ib;
int sa, ma, sb, mb;
string a,b;
cout<<"输两整数"<<endl;
cin>>ia>>ib;
cout<<"整数和 = "<<add(ia,ib)<<endl;
cout<<"输两分数"<<endl;
cin>>sa>>ma>>sb>>mb;
cout<<"分数和 = "<<add(sa, ma, sb, mb)<<endl;
cout<<"输两字符串"<<endl;
cin>>a>>b;
cout<<"字符串和 = "<<add(a,b)<<endl;
system("pause");
return 0;
}
#include<iostream>
#include<string>
using namespace std;
int add(int a,int b)
{
return a+b;
}
string add(string s1,string s2)
{
s1+=s2;
return s1;
}
double add(double a,double b)
{
return a+b;
}
int main()
{
cout<<add(1,2)<<endl;
cout<< add("Hello","word")<<endl;
cout<<add(1.1,2.2)<<endl;
return 0;
}