編程長方形類
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方法設置和獲得長和寬。編寫測試類測試是答否達到預定的功能。要求使用自定義的包版。急急急急急急急啊,明天就要交權作業了