一个C++简单程序的问题

一个C++简单程序的问题,第1张

#include<iostream.h>

#include<stdlib.h>

class Point

{

private:

int x

int y

public:

Point(int x,int y)

{

this->x=x

this->y=y

}

void setX(int a)

{

x=a

}

void setY(int a)

{

y=a

}

int getX()

{

return x

}

int getY()

{

return y

}

~Point()

{}

}

class Circle: public Point

{

private:

float r

public:

Circle(int x,int y,float r)

:Point(x,y)

{

this->r=r

}

void setR(float a)

{

r=a

}

float getR()

{

return r

}

~Circle()

{}

}

class Cylinder:public Circle

{

private:

float h

public:

Cylinder():Circle(0,0,0),h(0){}

Cylinder(int x,int y,float r,float h)

:Circle(x,y,r)

{

this->h=h

}

void setH(float a)

{

h=a

}

float getH()

{

return h

}

friend istream &operator >>(istream &in, Cylinder &c1)

friend ostream &operator <<(ostream &out, Cylinder &c1)

}

istream &operator>>(istream &in,Cylinder &c1)

{

int _x,_y

float _h,_r

cout<<"请输入坐标:\n"

in>>_x>>_y

cout<<"请输入半径:\n"

in>>_r

cout<<"请输入高:\n"

in>>_h

c1.setX(_x)

c1.setY(_y)

c1.setR(_r)

c1.setH(_h)

return in

}

ostream &operator <<(ostream &out,Cylinder &c1)

{

out<<"坐标为"<<"("<<c1.getX()<<","<<c1.getY()<<")"<<endl

out<<"半径为"<<c1.getR()<<endl

out<<"高为"<<c1.getH()<<endl

return out

}

int main()

{

Cylinder a

cin>>a

cout<<a

return 0

}

楼上的都说错了! 即使的getX() 也只是返回的一个拷贝! 仅仅返回的是一个值!不能改变原来对象的field!应该写一个set 函数! 值传递的知识 楼上的根本就不懂啊! 汗!

#include <stdio.h>

#include <string.h>

#include "stdlib.h"

unsigned int char2int(char *str)

{

unsigned int count=0, ret=0

for(count = 0count<strlen(str)count++)

{

ret = ret<<1

if('0' != str[count])

{ ret+=1}

}

return ret

}

unsigned int getR(char *str)

{

unsigned int c =0

int ret = strlen(str)-1

for(c=0c <strlen(str)c++)

{if(str[c] != '0')<br/> {return ret-c}

}

}

int getRi(unsigned int num)

{

int c =0

for(num != 0c++)

{num = num>>1}

return c

}

void CRC(char *scode, char *p, char*g )

{

unsigned int iP = char2int(p)

unsigned int iG = char2int(g)

unsigned int r= getR(g)

unsigned int code = iP <<r

unsigned int yx = code

for(getRi(yx) >= getRi(iG))

{ yx = yx ^ (iG<<(getRi(yx) - getRi(iG)))}

code += yx

itoa(code,scode,2)

}

void main() //定义主函数

{

char data[8]="" , bds[8]="",code[16]=""

printf("数据:")

scanf("%s", data)

printf("表达式:")

scanf("%s", bds)

CRC(code,data,bds)

printf("编码:%s",code)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7877255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存