promotion image of download ymail app
Promoted
VeVe 發問時間: 電腦與網際網路程式設計 · 1 0 年前

有關C++程式碼的寫法

各位大大,請問有人會寫C++的程式碼嗎??

可不可以幫小弟一下??

這是我上課後要做的練習...

但是我不會做丫....

請各位大大幫忙

Exercise 2 : Using while and do/while

Repeat the above exercise using both a while statement and a do/while statement.

Exercise 3 : getch & putchar

Use these above functions to write a program that echo's what you type to the screen. The program is to terminate when the 'Q' key is pressed

Exercise 4 :

Write a short menu style program that responds to the keys you press. The following are the 'rules' for the program

Key pressedAction

adisplay Hello, how are you on the screen

bdisplay This is software engineering at its best on the screen

cdisplay a count of the numbers of key presses so far

qquit the program

<none of the above>display You have made an odd selection on the screen

Hint: This program is basically just 'if , else if, else if, else .. ' with a while loop and a counter thrown in for good measure.

已更新項目:

Exercise 1 : Using for

Write a short program that counts from one to ten (inclusive), and calculates the sum of these values, this value to be displayed on the screen.

4 個解答

評分
  • 1 0 年前
    最佳解答

    Exercise 2.

    (1)

    main(){

    int i=1,sum=0;

    while(i<=10){

    sum=sum+i;

    i++;

    }

    cout<<"sum="<<sum;

    }

    (2)

    main(){

    int i=1,sum=0;

    do{

    sum=sum+i;

    i++;

    }while(i<=10);

    cout<<"sum="<<sum;

    }

    Exercise 3.

    main(){

    char a[100];

    while(a!='Q'){

    cout<<"you:";

    gets(a);

    cout<<"computer:";

    puts(a);

    }

    }

    Exercise 4.

    main(){

    int j=0;

    char i;

    cout<<"input a word 'a' or 'b' or 'c'.";

    cin>>i;

    while(i=='q'){

    j++;

    if(i=='a'){

    cout<<"Hello, how are you on the screen"<<endl;

    else if(i=='b')

    cout<<"This is software engineering at its best on the screen"<<endl;

    else if(i=='c')

    cout<<"you input "<<j<<" times"<<endl;

    else

    cout<<"You have made an odd selection on the screen"<<endl;

    cout<<"you want terminate program to input 'q',go on input 'a' or 'b' or 'c'"<<endl

    }

    }

    2007-10-12 10:34:37 補充:

    補之前第一題

    main(){

    int i,sum=0;

    for(i=1;i<=10;i++)

    sum=sum+i;

    cout<<"sum="<<sum;

    }

    • Commenter avatar登入以對解答發表意見
  • 1 0 年前

    因為第一題我會做....第一題是用for來寫的...

    我真的不會做第二題...

    這只是我的第一節computer engineerin的課,

    所以...請各位大大務必幫幫忙><

    • Commenter avatar登入以對解答發表意見
  • 1 0 年前

    你把第一題省了 這樣對嗎?

    第二題 是叫你用 while() 做一個可以重複執行上一題動作(n次)的迴圈。

    可是....課上到這裡了 如果還不會做迴圈 那很麻煩耶!

    • Commenter avatar登入以對解答發表意見
  • Ashley
    Lv 7
    1 0 年前

    所以如果你英文沒問題的話

    麻煩先翻譯成中文囉

    看的好累喔

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。