編程算矩形
㈠ c語言,編寫程序計算矩形的面積和周長,用兩個函數分別計算面積和周長
#include<stdio.h>
doublezc(doublex,doubley){
return2*(x+y);
}
doublemj(doublex,doubley){
returnx*y;
}
intmain(){
doublex,y;
scanf("%lf%lf",&x,&y);
printf("%lf%lf",zc(x,y),mj(x,y));
getchar();
getchar();
return0;
}
㈡ C++編程:編寫一個矩形rectange類。。。
程序比較長,分開發給你,按照順序粘貼到一起就行了
類定義:
#include
#include
#include
#define
n
100
using
namespace
std;
int
num_of_students=0;
class
student
{
private:
string
name;
string
no;
string
sex;
int
age;
float
score;
int
squad;
public:
void
get_info();
void
show_info();
void
show_ord_info();
string
&get_name()
{return
name;}
string
&get_no()
{return
no;}
float
get_score()
{return
score;}
int
get_squad()
{return
squad;}
}
st[n],t;
void
student::get_info()
{
cout<<"姓名:";
cin>>name;
cout<<"性別:";
cin>>sex;
cout<<"年齡:";
cin>>age;
cout<<"學號:";
cin>>no;
cout<<"班級:";
cin>>squad;
cout<<"成績:";
cin>>score;
}
void
student::show_info()
{
cout<<"---------------"<
評論
0
0
載入更多
㈢ java編程求矩形的面積
import java.util.*;
public class Rectangle {
private float length; //定義長變數
private float width; // 寬變數
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;
} //求周長方法
public float getArea(){
return length*width;
} //求面積方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//調用輸入方法
System.out.println ("請輸入矩形的長:");
float a=in.nextFloat();
System.out.println ("請輸入矩形的寬:");
float b=in.nextFloat();
System.out.println ("矩形周長為:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面積為:"+new Rectangle(a,b).getArea());
}
}
㈣ C語言問題,編寫一個程序計算矩形的面積和周長
1.代碼參考:(邊長可以是整數也可以是小數;實現乘法的運算符是*)
(4)編程算矩形擴展閱讀
1.結構類型是在程序中定義的類型,以指定記錄的格式,它包括成員名稱和類型,以及成員在內存中的存儲次序。
2.一旦定義了結構類型,就可以像使用其他所有類型一樣使用這種結構類型,可以聲明具有這種結構類型的對象,定義指向這種對象的指針,以及定義具有這種結構類型元素的數組。
3.結構類型的定義從關鍵字 struct 開始,大括弧內包含聲明結構成員的列表:struct [標簽名稱] {成員聲明列表};
4.結構必須包含至少一個成員。下面的例子定義了 struct Date 類型,它有 3 個 short 類型的成員:struct Date { short month, day, year; };
5.標識符Date是該結構類型的標簽(tag)。標識符 year、month 和 day 是成員名稱。
6.結構類型的標簽屬於一個不同的命名空間:即使結構標簽與變數名或函數名相同,編譯器也仍然可以區分。類似地,對於每個結構類型,其中的每個結構成員名稱都屬於不同的命名空間。
7.結構的成員,可以定義為任何所需的完整類型,包括之前已定義的結構類型。但是不能是長度可變的數組,或者指向長度可變數組的指針。
㈤ 求C語言編程矩形面積周長對角線
#include "stdio.h"
//面積
double area(double len,double wid){return len*wid;}
//周長
double circle(double len,double wid){return 2*(len+wid);}
//對角線
double ijiaoxian(double len,double wid){return sqrt(len*len+wid*wid);}
void main()
{
printf("請輸入長寬:\n");
double length,width;
scanf("%f%f",&length,&width);
printf("面積為:\n",area(length,width));
printf("周長為:\n",circle(length,width));
printf("對角線長為:\n",ijiaoxian(length,width));
}
㈥ 編程實現矩形類,其中包括計算矩形周長和面積的方法,並測試方法的正確性,用JAVA編寫
/**
* 矩形類
*/
public class Rectangle {
private double length; //長
private double width; //寬
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public Rectangle() {
}
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
/**
* 面積計算方法
* @param length 長
* @param width 寬
* @return 面積
*/
public double area(){
return length*width;
}
/**
* 周長計算方法
* @param length 長
* @param width 寬
* @return 周長
*/
public double girth(){
return 2*(length+width);
}
public static void main(String[] args) {
//定義矩形,長為4.5,寬為3
Rectangle rectangle=new Rectangle(4.5,3);
System.out.println("矩形面積是:"+rectangle.area());
System.out.println("矩形周長是:"+rectangle.girth());
}
}
㈦ 怎麼用c語言求矩形面積
答:
一、首先弄清公式:S(面積)=a(長)×b(寬);這應該是最簡單的公式了。
二、明確輸入,既然是求面積,必須知道長和寬,把它們作為輸入項。
三、模塊劃分:計算過程封裝到函數int RecArea(int rec_length, int rec_width);
四、實現如下:
#include<stdlib.h>
#include<stdio.h>
//計算矩形面積
intRecArea(intrec_length,intrec_width)
{
intrec_area=0;
rec_area=rec_length*rec_width;
returnrec_area;
}
intmain()
{
intlength,width,area;
printf("輸入矩形的長和寬(用逗號分隔):");
scanf("%d,%d",&length,&width);
area=RecArea(length,width);
printf("矩形面積為:%d ",area);
return0;
}
㈧ 數控車床車螺紋編程矩形怎樣計算
矩形跟一般的三角螺紋一樣,圖紙上給的條件已經足夠了,不用計算,車法跟三角螺紋也是一樣的,只不過刀的形狀不一樣而已,一個是三角形,一個是矩形的刀頭