编程长方形类
1. C++问题,设计一个长方形类
#include <iostream>
using namespace std;
class Rectangle {
double width, height;
public:
void setRectangle(double width, double height) {
this->width = width;
this->height = height;
}
double getArea() {
return width * height;
}
double getPerimeter() {
return (width + height) * 2;
}
};
int main() {
double width, height;
Rectangle rectangle;
cin >> width >> height;
rectangle.setRectangle(width, height);
cout<<rectangle.getArea()<<'\n'<<rectangle.getPerimeter();
return 0;
}
【答题不易,请采纳谢谢】
2. java创建一个长方形的类 急!!!在线等!!!学号是37!
import java.util.Scanner;
public class Demo_137 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入长和宽:");
int length=input.nextInt();
int wide=input.nextInt();
if(length==137) {
Rectangle rec=new Rectangle(length, wide);
System.out.println("周长:"+rec.perimeter());
System.out.println("面积:"+rec.area());
System.out.println("构造长方形个数:"+rec.getCount());
}
}
}
class Rectangle{
private int length,wide,count=0;
public Rectangle(int length,int wide) {
this.length=length;
this.wide=wide;
count++;
}
public int perimeter() {
int per=(length+wide)*2;
return per;
}
public int area() {
int are=length*wide;
return are;
}
public int getCount() {
return count;
}
}
3. java定义5个类:圆类、圆锥类、长方形类、几何图形类,编程实现求长方形的面积和圆锥的体积
长方形类里面肯定有长和宽两个参数吧。
圆锥类里面肯定有半径和高两个参数吧。
不知道你的类名和参数名,我瞎取的,看拼音你肯定能懂。
public float size(float height, float width){
changfangxing chang = new changfangxing;
float height1 = chang.height;
float width1 = chang.width;
float size = height*width;
return size;
}
public float volume(float height, float banjing){
yuanzhui yuan = new yuanzhui;
float height1 = yuan.height;
float banjing1 = chang.banjing;
float volume = height*banjing*banjing*3.14/3;
return volume;
}
4. JAVA编写一个长方形类,
public class Rectangle {
double a = 36.8;
double b = 12;
public double area() {
return a*b;
}
public void output() {
System.out.println("The area is " + area());
}
public static void main(String args[]) {
Rectangle rec = new Rectangle();
rec.output();
}
}
5. java编程:定义一个长方形类,含有成员变量:长length, 宽width;成员方法:构造方法,
长方形是长方体的属性
6. Java定义长方形类Rect ,包含三个属性长len ,宽width,高height和一个计算体积
public class Rect {
private double len;
private double width;
private double height;
//体积
public double volume () {
return this.len * this.width * this.height;
}
public double getLen() {
return len;
}
public void setLen(double len) {
this.len = len;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
class RectTest {
public static void main(String[] args) {
Rect rect = new Rect();
rect.setLen(5);
rect.setWidth(7);
rect.setHeight(9);
double volume = rect.volume();
System.out.println("体积为 = " + volume);
}
}
7. java,定义一个长方形类
public class Test {
public static void main(String[] args) {
Rectangle r = new Rectangle(5, 4);
System.out.println("Circle for rectangle is: " + r.circle());
System.out.println("Area for rectangle is: " + r.area());
}
}
class Rectangle{
private double length;
private double width;
public Rectangle(double length, double width){
this.length = length;
this.width = width;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public void setLength(double length) {
this.length = length;
}
public void setWidth(double width) {
this.width = width;
}
public double circle(){
return 2 * (width + length);
}
public double area(){
return width * length;
}
}
------------------------
Circle for rectangle is: 18.0
Area for rectangle is: 20.0
8. JAVA编程 定义一个长方形类,含有两个实例变量w.l 和实例方法两个,分别计算面积和周长,
你好 如图:
9. Java编程:面向对象。设计一个长方形类,成员变量包括长和宽.
设计一个百长方形类,成员变量包括长和宽.类中有计算面积和周度长的方法,并有相应的set方法和问get方法设置和获得长和宽。编写测试类测试是答否达到预定的功能。要求使用自定义的包版。急急急急急急急啊,明天就要交权作业了