もう一度すみません、私はプログラミングの天才ではありません。
まずはまとめ:配列入力。2 つの 3D ベクトル...ははは、ベクトルを使用して、MORE ベクトルを計算しましょう。とにかく: 内積はまったくばかげています (10 進数の前に 9 つの数字。つまり、まじめな話、1x8+7x5+4x2 に 9 つの数字があるとは思いもしませんでした)。外積は...さらに悪いです。
私が作った...ええと...どうやってそれを呼ぶことができますか? ええと、私たちはそれを「トラザ」と呼んでいます。理解できるように定義を翻訳します。コードの「トラザ」は、その実行の命令のシーケンスと、コードの各行の後に変数がどのように変化するかを教えてくれます。ご存知のように、変数と数字の付いた表は、コードが予期しないことを行っているかどうかを調べるコード行を示しています。要点を言えば、私が見る限り、すべて問題ありません。
次に、印刷コマンドとベクトルからのすべての値を使用して、予想外に「疑似トラザ」を作成しました。入力の直後でドット積の直前 (関数内)。何を推測しますか:1)それは私の入力ではなく、どちらも2)同じ値でさえありません3)最初の値は私の入力から遠く離れていますが、少なくとも次の値はより多くのロジックでした(入力との違いが少ない) .
今朝、12 時間前に、配列やベクトルなどの使い方を学びました。入力前にデフォルト値として 0 を設定する必要はありませんでした。しかし、このようなことが以前に起こったときに私が知っていた唯一のことです. (いつの日か、あなた方の誰かが私のプログラミングの先生になるでしょう。あなた方は私自身よりも多くのことを学んでいます...そして私のひどい文法を許してください。 ..大学入試に合格するために必要なすべてです!")
#include <iostream>
using namespace std;
#include <stdlib.h>
const int N = 3;
typedef int Vector[N];
void introduirVector (Vector);
float producteEscalar (const Vector, const Vector); /*Input vector and dot product*/
int main (void)
{
Vector v1, v2;
float p_esc;
cout << "Introduim les dades del vector A: "; /* Input */
introduirVector (v1);
cout << "Introduim les dades del vector B: "; /* 2x Input combo */
introduirVector (v2);
cout << v1[0] << "\n" << v1[1] << "\n" << v1[2] << "\n" << v2[0] << "\n" << v2[1] << "\n" << v2[2] << endl; /* "Puseudotraza*/
p_esc= producteEscalar (v1, v2); /*Dot product*/
cout << "El producte escalar: " << p_esc; /*Dot product is...*/
system ("PAUSE");
return 0;
}
/*3x Input combo*/
void introduirVector (Vector)
{
int i;
Vector v;
for (i = 0; i < N; i++)
{
cin >> v[i];
}
return;
}
/* Dot product (why all the Vectors are set as constants but another after this is not set? It's the hint given by the teacher, my (not) beloved teacher...they gave us the main function and the other function's prototypes, but that's all) */
float producteEscalar (const Vector, const Vector)
{
float escalar;
Vector v1, v2;
/* Pseudotrazas for all*/
cout << v1[0] << "\n" << v1[1] << "\n" << v1[2] << "\n" << v2[0] << "\n" << v2[1] << "\n" << v2[2] << endl;
/* Dot product and all that */
escalar = (v1[0]*v2[0])+(v1[1]*v2[1])+(v1[2]*v2[2]);
return escalar;
}