程序
文章平均质量分 56
liu_111111
这个作者很懒,什么都没留下…
展开
-
1到100之间所有能被3和7整除的整数和
#includevoid main(){int sum=0;for (int i=1;i{if (i%3==0 && i%7==0){ coutsum+=i;}}cout}原创 2011-10-26 14:58:06 · 9700 阅读 · 0 评论 -
奖金计算
(一)#includevoid main(){double jj;int a;cin>>a;if (a{jj=a*0.1;coutelse if (a>100000 && a{ jj=a*0.12;coutelse if (a>200000 && a{ jj=a*0.14; cout else if (a>4原创 2011-10-26 15:07:29 · 508 阅读 · 0 评论 -
输入三个数,判断能否构成锐角三角形
#includevoid main(){int a,b,c;cin>>a>>b>>c;if ((a*a+b*bcoutelse cout}原创 2011-10-26 15:09:15 · 1512 阅读 · 0 评论 -
任意两个正整数的加减乘除运算
#includevoid main(){ int a,b,sum; char t; cout cin>>a>>b; cout cin>>t; switch(t) { case '+': sum=a+b; break;原创 2011-10-26 15:13:14 · 822 阅读 · 0 评论 -
分数序列2/1,3/2,5/3,8/5,13/8,21/13……前二十项的和
#includevoid main(){ long f1=1,f2=1,f3,a1=0,a2=1,a3; int k,sum=0; for (k=1;k { f3=f1+f2; a3=a1+a2; sum=sum+f3/a3; f1=f2;f2=f3; a1=a2;a2=a3; } cout}原创 2011-10-25 17:44:28 · 1961 阅读 · 0 评论 -
利用二维数组存储一个3行4列的单位矩阵,并输出最大值和最小值
#includevoid main(){ int i,j,a[3][4]; int max,min; for(i=0;i { for(j=0;j cin>>a[i][j]; } for(i=0;i { cout for(j=0;j cout } max=a[0][0]; min=a[0][0];原创 2011-10-25 17:43:24 · 7160 阅读 · 0 评论 -
统计你输入的前20个字符
#includevoid main(){ int m,n,x,y,j; m=0;n=0;y=0;x=0; char a[20]; for (j=0;j {cin>>a[j]; if (a[j]>='a' && a[j] m+=1; else if (a[j]>='A' && a[j] n+=1; else if (a[j]>=原创 2011-10-27 16:42:13 · 460 阅读 · 0 评论 -
输入五个同学的成绩,统计出最大成绩
#include const int N=5;void main(){ double a[N]; double max; int i; for(i=0;i { cout cin>>a[i]; } max=a[0]; for(i=1;i {原创 2011-11-01 10:27:32 · 1093 阅读 · 0 评论 -
求一个整数的绝对值(两种方法)
(1)#includevoid main(){ int x,y; cout cin>>x; if (x y=-x; else y=x; cout} (2)#includevoid main(){ int x; cout cin>>x; if (x x=-x; cout原创 2011-11-01 10:42:31 · 2346 阅读 · 0 评论 -
输入年月日,计算出该日为该年的第几天
#includeint leap(int year){ int lp; lp=((year%4==0 && year%100!=0)|| (year%400==0))?1:0; return lp;}int month_days(int year,int month){ int d; switch (month) { case 1: case 3原创 2011-11-01 11:25:46 · 3495 阅读 · 1 评论 -
求1/1+1/3+1/5+...+1/99的和 , 求1/2+1/4+1/6+...+1/00的和
#include void main(){int n,m;double sum1, sum2; sum1 = 0; // 求1/1+1/3+1/5+...+1/99的和for (n=0;n sum1 += 1.0/(2*n+1); cout sum2 = 1;// 求1/2+1/4+1/6+...+1/00的和for(m=1;m sum2 +=1.0/(原创 2011-11-01 11:50:25 · 6211 阅读 · 0 评论 -
输出1~100,每五个显示在一行
#includevoid main(){ for(int i=1;i { cout if (i%5==0) cout }}原创 2011-11-01 10:32:16 · 3448 阅读 · 0 评论 -
闰年
#includeint main(){ int a,b; cin>>a; b=( (a%4==0&&a%100!=0)||(a%400==0)); if (b==1) cout else cout}原创 2011-10-26 15:04:46 · 340 阅读 · 0 评论 -
递归算法计算n!
#includelong fac(unsigned n){ long f; if (n==0) f=1; else f=n*fac(n-1); return f;}void main(){ long y; int n; cin>>n; y=fac(n); cout}原创 2011-11-01 16:19:37 · 460 阅读 · 0 评论 -
输入x和n,求x的n次方
#includefloat power(float x, int n){ int i; float t=1; for(i=1;i t=t*x; return t;}void main(){ float x,y; int n; float power(float x,int n); cin>>x>>n; y=power(x,n); c原创 2011-11-01 16:34:05 · 2519 阅读 · 0 评论 -
利用函数调用求三个数中最大数
(一)#includevoid max(int a,int b,int c){ int y; y=(a>b)?a:b; y=y>c?y:c; cout}void main(){ int x,y,z; cin>>x>>y>>z; max(x,y,z);} (二)#includeint max(int a,int b){原创 2011-11-01 16:51:11 · 4170 阅读 · 0 评论 -
引入友元机制,求任意两点间的距离
#include#includeclass Point{private: double x,y;public: Point(){} Point(double x,double y) { this->x=x; this->y=y; } double getX() //获取横坐标 { return x; } doubl原创 2011-11-23 10:19:28 · 860 阅读 · 2 评论 -
利用重载后的运算符求任意两个数的加减乘除
#includeclass Complex //定义一个Complex类{private: double real; //实部 double imag; //虚部public: Complex(){}原创 2011-11-23 11:28:08 · 1165 阅读 · 0 评论 -
用函数和指针实现两个数的交换
#include void swap(int* p1,int* p2) { int t; t=*p1; *p1=*p2; *p2=t; } int main() { int i,j; cin>>i>>j; cout swap(&i,&j); cout return 0; }原创 2011-11-02 11:41:51 · 1364 阅读 · 0 评论 -
重载自减运算符
#includeclass counter{private: int v;public: counter(){} counter(int v) { this->v=v; } counter operator --() { v--; return *this; } counter operator --(int) { co原创 2011-11-24 17:40:39 · 476 阅读 · 0 评论 -
100之内素数
#include#includevoid main(){ int i,j,k,num=0; for(i=2;i { k=sqrt(i); for (j=2;j { if(i%j==0) break; } if (j>k) { num++;原创 2011-11-01 11:06:48 · 349 阅读 · 0 评论 -
统计十个数中所有素数的和
#include#includeint prime(int x){ int f=1,k; if (x==1) f=0; for (k=2; k if (x%k==0) { f=0; break; } return f;}void main(){ int a[10],i,sum=0; cout for(i=0;i原创 2011-11-03 16:58:06 · 592 阅读 · 0 评论 -
等差数列前n项和
#includevoid main(){ int s,i,n,sum; cout cin>>s; cout cin>>i; cout cin>>n; sum=(s+s+(n-1)*i)*n/2; cout}原创 2011-11-08 16:41:26 · 647 阅读 · 0 评论 -
所有水仙花数
#includeint cubic(int x){return x*x*x;}int main(){ int a1,a2,a3; for(int i=100;i { a1=i/100; a2=i/10-10*a1; a3=i%10; if (i==cubic(a1)+cubic(a2)+cubic(a3)) cout }ret原创 2011-11-08 17:13:45 · 722 阅读 · 2 评论 -
重载下标运算符
#includeclass chararray //定义一个字符数组类{private: int length; char *buff;public: chararray(int l) { length=l; buff=new char[length]; //分配一个连续length个数组的空间 } ~chararra原创 2011-11-29 16:35:31 · 1951 阅读 · 0 评论 -
设计一个string类,通过重载“+=”运算符,实现对两个string类对象m1,m2的操作。
#includeclass string{private: int x,y;public: string(){} string(int a,int b) { x=a;y=b; } void display() { cout } void operator +=(string m2) { x+=m2.x; y+=m2.y原创 2011-11-29 17:56:27 · 3219 阅读 · 0 评论 -
刚学了构造函数,编个程序(两个数的加减乘除运算)
#includeclass calculator{private: int i,num1,num2,result[4];public: calculator(int a,int b) { num1=a; num2=b; } void add() { result[0]=num1+num2; } void minus() {原创 2011-11-10 16:52:22 · 1296 阅读 · 0 评论 -
友元课后题
#include#include"string.h"class score{private: char name[8],xh[7]; double sx,yw,yy; public: score(char n[8],char z[7],double a,double b,double c) { strcpy(name,n); strcpy(x原创 2011-11-30 20:34:31 · 1339 阅读 · 0 评论 -
重载赋值运算符
# includeclass sample{ int n;public: sample(){} sample(int i){n=i;} sample &operator=(sample s) //重载赋值运算符 { n=s.n; return *this; } void disp() { cout }};void原创 2011-12-01 16:32:51 · 1375 阅读 · 0 评论 -
采用冒泡排序法,将数组中元素按照从小到大的顺序排序
#includevoid sort(int[],int);void main(){ int b[5]={71,83,52,35,100}; cout for(int i=0;i cout cout sort(b,5); //数组名作为实参调用函数sort() cout for(i=0;i cout cout原创 2011-12-01 17:15:31 · 38039 阅读 · 1 评论 -
逆序输出字符串
#include #include using namespace std;int main(){string str;int i,n;char temp;coutcin>>str;n=str.size();for(i=0;i{ temp=str[i]; str[i]=str[n-i-1]; str[n-i-1]=tem原创 2011-12-06 17:41:03 · 747 阅读 · 0 评论 -
两个例子分析 9章课后选择7题
7.当一个类的某个函数被说明为virtual时,该函数在该类的所有派生类中(A)A. 都是虚函数B. 只有被重新说明时才是虚函数C. 只有被重新说明virtual时才是虚函数D. 都不是虚函数例一: #includeconst double pl=3.14;class Shape //定义一个图形类{public: virtual原创 2011-12-14 11:50:21 · 612 阅读 · 0 评论 -
开学第一天!!!!!
我以为开学第一天讲不了课了,大伙儿说说假期,谈点对未来一年有什么想法,有一个什么样的规划,所以我一点上课的准备也没有,可是上了半天课,令我庆幸的是老师带着我们复习,更让我高兴的是我挺投入的也听懂了。 讲的类,构造方法,静态的构造方法,静态的字段,静态的类,部分类,匿名类…… 小知识点: 1.用static可以定义静态的字段,静态的方法,静态的类 2.静原创 2012-09-03 19:44:55 · 548 阅读 · 0 评论 -
继承
继承是指能够从它的父类中继承除构造函数以外的所有数据的定义和功能。继承可以提高代码的可重用性。C#语言的类继承具有以下特点:❤C#语言只允许单继承,即派生类只能有一个基类。❤C#语言继承是可以传递的,如果C从B派生,B从A派生,那么C不但继承B中的成员,还要继承A中的成员。❤派生类可以添加新成员,但不能删除基类中的成员。❤派生类不能继承基类的构造函数、析构函数和事件,但能继原创 2012-09-04 20:34:35 · 444 阅读 · 0 评论 -
接口和抽象类
接口可由方法、属性、事件、索引器或这4种成员类型的组合构成。接口的主要特点是只有声明部分,而没有实现部分。和类一样,接口也定义了一系列属性、方法和事件等。但与类不同的是,接口本身并不提供接口成员的实现,而是在继承接口的类中实现,并在类中被定义为单独的实体。接口所具有的属性包括以下特点:❤接口类似于抽象类,继承接口的任何非抽象类型都必须实现接口的所有成员。❤接口不能包涵字段而且接原创 2012-09-05 14:56:01 · 339 阅读 · 0 评论 -
委托
委托对我们C#接触不长的人来说挺不容易的,听课的时候也是听的云里雾里的,晚自习在网上找了找与委托相关的资料,看了一遍觉得很清晰,再实践实践就okle ,我觉得迈过了这个槛儿就觉得委托太容易了,我郁闷了一下午,现在心情总算好点了。现在我把我看的资料粘得这,想不起来的时候再练练。通过两个范例由浅入深地讲述什么是委托、为什么要使用委托、事件的由来、.Net Framework中的委托和事件、委托和事原创 2012-09-06 20:27:57 · 435 阅读 · 0 评论 -
arraylist、hashtable
System.Collections.ArrayList类是一个特殊的数组。通过添加和删除元素,就可以动态改变数组的长度。arraylist可以自动改变大小,灵活的插入元素、删除元素、访问元素,跟一般的数组比起来,速度比较慢using System;using System.Collections.Generic;using System.Linq;using System原创 2012-09-10 15:14:20 · 439 阅读 · 0 评论 -
泛型集合List<>
泛型是具有占位符(类型参数)的类、结构、接口和方法,这些占位符是类、结构、接口和方法所存储或使用的一个或多个类型的占位符。 泛型集合类可以将类型参数用作它所存储的对象的类型的占位符;类型参数作为其字段的类型和其方法的参数类型出现。泛型方法可以将其类型参数用作其返回值的类型或者其形参的类型之一。 List 是对应于 ArrayList 的泛型类。 Dictionary原创 2012-09-11 19:10:51 · 487 阅读 · 0 评论 -
123……变成相应的大写文字壹、贰、叁……(泛型集合)
Console.WriteLine("请输入一个数:"); string number = Console.ReadLine(); string str = "1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖 0零"; Dictionary dict = new Dictionary();原创 2012-09-11 19:15:15 · 1186 阅读 · 0 评论 -
泛型类型的参数约束
T:结构 类型参数必须是值类型。可以指定除 Nullable 以外的任何值类型。 T:类 类型参数必须是引用类型;这一点也适用于任何类、接口、委托或数组类型。T:new() 类型参数必须具有无参数的公共构造函数。当与其他约束一起使用时,new() 约束必须最后指定。 T:原创 2012-09-12 15:57:18 · 462 阅读 · 0 评论