3.动态存储管理和程序调试
2013-05-03 17:53
253 查看
point.h
----------------------------------------------------------------------------
#include<iostream>
#include<cmath>
using namespace std;
class point{
private:
double x,y;
public:
point(double =0,double =0);
double Getx(); //获取x
double Gety(); //获取y
void setxy(double,double); //设置x,y
~point(); //析构的同时显示删去的点
};
void set(point *); //设置x,y
void Display(point *); //显示x,y
double lenth(point *); //计算折现长度
const int num=10; //设置开辟内存的大小
--------------------------------------------------------------------------
#include"point.h"
point::point(double a,double b){
x=a;
y=b;
}
double point::Getx(){
return x;
}
double point::Gety(){
return y;
}
void point::setxy(double a,double b){
x=a;
y=b;
}
point::~point(){
cout<<x<<","<<y<<"is delete."<<endl;
}
void set(point *p){
double a,b;
int i;
for(i=0;i<num;i++)
{
cout<<"请输入第"<<i<<"个点坐标:";
cin>>a>>b;
(p+i)->setxy(a,b);
}
}
void Display(point *p){
for(int i=0;i<num;i++)
{
cout<<"第"<<i<<"个点的坐标是:"<<(p+i)->Getx()<<","<<(p+i)->Gety()<<endl;
}
}
double lenth(point *p){
double sum=0.0,a1,a2,b1,b2;
a1=p->Getx();
b1=p->Gety();
for(int i=1;i<num;i++)
{
a2=(p+i)->Getx();
b2=(p+i)->Gety();
sum+=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1));
a1=a2;
b1=b2;
}
return sum;
}
int main()
{
point *p=new point[10];
if(p==NULL)
{
cout<<"分配内存失败。"<<endl;
return 0;
}
set(p);
Display(p);
cout<<"lenth="<<lenth(p)<<endl;
delete []p;
return 0;
}
----------------------------------------------------------------------------
#include<iostream>
#include<cmath>
using namespace std;
class point{
private:
double x,y;
public:
point(double =0,double =0);
double Getx(); //获取x
double Gety(); //获取y
void setxy(double,double); //设置x,y
~point(); //析构的同时显示删去的点
};
void set(point *); //设置x,y
void Display(point *); //显示x,y
double lenth(point *); //计算折现长度
const int num=10; //设置开辟内存的大小
--------------------------------------------------------------------------
#include"point.h"
point::point(double a,double b){
x=a;
y=b;
}
double point::Getx(){
return x;
}
double point::Gety(){
return y;
}
void point::setxy(double a,double b){
x=a;
y=b;
}
point::~point(){
cout<<x<<","<<y<<"is delete."<<endl;
}
void set(point *p){
double a,b;
int i;
for(i=0;i<num;i++)
{
cout<<"请输入第"<<i<<"个点坐标:";
cin>>a>>b;
(p+i)->setxy(a,b);
}
}
void Display(point *p){
for(int i=0;i<num;i++)
{
cout<<"第"<<i<<"个点的坐标是:"<<(p+i)->Getx()<<","<<(p+i)->Gety()<<endl;
}
}
double lenth(point *p){
double sum=0.0,a1,a2,b1,b2;
a1=p->Getx();
b1=p->Gety();
for(int i=1;i<num;i++)
{
a2=(p+i)->Getx();
b2=(p+i)->Gety();
sum+=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1));
a1=a2;
b1=b2;
}
return sum;
}
int main()
{
point *p=new point[10];
if(p==NULL)
{
cout<<"分配内存失败。"<<endl;
return 0;
}
set(p);
Display(p);
cout<<"lenth="<<lenth(p)<<endl;
delete []p;
return 0;
}
相关文章推荐
- 编写程序模拟完成动态分区存储管理方式的内存分配和回收。
- 动态树的管理程序(基于jQuery Treeview实现)
- IBM的LPI复习资料之LPI101-Topic102:Linux安装和包管理(3)管理动态链接库(查找和加载程序需要的动态链接库文件)
- 动态存储管理
- 利用程序动态管理Web.config文件
- 集成Ajax的调试ASP语句的小程序(内嵌可移动+可滚动跟随+可隐藏、显示的输入小窗口,可输入asp语句动态运行可)
- 利用程序动态管理Web.config文件的配置
- 动态存储空间管理示例——比较两个数大小
- 第十五章 调试及安全性(In .net4.5) 之 管理程序集
- 数据结构复习笔记七:动态存储管理
- 利用程序动态管理Web.config文件
- C语言提高-39讲: 动态存储管理与动态数组的实现(实践)
- 动态调用Excel,从而避免因为版本不同而使用程序无法编辑或调试
- 利用程序动态管理Web.config文件
- iOS程序 防止动态调试
- 利用程序动态管理Web.config文件(作者:海雅)
- 存储过程学习(003)--象写程序一样的写存储过程及调试
- [OS复习]程序装入技术、简单存储管理技术
- 利用程序动态管理Web.config文件的配置
- C语言内存的动态存储管理2-空闲链表