Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 速度和速度;动量-我能';不要走那么远_C++_For Loop_Pass By Reference_Pass By Value - Fatal编程技术网

C++ 速度和速度;动量-我能';不要走那么远

C++ 速度和速度;动量-我能';不要走那么远,c++,for-loop,pass-by-reference,pass-by-value,C++,For Loop,Pass By Reference,Pass By Value,我目前正在处理一项任务,该任务要求我使用以下参数编译和执行一个程序: 编写一个程序,执行以下操作:计算物体的速度和动量。速度的公式是V=d/t,动量的公式是m=质量*速度。您的程序应该由两个函数组成:通过值传递(一个),通过指针传递(一个)。它还应该有一个for循环和必要的print语句,以便以表格格式打印结果。 ·“通过值传递”函数用于计算对象的速度,在该函数中,将两个参数传递给该函数一个恒定的距离,但时间是for循环的值:I=1: 双速度(双距离,整数时间); ·“通过指针传递”函数计算对象

我目前正在处理一项任务,该任务要求我使用以下参数编译和执行一个程序:

编写一个程序,执行以下操作:计算物体的速度和动量。速度的公式是V=d/t,动量的公式是m=质量*速度。您的程序应该由两个函数组成:通过值传递(一个),通过指针传递(一个)。它还应该有一个for循环和必要的print语句,以便以表格格式打印结果。 ·“通过值传递”函数用于计算对象的速度,在该函数中,将两个参数传递给该函数一个恒定的距离,但时间是for循环的值:I=1:

双速度(双距离,整数时间); ·“通过指针传递”函数计算对象的动量,您可以向该函数传递两个参数:对象的速度和恒定质量:质量=100:

双动量(双*速度,双*质量)

输出应具有由时间、速度和动量组成的表格格式。用户无需输入值,时间输入范围应为1-200

**现在是我的挣扎,我已经尽我所能把它放在一起,但似乎无法正确编译,它只是继续“按任何按钮继续…”

我真的不明白我做错了什么,只是需要帮助编译和运行,任何帮助都将不胜感激

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

//Function prototypes (declaring the functions).
double velocity(double distance, int time);
double momentum(double *velocity ,double *mass);

//Main function.
int main()
{
    double PrimaryVelo(0);
    double TotalMomentum(0);
    int t(1);
    for (double d = 1; d <= 10; d++)
    {
        PrimaryVelo = velocity(d, t);
    }  //End for the primary for loop. 
    system("pause"); //Prevents closing of debug automatically.
    return 0;
} //End of the main function.

//Pass-by-value method for velocity.
double velocity(double distance, int time)
{
    return distance / time;
}

//Pass-by-pointers method for momentum.
double momentum(double &velocity ,double &mass)
{
    return (velocity * 205);
}
#包括
使用std::cout;
使用std::endl;
使用std::cin;
//函数原型(声明函数)。
双速度(双距离,整数时间);
双动量(双*速度,双*质量);
//主要功能。
int main()
{
双初级速度(0);
双总动量(0);
int t(1);
对于(双d=1;d井…)。。。。
这是您的代码

#include <iostream>

using namespace std;

double velocity(double distance, int time);
double momentum(double velocity ,double mass);

int main()
{
    double Mass=205;
    double Distance=100;
    double Velocity;
    //cout << "Time\t\tVelocity\tMomentum" << endl; //You'll need to reformat this
    for ( int Time = 1 ; Time <= 200 ; Time++ )
    {
        cout << Time << "\t" ;
        cout << velocity ( Distance , Time ) << "\t" ;
        Velocity = velocity ( Distance , Time ) ;
        cout << momentum ( Velocity , Mass ) << endl ;
    }

    // If you can't use conio.h and getch();
    // Use something like this to stop console from closing itself
    int a;  
    cin>>a;  
    return 0;
}
double velocity(double distance, int time)
{
    return distance / time;
}

double momentum(double velocity ,double mass)
{
    return velocity * mass;
}
#包括
使用名称空间std;
双速度(双距离,整数时间);
双动量(双速度,双质量);
int main()
{
双质量=205;
双倍距离=100;
双速;
//库塔;
返回0;
}
双速度(双距离,整数时间)
{
返回距离/时间;
}
双动量(双速度,双质量)
{
返回速度*质量;
}
注意:我已经给了您一些代码,其中函数接受由值传递的参数

我希望它能帮助

祝你有一个愉快的一天。。。。 这是您的代码

#include <iostream>

using namespace std;

double velocity(double distance, int time);
double momentum(double velocity ,double mass);

int main()
{
    double Mass=205;
    double Distance=100;
    double Velocity;
    //cout << "Time\t\tVelocity\tMomentum" << endl; //You'll need to reformat this
    for ( int Time = 1 ; Time <= 200 ; Time++ )
    {
        cout << Time << "\t" ;
        cout << velocity ( Distance , Time ) << "\t" ;
        Velocity = velocity ( Distance , Time ) ;
        cout << momentum ( Velocity , Mass ) << endl ;
    }

    // If you can't use conio.h and getch();
    // Use something like this to stop console from closing itself
    int a;  
    cin>>a;  
    return 0;
}
double velocity(double distance, int time)
{
    return distance / time;
}

double momentum(double velocity ,double mass)
{
    return velocity * mass;
}
#包括
使用名称空间std;
双速度(双距离,整数时间);
双动量(双速度,双质量);
int main()
{
双质量=205;
双倍距离=100;
双速;
//库塔;
返回0;
}
双速度(双距离,整数时间)
{
返回距离/时间;
}
双动量(双速度,双质量)
{
返回速度*质量;
}
注意:我已经给了您一些代码,其中函数接受由值传递的参数

我希望它能帮助


祝你有一个愉快的一天。

你说:“它只是一直在“按任何按钮继续…”当然。这是来自
系统(“暂停”)
您的程序编译得很好,但这条消息是它唯一的副作用。其余的都是一些您不使用的算术结果,编译器正在对其进行优化。应该实际编写任何输出的代码在哪里?
它还应该有一个for循环和必要的print语句,以便以表格形式打印结果rmat.
正如前面所指出的,你还没有达到这个要求。::拍自己的额头::我真是个白痴。@remyable我想了一下(双d=1;d你说:“它只是一直在“按任何按钮继续…”当然。这是来自
系统(“暂停”)
您的程序编译得很好,但这条消息是它唯一的副作用。其余的都是一些您不使用的算术结果,编译器正在对其进行优化。应该实际编写任何输出的代码在哪里?
它还应该有一个for循环和必要的print语句,以便以表格形式打印结果rmat.
正如前面所指出的,你还没有达到这个要求。::拍自己的额头::我真是个白痴。@remyable我曾想过(双d=1;d)