编程算矩形
㈠ 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;
}
㈧ 数控车床车螺纹编程矩形怎样计算
矩形跟一般的三角螺纹一样,图纸上给的条件已经足够了,不用计算,车法跟三角螺纹也是一样的,只不过刀的形状不一样而已,一个是三角形,一个是矩形的刀头