跪求编程高手帮忙编一道c++的题目,感激不尽

通过指针处理下面的问题:利用随机函数模拟产生300个1~12月出生的人数(要求应用C++语言指针的知识) 谢谢,感激不尽

第1个回答  推荐于2018-03-29
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[]) {
int n;
printf("输入人数:\n");
scanf("%d", &n);
int* p = new int[n];
//下面的语句能使每次得到的结果不相同
// srand( (unsigned)time( NULL ) ); //用系统时间当种子,对随机函数进行初始化
for (int i = 0; i < n; ++i) {
*(p + i) = rand() % 12 + 1;
}
for (int i = 0; i < n; ++i) {
printf("%d ", *(p + i));
if (i % 10 == 9)
printf("\n");
}
return 0;
}本回答被提问者和网友采纳
第2个回答  2010-11-25
class Money {
private:
double money;
public:
Money(double dollars = 0):money(floor(dollars*100.f+0.5)/100.f){};
Money(int dollars, float cents):money(floor((dollars+cents/100)*100.f+0.5)/100.f){};

double getMoney()
bool operator==(Money& m)
bool operator!=(Money& m)
bool operator<(Money& m)
bool operator<=(Money& m)
bool operator>(Money& m)
bool operator>=(Money& m)
void operator+=(Money& m)
void operator-=(Money& m)
Money operator+(Money& m)
Money operator-(Money& m)
Money operator*(double d)
friend Money operator*(double d, Money& m)
Money operator/(double d)
friend ostream& operator<<(ostream& ostr, const Money& m)
};
希望对你有帮助
相似回答