跪求编程高手帮忙编一道c++的题目,感激不尽
通过指针处理下面的问题:利用随机函数模拟产生300个1~12月出生的人数(要求应用C++语言指针的知识)谢谢,感激不尽...
通过指针处理下面的问题:利用随机函数模拟产生300个1~12月出生的人数(要求应用C++语言指针的知识) 谢谢,感激不尽
展开
2个回答
展开全部
#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;
}
#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;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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)
};
希望对你有帮助
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)
};
希望对你有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |