电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

北邮小学期c++实验报告and程序文件

北邮小学期c++实验报告and程序文件_第1页
1/25
北邮小学期c++实验报告and程序文件_第2页
2/25
北邮小学期c++实验报告and程序文件_第3页
3/25
C++实验课总结 张涛 实验一:简单c++程序设计 一、 1、 猜价格游戏 编写 C++程序完成以下功能: (1) 假定有一件商品,程序用随机数指定该商品的价格(1-1000 的整数); (2) 提示用户猜价格,并输入:若用户猜的价格比商品价格高或低,对用户作出相应的提示; (3) 直到猜对为止,并给出提示。 #include #include using namespace std;//使用命名空间 std. int main() { srand(time(NULL));//将时钟数作为随机数种子 int price,guess; price = rand() % 1000 + 1;//取余,获得 1~1000 的随机数 cout << "please input the price:" << endl; do{ cin >> guess;//记录玩家所输入数值 if(guess > price) cout << "The price is lower than your guess,please input the price again:" << endl; if(guess < price) cout << "The price is higher than your guess,please input the price again:" << endl;//给予玩家比较大小的提示 } while (guess != price);//循环结构 cout << "The price you give is right.It cost " << price << "." < #include #include//两种输入流 using namespace std; int isprime(int a) {int b = 2; while(a % b!=0 && b < sqrt(a)) {b++; } if(a % b==0) return 0; if(a % b!=0) return 1; }//判断是否为素数的函数定义 int main() { int num,a; ofstream myFile("d:\\result.txt"); cout << "Please input the number:" << endl; cin >> num ; myFile << "2 "; for(a = 2;a <= num;a++)//例举所有数,并对其进行判断,是否为素数 {if(isprime(a)==1) myFile << a <<" "; }//向文件内输出数据 system("pause"); return 0; } 3、 袋中取球 编写C++程序完成以下功能(使用 enum): (1) 袋子中有 red, yellow, blue, white, black 五种颜色的球多个; (2) 一次从袋子里取出3 个颜色不同的球,有几种取法; (3) 将每种方法...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

北邮小学期c++实验报告and程序文件

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部