c++实验大纲

2026/1/27 20:02:04

(2)定义一个具有构造函数和析构函数的类,如实验一的CPU类,定义一个CPU的对象数组,观察构造函数的析构函数的调用过程。 #include%using namespace std;

class CPU {

public: CPU(int xx,int yy):x(xx),y(yy) { cout<<\ } CPU() { cout<<\ } ~CPU() { cout<<\ } private: int x,y; };

int main() { CPU P[5]; CPU a[2]={CPU(1,2),CPU(2,3)}; return 0; }

2)

利用动态内存分配的方式重新完成题目2)。

#include%using namespace std;

class CPU {

public: CPU(int xx,int yy):x(xx),y(yy) { cout<<\ } CPU() { cout<<\ } ~CPU() { cout<<\ } private: int x,y; };

class ArrayofCPUs {

public:

ArrayofCPUs(int size):size(size) { p=new CPU[size]; } ~ArrayofCPUs() { cout<<\ delete [] p; } private: int size; CPU *p; };

int main() { CPU P[5]; CPU a[2]={CPU(1,2),CPU(2,3)}; return 0; }

3)

使用系统提供的string类定义字符串对象并初始化,实现从原始字符串中提取

一个子串。

#include\

#include%using namespace std;

int main() { int pos,n,l; string str(\ cout<>pos; if(pos<1 || pos>l) { cout<<\不合法!!\ exit(1); } cout<<\取子串中n=\ cin>>n; if(n>l || pos+n>l) { cout<<\不合法!!\ exit(1); } string str2=str.substr(pos,n); cout<

4)

选做:定义一个Point(二维点类)的对象数组,利用该数组实现直线的线性

拟合。


c++实验大纲.doc 将本文的Word文档下载到电脑
搜索更多关于: c++实验大纲 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219