赞
踩
- #include<iostream>
- using namespace std;
- class DataList
- {
- int len;
- double *d;
- public:
- DataList (int len,double data[]=NULL);
- DataList(){delete[]d;}
- int length()const{return len;}
- double getElement (int i)const{return d[i];}
- void sort()const;
- };
- void writeToFile(char*,const DataList&);
- //main.cpp
- #include"DataList.h"
-
- DataList::DataList(int len,double data[]):len(len)
- {
- d = new double[len];
- for(int i = 0;i<len;i++)
- d[i]=(data==NULL?0.0:data[i]);
- }
- void DataList::sort()
- {
- for(int i=0;i < len;++i)
- for(int j =i;j< len; ++j)
- if(d[i]>d[j])
- {
- int temp =d[i];
- d[i] =d[j];
- d[j] = temp;
- }
- }
- void DataList::sort()const
- {
- for(int i =0;i<len -1;i++)cout<<d[i]<<",";
- cout<<d[len-1]<<endl;
- }
- int main()
- {
- double s[] = {7,1,3,11,6,9,12,10,8,4,5,2};
- DataList list (12,s);
- cout<<"排序前:";
- list.show();
- list.sort();
- cout<<endl<<"排序后:";
- list.show();
- writeToFile("",list);
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- #include<iostream>
- using namespace std;
- class Door
- {
- int num;
- bool closed;
- bool locked;
- public:
- Door(int num)
- {
- this->num=num;
- closed = locked=true;
- }
- bool isClosed()const{return closed;}
- bool isOpened()const{return! closed;}
- bool isLocked()const{return locked;}
- bool isUnlocked()const{retuen !locked;}
- void open()
- {
- cout<<endl<<"打开"<<num<<"号门...";
- if(!=closed)
- cout<<"门是开着的,无须在开门。";
- else if(locked)
- count<<"门是锁着的,打不开。";
- else
- {
- closed = false;
- cout << "门打开了。";
- }
- }
- void close()
- {
- cout<< endl<<"关上"<<num<<"号门...";
- if(closed)
- cout<<"门是关着的,无须在关门。";
- else
- {
- closed = true;
- cout <<"门关上了。";
- }
- }
- void lock()
- cout<<endl<<"锁上"<<num<<"号门...";
- if(locked)
- {
- cout<<"门是锁着的,无须再锁门。";
- else
- {
- if(!closed)
- {
- cout<<"先关门...";
- closed=true;
- }
- locked = true;
- cout<<"门锁上了。";
- }
- }
- void unlock()
- {
- cout<<endl<<"开"<<num<<"号门的锁...";
- if(!locked)
- cout << "门没有上锁,无须再开锁。";
- else
- {
- locked = false;
- cout<<"锁开了。";
- }
- }
- };
- int main()
- {
- Door door(503);
- door.open();
- door.unlock();
- door.open();
- door.open();
- door.lock();
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- #include<iostream>
- using namespace std;
- class CharShape
- {
- public:
- CharShape(char ch):_ch(ch){};
- virtual void Show() = 0;
- protected:
- char _ch;
- };
- class Triangle:public CharShape
- {
- public:
- Thiangle(char ch,int r):CharShape(ch),_rows(r){}
- void Show();
- private:
- int_rows;
- };
- class Rectangle: public CharShape
- {
- public:
- Rectangle(char ch, int r,int c):CharShape(ch),_rows(r),_cols(c){}
- void Show();
- private:
- int_rows,_cols;
- void Triangle::Show()
- {
- for(int i = 1;j<=i*2-1;i++)
- count << _ch;
- cout << endl;
- }
- }
- void Rectangle::Show()
- {
- for(int i &
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。