随笔分类 - c++
收集本人教学中的一些程序
摘要:源程序: #include <stdio.h>#include <iostream>#include <stdlib.h>using namespace std;int main(){ char* p; char a[80]; p = a; int i = 0; while((*p=getchar(
阅读全文
摘要:#include <iostream>using namespace std; class myComplex{private: double real,imag;public: myComplex(); myComplex(double r,double i); void outCom(); my
阅读全文
摘要:#include <iostream>#include <cmath>using namespace std; class Point{private: double x,y; friend class Line;public: Point(double i=0,double j=0) { x=i;
阅读全文
摘要:#include <iostream>using namespace std; class myComplex //复数类{private: double real,imag;public: myComplex(); myComplex(double r,double i); friend clas
阅读全文
摘要:源程序: #include <iostream>using namespace std;class constClass{private: const int conMbr; int Mbr;public: constClass():conMbr(0),Mbr(100){}; constClass(
阅读全文
摘要:源程序: //编写一个程序,将从键盘输入的n个字符串保存在一个一维数组A中。在输入字符串之前,先输入n的值。//要求,数组A需要动态申请空间,程序运行结束前再释放掉。//再输出n字符串中最长和最短的串,计算平均字符中的长度。#include <iostream>#include <string>us
阅读全文
摘要:程序一: #include <iostream>#include <stdlib.h>#define COST 20using namespace std;class tiji //体积{private: double length, width, height; //长宽高public: tiji
阅读全文
摘要:源程序: #include <iostream>using namespace std;class A{public: virtual void printMe() { cout<<"This is class A printing."<<endl; }} ;class B:public A{pub
阅读全文
摘要:源程序: #include <iostream>using namespace std; class B;class A{private: int i;public: int set(B&); int get() { return i; } A(int x) { i = x; }}; class B
阅读全文
摘要:源程序: #include <iostream>using namespace std; class birth{private: int year,month,day;public: birth(int x,int y,int z) { year=x; month=y; day=z; } void
阅读全文
摘要:源程序: #include <iostream>using namespace std; void sort(int L[],int n){ int j,k,flag,temp; flag=n-1; while(flag>0) { k=flag-1; flag=0; for(j=0;j<=k;j++
阅读全文
摘要:声明复数类Complex,该类中有两个私有变量real , image分别表示一个复数的实部和虚部。 为Complex类添加适当的构造函数,并使用友元函数 add实现复数加法。 #include <iostream>using namespace std; class Complex{private
阅读全文
摘要:源程序: #include <iostream>using namespace std; class Based{public: Based() { cout<<"Based构造函数\n"; fun(); } virtual void fun() { cout<<"Base::fun()函数\n";
阅读全文
摘要:源程序: #include <iostream>using namespace std; class example{private: int a;public: example(int b=5) { a=b++; } void print() { a=a+1; cout<<a<<" "; } vo
阅读全文
摘要:源程序: 要求输出结果为40 #include <iostream>using namespace std; class Test{ static int x; //程序填空public: Test(int i=0) { x=i+x; } int Getnum() { return Test::x+
阅读全文
摘要:源程序: #include <iostream>using namespace std; class line;class box{private: int color; int upx,upy; int lowx,lowy;public: friend int same_color(line l,
阅读全文
摘要:源程序: 下列程序,输出结果为150。 #include <iostream>using namespace std; class Arr{ int *a,n;public: Arr():a(0),n(0){} Arr(int *aa,int nn) { n=nn; a=new int [n]; f
阅读全文
摘要:源程序: #include <iostream>using namespace std; int main(){ int max(int a,int b,int c=0); int a,b,c,m1,m2; cin>>a>>b>>c; m1=max(a,b,c); //程序填空 m2=max(a,b
阅读全文
摘要:源程序: #include <iostream>using namespace std; class toy{private: int num,price;public: toy(int q,int p) { num=q; price=p; } int get_num() { return num;
阅读全文
摘要:源程序: #include <iostream>using namespace std;int time=0,end=0;class Test{public: Test() { if(time==0) //程序填空 cout<<"欢迎使用测试程序!"<<endl; time=time+1; } ~T
阅读全文