
Think in c++ 课后习题
子墨777
Try to make yourself more excellent!
展开
-
3-2编程求解质数
#include using namespace std; int main(){ int n;int c=0; while (cin>>n){ cout<<1<<endl; cout<<2<<endl; for (int j=2;j<=n;j++){ for(int i=2;i<j ;i++){ c=j%i; if(c!=0){ cout<<j<<endl;原创 2016-10-16 22:56:35 · 391 阅读 · 0 评论 -
3.4修改menu.cpp
#include using namespace std; int main(){ char c,d; cin>>c; switch (c){ case 'l':{ cout<<"You choose Left:"<<endl; cin>>d; switch(d){ case 'd':cout <<"You choose d!!!"<<en原创 2016-10-17 09:40:01 · 264 阅读 · 0 评论 -
结构体的简单使用
#include using namespace std; typedef struct{ char c; int i; float f; double d; }str; int main(){ str str1, str2; str *p=&str2; str1.c='chy'; str1.d=10.0; str1. f =12; str1.i=9; p原创 2016-10-18 10:30:26 · 347 阅读 · 0 评论 -
枚举类型的应用
口袋中有红、黄、蓝、白、黑5种颜色的球若干。每次从口袋中任意取出3个球,问得到3中不同颜色的球的可能取法,输出每种排列的情况。 分析:球的颜色只有5种,每一个球的颜色只能是这5种之一,因此可以用枚举类型变量来处理。#include using namespace std; int main (){ enum {red=1,yellow,blue, white ,black};原创 2016-10-18 11:54:53 · 633 阅读 · 0 评论 -
类参数初始化列表
#include using namespace std ; class B1 { public: B1(int ii=0); void print(){cout<<i<<endl;} ~B1(); private: int i; }; B1::B1(int ii):i(ii){}; B1::~B1() { } int main(){ B1 a(1),b(2原创 2016-12-29 20:19:22 · 1402 阅读 · 0 评论 -
const 的一些用法
#include "stdafx.h" #include "iostream" using namespace std; class test{ public : test(int x): x1(x) {}//参数初始化列表 void testConstFunction(int x)const{ //在const 成员函数中不能修改任何函数值 //x1=x; //错原创 2016-12-29 19:50:01 · 337 阅读 · 0 评论