[CODE]
/*
//第一题:
#include <iostream>
using namespace std;
int main()
{
bool StringCheck(char S[]);
char strArray[20] = "";
bool myBool = false;
printf("请输入不超过20的字符串:\n");
gets(strArray);
myBool = StringCheck(strArray);
if(myBool == true)
{
cout << "'(' == ')'" << endl;
}
else
{
cout << "'(' != ')'" << endl;
}
return 0;
}
bool StringCheck(char S[])
{
int count1 = 0;
int count2 = 0;
int INum = -1;
//为了计算字符数组的长度!
for(int i = 0; ; i++)
{
INum++;
if(S[i] == 0)
{
break;
}
}
for(i = 0; i < INum; i++)
{
if(S[i] == '(')
{
count1++;
}
else if(S[i] == ')')
{
count2++;
}
}
cout << count1 << endl << count2 << endl;
if(count1 == count2)
{
return true;
}
else
{
return false;
}
}
//第二题:
#include <iostream>
using namespace std;
int main()
{
float AverOdd(int d[], int n);
int d[10] = {0};
float avg = 0.0;
printf("请输入数组的元素:\n");
for(int i = 0; i < 10; i++)
{
scanf("%d",&d[i]);
}
avg = AverOdd(d,10);
printf("avg = %f\n",avg);
return 0;
}
float AverOdd(int d[], int n)
{
int sum = 0;
float avg = 0;
int count = 0;
for(int i = 0; i < n; i++)
{
if(d[i] % 2 != 0)
{
sum += d[i];
count++;
}
}
avg = sum/count;
return avg;
}
//第三题:
#include <iostream>
using namespace std;
class Person
{
public:
Person(string _name, int _age, int _tel);
~Person();
void ModifyAge();
void ModifyTel();
private:
string name;
int age;
int tel;
};
int main()
{
Person zs("张三",35,62458686);
Person ls("李四",32,58729877);
zs.ModifyAge();
ls.ModifyTel();
return 0;
}
Person::Person(string _name, int _age, int _tel)
{
name = _name;
age = _age;
tel = _tel;
}
Person::~Person()
{
}
void Person::ModifyTel()
{
tel = 63580246;
cout << tel << endl;
}
void Person::ModifyAge()
{
age += 1;
cout << age << endl;
}
//第四题:
#include <iostream>
using namespace std;
class CIRCLE
{
public :
CIRCLE()
{
x = 0;
y = 0;
r = 50;
}
CIRCLE(CIRCLE &)
{
}
void SetPosition(float NewX,float NewY);
void SetRadius(float NewR);
float GetRadius();
private:
float x;
float y;
float r;
};
int main()
{
return 0;
}
void CIRCLE::SetPosition(float NewX, float NewY)
{
x = NewX;
y = NewY;
}
void CIRCLE::SetRadius(float NewR)
{
r = NewR;
}
float CIRCLE::GetRadius()
{
return r;
}
*/
[/CODE]