**** 高分 这些作业题咋做啊

chinaworker 2003-09-12 05:22:01





[ 2 ]将下面的c转换成c++
#include<stdio.h>
#define pi 3.14159
#define R(d) d*pi/180
main()
{ float degree;
scanf(“%f”,°ree);
printf(“%f\n”,R(degree));
}


2.重复读入球体的半径,计算球体的表面积(4πR2)和体积(4/3πR3)
要求:(1)定义PI为const常量,用主函数型编程(for,while,do…while)
(2)用自定义函数编程:
①自定义函数参数为普通变量,使用按值传递调用。
②自定义函数参数为指针变量,使用按指针传递调用。
③自定义函数参数为指针变量,使用取变量地址传递。
④自定义函数参数为引用,使用按引用传递调用。
⑤自定义函数参数为数组,使用按数组名传递调用。
...全文
30 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
noscar 2003-09-19
  • 打赏
  • 举报
回复
scanf->cin;
printf->cout;
const double pi=3.12159;
头文件是否要为:<cstdio.h>我不确顶用MSDN查!!
kena 2003-09-19
  • 打赏
  • 举报
回复
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

const double pi = 3.14159265;

inline double BallArea(double);
inline double BallArea_pointer(double *);
inline double BallArea_reference(double &);
double BallArea_array(double[],int);

int main()
{
double radius;
cin>>radius;
cout<<BallArea(radius)<<endl;
cout<<BallArea_pointer(&radius)<<endl;
cout<<BallArea_reference(radius)<<endl;

cout<<"array showing:"<<endl;
double radius_array[] = {1,2,3,4,5}; //可改成动态输入,节省时间,这里简单演示一下
BallArea_array(radius_array,5);

return 0;
}


inline double BallArea(double r)
{
return 4*pi*r*r;
}

inline double BallArea_pointer(double *r)
{
return 4*pi*(*r)*(*r);
}

inline double BallArea_reference(double& r)
{
return 4*pi*r*r;
}

double BallArea_array(double r[],int size)
{
for(int i=0;i<size;i++)
cout<<4*pi*r[i]*r[i]<<endl;
return 0;
}
有些地方为节省时间省略了,有些提示语句你可以自己加上,先看看吧:)
TianGuangZao 2003-09-19
  • 打赏
  • 举报
回复
第二题,请看 c++ 模板和多态。
cnxiaohai 2003-09-19
  • 打赏
  • 举报
回复

#include <iostream.h>
#define pi 3.14159
#define R(d) d*pi/180
int main()
{ float degree;
cin>>degree;
cout<<R(degree);
return 0
}


#include <iostream.h>
#include <math.h>
void main()
{
float r,s,v;
const float PI=3.14
cin>>r;
for(;r!=13;)
{
s=4*PI*r*r;
v=4/3*PI*pow(r,3);
cout<<s<<endl;
cout<<v<<endl;
cin>>r;
}
}

chinaworker 2003-09-19
  • 打赏
  • 举报
回复
②自定义函数参数为指针变量,使用按指针传递调用。
③自定义函数参数为指针变量,使用取变量地址传递。
④自定义函数参数为引用,使用按引用传递调用。
⑤自定义函数参数为数组,使用按数组名传递调用。


其他的呢?谢谢了
showming 2003-09-17
  • 打赏
  • 举报
回复
2:
①自定义函数参数为普通变量,使用按值传递调用
#include <iostream.h>
#define PI 3.14159
float mianji(float R);
float tiji(float R);
int main()
{
float R=1,S=1,V=1;
while(R)
{
cout<<"请输入半径(当小于等于0时退出):";
cin>>R;
if(R<=0)
return 1;
S=mianji(R);
cout<<endl<<"面积是:"<<S;
V=tiji(R);
cout<<endl<<"体积是:"<<V;
}
return 1;
}

float mianji(float R)
{
float S=0;
S=4*PI*R*R;
return S;
}

float tiji(float R)
{
float V=0;
V=PI*R*R*R*4/3;
return V;
}
showming 2003-09-17
  • 打赏
  • 举报
回复
上面写错了:
第二题:(许在中文编译条件下)
1:
#include <iostream.h>
int main()
{
const float PI=3.14159;
float R=1;
while(R)
{
cout<<"请输入半径(当小于等于0时退出):";
cin>>R;
if(R<=0)
return 1;
cout<<endl<<"面积是:"<<4*PI*R*R;
cout<<endl<<"体积是:"<<PI*R*R*R*4/3;
cout<<endl;
}
return 1;
}
showming 2003-09-17
  • 打赏
  • 举报
回复
第二题:(许在中文编译条件下)
1:
#include <iostream.h>
int main()
{
const float PI=3.14159;
float R=1;
while(R)
{
cout<<"请输入半径(当小于等于0时退出):";
cin>>R;
if(R<=0)
return 1;
cout<<endl<<"面积是:"<<4*PI*R;
cout<<endl<<"体积是:"<<PI*R*4/3;
cout<<endl;
}
return 1;
}
jxbicestare 2003-09-17
  • 打赏
  • 举报
回复
无聊
playboyxp 2003-09-17
  • 打赏
  • 举报
回复
#include <iostream.h>
#define pi 3.14159
#define R(d) d*pi/180
int main()
{ float degree;
cin>>degree;
cout<<R(degree);
return 0
}


#include <iostream.h>
#include <math.h>
void main()
{
float r,s,v;
const float PI=3.14
cin>>r;
for(;r!=13;)
{
s=4*PI*r*r;
v=4/3*PI*pow(r,3);
cout<<s<<endl;
cout<<v<<endl;
cin>>r;
}
}

program2100 2003-09-17
  • 打赏
  • 举报
回复
up
hslinux 2003-09-17
  • 打赏
  • 举报
回复
兄弟,多看看书把,这些任何一本C++书里都有的。这些都是最基础的了。
chinaworker 2003-09-15
  • 打赏
  • 举报
回复
第二呢?

第二道题目呢???
Wolf0403 2003-09-14
  • 打赏
  • 举报
回复
#include<cstdio>
#define pi = 3.14159
#define R(d) d*pi/180
int main()
{
float degree;
scanf(“%f”,°ree);
printf(“%f\n”,R(degree));
return 0;
}
哈哈,这是最简单的转换法
emmyjeff 2003-09-14
  • 打赏
  • 举报
回复
上面发错了,应该为:
第一题

#include<stdio.h> #include "iostream"
#define pi 3.14159 const float PI = 3.14159
#define R(d) d*pi/180 inline float R(float d){return d * PI / 180}
use namespace std;
main() void main()
{ float degree;
scanf(“%f”,°ree); cin>>f;
printf(“%f\n”,R(degree)); cout<<R(degree);
}

emmyjeff 2003-09-14
  • 打赏
  • 举报
回复
#include<stdio.h> #include "iostream"
第一题
#define pi 3.14159 const float PI = 3.14159
#define R(d) d*pi/180 inline float R(float d){return d * PI / 180}
main() void main()
{ float degree;
scanf(“%f”,°ree); cin>>f;
printf(“%f\n”,R(degree)); cout<<R(degree);
}


scpzhwang 2003-09-14
  • 打赏
  • 举报
回复
#include <iostream.h>
#define pi 3.14159
#define R(d) d*pi/180
void main()
{
float degree;
cin>>degree;
cout<<R(degree);
}
Peterwby 2003-09-14
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
const int Pi = 3.14159;

inline double R(float degree)
{
return degree * Pi / 180;
}

int main()
{
float degree;
cin >>degree;
cout <<R(degree)<<endl;
}
tonybaobao 2003-09-14
  • 打赏
  • 举报
回复
#include<stdio.h>
#define pi 3.14159
#define R(d) d*pi/180
main()
{ float degree;
cin>>degree;
cout<<R(degree);
}
goodluckyxl 2003-09-14
  • 打赏
  • 举报
回复
scanf->cin

printf->cout
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 看图猜成语微信小程序源码+项目说明+数据库(高分毕设).zip **本系统参考明日科技官方开发的看图猜成语小程序** **1. 题目** > * 看图猜成语小程序开发(Flask\MySql+微信小程序实现) **2. 题目要求** > * 操作系统:window7及以上版本、Linux > * Python版本:Python3.7 > * 开发工具:微信开发工具+PyCharm等 > * Python Web框架:Flask > * 虚拟环境:virtualenv > * 数据库:PyMySQL+MySQL **3. 功能要求** > * 微信小程序授权登录功能 > * 显示当前关卡功能 > * 显示用户信息功能 > * 答题功能 > * 判卷功能 > * 自动下一题功能 > * 排行榜功能 > * 分享好友功能 **4. 开发环境** > * 操作系统:windows10 > * Python版本:Python3.7 > * 开发工具:微信开发者工具、PyCharm > * Python Web框架:Flask > * 虚拟环境:virtualenv > * 接口调试工具:Postman > * 数据库:PyMySQL、MySQL > * 测试环境:iPhone 5 > * requirements.txt: > > * Click==7.0 > > * Flask==1.1.1 > > * Flask-HTTPAuth==3.3.0 > > * Flask-SQLAlchemy==2.4.1 > > * Jinja2==2.10.3 > > * MarkupSafe==1.1.1 > > * PyMySQL==0.9.3 > > * SQLAlchemy==1.3.12 > > * Werkzeug==0.16.0 > > * asn1crypto==1.2.0 > > * certifi==2019.11.28 > > * cffi==1.13.2 .....

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧