码迷,mamicode.com
首页 > 编程语言 > 详细

最近看了点C++,分享一下我的进度吧!

时间:2014-07-10 13:22:54      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

bubuko.com,布布扣
  1 #include <iostream>
  2 #include <cmath>
  3 #include <iomanip>
  4 
  5 using namespace std;
  6 
  7 //Student类
  8 class Student
  9 {
 10     private://私有
 11         char name[10];
 12         int age;
 13         char address[50];
 14     public://公共方法
 15         void setStudent()
 16         {
 17             cout<<"请输入姓名:" <<endl;
 18             cin>>name;
 19             cout<<"请输入年龄:" <<endl;
 20             cin>>age;
 21             cout<<"请输入家庭住址:" <<endl;
 22             cin>>address;
 23         }
 24         void displayStudent()
 25         {
 26             cout<<"姓名:"<<name<<"年龄:"<<age<<"家庭住址:"<<address<<endl;
 27         }
 28 };
 29 //求三角形面积
 30 class San
 31 {
 32     private:
 33         float p;
 34     public:
 35         float displayArea(float a,float b,float c)
 36         {
 37             p=(a+b+c)/2;
 38             return sqrt(p*(p-a)*(p-b)*(p-c));;
 39         }
 40 };
 41 //主函数
 42 int main()
 43 {
 44     /*
 45     Student stu;
 46     stu.setStudent();
 47     stu.displayStudent();
 48 
 49     cout<<20%3<<endl;
 50 */
 51 
 52 //===========================================================================================================
 53 
 54 
 55     //一元二次方程
 56     /*
 57     float a,b,c,s1,s2;
 58     cin>>a>>b>>c;
 59     s1=(-b+ sqrt(b*b-4*a*c))/(2*a);
 60     s2=(-b- sqrt(b*b-4*a*c))/(2*a);
 61     cout<<s1<<"   "<<s2<<endl;
 62     */
 63     //求三角形面积
 64     /*
 65     San san;
 66     cout<<san.displayArea(3,4,5)<<endl;
 67     */
 68 
 69 //===========================================================================================================
 70 
 71 //π/4≈1-1/3+1/5-1/7+…直到最后一项的绝对值小于10-7为止。
 72     /*
 73     int s=1;
 74     double i=1,pi=0,t=1;
 75     while ((fabs(t))>(1e-7))
 76     {
 77         pi+=t;
 78         i+=2;
 79         s=-s;
 80         t=s/i;
 81     }
 82     pi*=4;
 83     cout<<setiosflags(ios::fixed)<<setprecision(6)<<pi<<endl;
 84 */
 85 
 86 //===========================================================================================================
 87 
 88 
 89     /*有一对兔子,从出生后第3个月起每个月都生一对兔子,
 90     小兔子长到第3个月后每个月又生一对兔子,
 91         假设所有兔子都不死,问每个月的兔子总数为多少*/
 92     /*
 93     long f1,f2;
 94     int i;
 95     f1=f2=1;
 96     for(i=1;i<=20;i++)
 97     {
 98         cout<<setw(12)<<f1<<":"<<setw(12)<<f2;
 99         //设备输出字段宽度为12,每次输出两个数
100         if(i%2==0) cout<<endl;
101         //每输出完4个数后换行,使每行输出4个数
102         f1=f1+f2;
103         //左边的f1代表第3个数,是第1?2个数之和
104         f2=f2+f1;
105         //左边的f2代表第4个数,是第2?3个数之和
106     }
107 */
108 
109 //===========================================================================================================
110     //简单加密程序
111     
112     //char w=‘W‘;
113     //char a=‘A‘;
114     //cout<<(int)w<<"::"<<(int)a<<endl;
115     
116     char tmp=NULL;
117     while ((tmp=getchar())!=\n)
118     {
119         if ((tmp>=a&&tmp<w)||(tmp>=A&&tmp<W))
120         {
121             tmp+=4;
122         }
123         else if ((tmp>=w&&tmp<=z)||(tmp>=W&&tmp<=Z))
124         {
125             tmp-=22;
126         }
127         cout<<tmp;
128     }
129 
130     cout<<endl;
131 
132 }
View Code

越来越感觉C++的强大了!相对于(C的高深莫测,汇编的苦涩难懂,C#的软件简单,Java没玩过)

最近看了点C++,分享一下我的进度吧!,布布扣,bubuko.com

最近看了点C++,分享一下我的进度吧!

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/linkong1081/p/3811790.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!