-3

私たちの教授はこのプロジェクトを割り当てましたが、私はそれをどのように行うか途方に暮れています. 通常は自分で考えますが、同じ日に大量の英文論文を提出する予定で、それも今週末に終わらせなければなりません。プログラムは 2013 年 11 月 12 日が期限ですが、2013 年 11 月 19 日までに成績に 20% のペナルティを課して提出することができます。

C++ プログラムを作成してテストし、次のプロジェクトを完成させます。

数学の問題で使用する数の表を生成します。

ユーザーに 3 つの番号を尋ねます。

  • 最初の数字は、テーブルに含める値の数を表します (1 ~ 25)。
  • 2 番目の数値は、テーブルの最初の値を表します。(-1000~+1000)
  • 3 番目の数値は、テーブル内の連続する値の間の増分を表します。(1~20)

選択した値を繰り返し処理し、繰り返しの各値から次の派生値を生成して保存します。

  • 四角

  • 平方根 (値が正またはゼロの場合のみ、その他の値はすべて「N/A」を表示)

  • キューブ
  • Cube Root (値が正またはゼロの場合のみ、その他の値はすべて「N/A」と表示)
  • 偶数か奇数か
  • 素数か素数か(課題5のロジックを元にユーザー定義関数を用意)。

計算結果を一連の配列に保存します。計算された値ごとに 1 つの配列です。

すべての値が計算されて保存されたら、計算された値ごとに 1 つの列と値のセットごとに 1 つの行を持つ表形式で値を表示します (ユーザーから読み取られた最初の値に対応します)。

最初の列の負の値ごとに、平方根と立方根の列に「N/A」と表示されることに注意してください。

各番号の偶数/奇数ステータスを「偶数」または「奇数」で表示します。数の素数を「真」または「偽」で表示します。

ユーザーがテーブル内の値の数としてゼロのカウントを入力するまで、このプロセスを繰り返します。

おまけ: triples.txt という名前のデータ ファイルから一連の 3 数値セットを読み取り、各 3 数値セットに対応する数値のテーブルを作成します。結果の数値表を、numbers.csv という名前の単一のテキスト ファイルにコンマ区切り値形式で保存します。

私がこれまでに持っているものは次のとおりです。

// TABLEation.cpp : builds a table based on user input.
//


using namespace std;
double square, squareroot,cube,cuberoot;
int initialValue,display,increment;
string even,prime;
const int SIZE=25;
int Value[SIZE];

bool isEven( int integer )
{

  if ( integer % 2== 0 )
     return true;
  else
     return false;
}

bool isPrime(int testValue) {
    int divisor=0, remainder=0;

if (testValue<2) return false;
        for(divisor=2; divisor<=sqrt(testValue);divisor++){
            if((testValue % divisor)==0) return false;
            }
            return true;
        }


int _tmain()
{
    do{
        begining:
        cout<<"Enter how many values to show (1-25)."<<endl;
        cin>>display;
    if((display>0) && (display<=25)){
        cout<<"Enter an initial Value (-1000 to 1000)."<<endl;
        cin>>initialValue;
    }
    else{
        cout<<"ERRROR! INVALID INPUT!TRY AGAIN"<<endl;
        goto begining;
        }
    if ((initialValue>= -1000) && (initialValue<=1000)){
        cout<<"Enter a number to increment by (1-20)"<<endl;
        cin>>increment;
        }
    else{
        cout<<"ERRROR! INVALID INPUT!TRY AGAIN"<<endl;
        goto begining;
        }

    }
    system("pause");
    return 0;
}

ここからどこへ行けばいいですか?

4

1 に答える 1

4

上記に質問がないので、誰かに答えてもらいたいか、正しい方向へのヒントを教えてもらいたいと思います。私はあなたが後者を求めているふりをするつもりです。問題はかなり簡単です。

Generate a table of numbers for use in a math problem.

Ask the user for three numbers: 
The first number represents how many values are to be in the table (1 to 25).
he second number represents the first value in the table. (-1000 to +1000)
The third number represents the increment between successive values in the table. (1 to 20) 

以下では、最初の答えが 0 になるまでループでこれらの質問をする必要があることがわかるので、関数 "bool get_input(int &num_values, int &start_num, int &increment)" を作成できます。この関数は、ユーザーが範囲内にない値、それ以外の場合は true。ここで、num_values が 0 の場合に終了する while ループでこの関数を呼び出します。

Iterate through the selected values, generating and saving the following derived values from each value in the iteration: 

これは for ループで、i = start_num で、反復ごとに i+=increment を増やします

for ループの反復ごとに、次の 6 つの関数を呼び出す必要があります。

Square 

値の二乗を返す int square(int i) 。

Square Root (only if the value is positive or zero, display “N/A” for all other values)

bool extract_square_root(int i, float &square_root) 値が負の場合は false を返し、そうでない場合は平方根を参照変数に入れます。

Cube

値の立方体を返す int cube(int i) 。

Cube Root (only if the value is positive or zero, display “N/A” for all other values) 

bool extract_cube_root(int i, float &cube_root) -- 上記と同様

Whether the number is even or odd

bool even_or_odd(int i) は、値が偶数の場合は true を返し、それ以外の場合は false を返します。

Whether the number is prime or not (Prepare a user-defined function based on the logic in Assignment 5)

bool prime(int i) は、値が素数の場合に true を返します。(割り当て5を使用)。

Save the results of the calculations in a set of arrays, one array for each calculated value. 

結果ごとに配列に格納します (square_root_array、cube_root_array など)。

After all values are calculated and saved, display the values in a tabular form with one column for each calculated value and a row for each set of values (corresponding to the first value read from the user).

関数 void display_values(float square_root_array[], ...) を呼び出します。これは、各配列を反復処理し、以下にリストされている規則に従って値を出力します。

Note that for each negative value in the first column, display “N/A” in the columns for square root and cube root.

Display “Even” or “Odd” for each number’s even/odd status.

Display “True” or “False” for the number’s prime-ness.

次の部分は、すでに while ループによって処理されています。

Repeat this process until the user enters a count of zero for the number of values in the table.

ボーナスはあなたが理解できるように残しておきます。

Bonus: Read a series of three-number sets from a data file named triples.txt and create a table of numbers corresponding to each three-number set. Save the resulting tables of numbers to a single text file named numbers.csv in comma-separated-value format. 

頑張ってください。たくさんの CS を取る予定がある場合は、徹夜することに慣れてください。コース並みです。

PS これらの指示に従い、不明な点がある各ステップの実行方法を調べれば、このプロジェクトを数時間で片付けることができます。

于 2013-11-09T17:19:12.820 に答える