佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

楼主: spannar90^_^

各位C++高手请进来。小弟有大大问题。

[复制链接]
 楼主| 发表于 6-11-2009 09:03 PM | 显示全部楼层
我不知道我的stpm会出怎样的question。因为这个sample是2003年的。现在2009。差很远。
回复

使用道具 举报


ADVERTISEMENT

发表于 6-11-2009 09:33 PM | 显示全部楼层

回复 84# geekman 的帖子

go to 是 goto对吗? 书上的范例是没有空格的哦。
回复

使用道具 举报

发表于 6-11-2009 09:37 PM | 显示全部楼层

回复 100# spannar90^_^ 的帖子

就以你这题做例子

start wait reading one character code and two integer entered by a user.if the character code is I,diplay the sum of two integer.if the character code is B,display the difference betwwen the two integer.if the character is K.display message the end and stop.if others than above this type code.display wrong code..the algorithm will repeat as long as the user does not input the end character code

c programming version:
  1. #include <stdio.h>
  2. #include <ctype.h>

  3. /*get user input */
  4. void getInput(int *arg1, int *arg2);

  5. int main()
  6. {
  7.     char choice;
  8.     int num1, num2;
  9.    
  10.     do
  11.     {
  12.         /*prompt user to enter his/her choice*/
  13.         printf("Please enter a character :");
  14.         
  15.         /*store user input in choice*/
  16.         scanf(" %c", &choice);
  17.         
  18.         /*perform action according user choice*/
  19.         switch( toupper(choice)) /*convert the character to upper case letter*/
  20.         {
  21.             /*if user input 'l' or 'L'*/
  22.             case 'L':
  23.                 /*get user input*/
  24.                 getInput(&num1, &num2);
  25.                
  26.                 /*output the sum*/
  27.                 printf("sum is %d\n", num1 + num2);
  28.                
  29.                 /*break the switch statement*/
  30.                 break;
  31.                
  32.             /*if user input 'b' or 'B'*/
  33.             case 'B':
  34.                 /*get user input*/
  35.                 getInput(&num1 , &num2);
  36.                
  37.                 /*output the different */
  38.                 printf("different is %d\n", num1 - num2);
  39.                
  40.                 /*break switch statement*/
  41.                 break;
  42.                
  43.             /*if user input 'k' or 'K'*/
  44.             case 'K':
  45.                 /*output program termination*/
  46.                 printf("Program terminated\n");
  47.                
  48.                 /*break the switch statement*/
  49.                 break;
  50.                
  51.             /*all character except 'k' , 'l', 'b' OR 'K', 'L', 'B'*/
  52.             default:
  53.                 /*output invalid prompt*/
  54.                 printf("invalid input, please try again\n");
  55.         }
  56.         
  57.     } while( toupper(choice) != 'K'); /*program ended if user entered 'K' or 'k'*/
  58.    

  59.     return 0;
  60. }
  61.    
  62. /*function*/
  63. void getInput(int *arg1, int *arg2)
  64. {
  65.     printf("please enter two integer :");
  66.     scanf(" %d %d", arg1, arg2);
  67. }
复制代码
c++ programming version:
  1. #include <iostream>
  2. #include <cctype>

  3. using namespace std;

  4. //get user input
  5. void getInput(int &arg1, int &arg2);

  6. int main()
  7. {
  8.     char choice;
  9.     int num1, num2;
  10.    
  11.     do
  12.     {
  13.         //prompt user to enter his/her choice
  14.         cout << "Please enter a character :";
  15.         
  16.         //store user input in choice
  17.         cin >> choice;
  18.         
  19.         //perform action according user choice
  20.         switch( toupper(choice)) //convert the character to upper case letter
  21.         {
  22.             //if user input 'l' or 'L'
  23.             case 'L':
  24.                 //get user input
  25.                 getInput(num1, num2);
  26.                
  27.                 //output the sum
  28.                 cout << "sum is " << num1 + num2 << endl;
  29.                
  30.                 //break the switch statement
  31.                 break;
  32.                
  33.             //if user input 'b' or 'B'
  34.             case 'B':
  35.                 //get user input
  36.                 getInput(num1 , num2);
  37.                
  38.                 //output the different
  39.                 cout <<"different is " << num1 - num2 << endl;
  40.                
  41.                 //break switch statement
  42.                 break;
  43.                
  44.             //if user input 'k' or 'K'
  45.             case 'K':
  46.                 //output program termination
  47.                 cout << "program terminated" << endl;
  48.                
  49.                 //break the switch statement
  50.                 break;
  51.                
  52.             //all other character besides 'k' , 'l', 'b' OR 'K', 'L', 'B'
  53.             default:
  54.                 //output invalid prompt
  55.                 cout << "invalid input, please try agaon" << endl;
  56.         }
  57.         
  58.     } while( toupper(choice) != 'K'); //program ended if user entered 'K' or 'k'
  59.    

  60.     return 0;
  61. }
  62.    
  63. //function
  64. void getInput(int &arg1, int &arg2)
  65. {
  66.     cout << "please enter two integer :";
  67.     cin >> arg1 >> arg2;
  68. }
复制代码

[ 本帖最后由 onlylonly 于 6-11-2009 09:55 PM 编辑 ]
回复

使用道具 举报

发表于 6-11-2009 09:40 PM | 显示全部楼层

回复 102# mash143 的帖子

psedurocode 并非真正的 langauge, 因此, syntax 是随意的。 没有一个真正的规格, 但是大部分人都倾向某些广为人用的 syntax。


因此在psesurecode 里

goto 对
go to 也对
回复

使用道具 举报

发表于 6-11-2009 09:42 PM | 显示全部楼层

回复 104# onlylonly 的帖子

哦。原来是这样的。那么使用toupper 就要include ctype.h 对吗 ?
回复

使用道具 举报

发表于 6-11-2009 09:43 PM | 显示全部楼层

回复 101# spannar90^_^ 的帖子

我們都知道電腦擅長於各種數字的計算,可是,我們又知道各種程式語言的變數又都有上限,比如整數只有2^16 或 2^32 個。如果要計算更大的數字時又該如何計算呢? 就交給聰明的您來解決囉。

以 + 代表加法
以 - 代表減法
以 * 代表乘法
以 / 代表除法 (取商數)



Input :
兩個正整數的運算式,運算元及運算子之間以空格隔開

Output :
兩個正整數的運算結果,總長度不超過 500 個位數

Sample Input :help


2222222222222222222222222 + 1111111111111111111111111
2222222222222222222222222 - 1111111111111111111111111
2222222222222222222222222 * 1111111111111111111111111
2222222222222222222222222 / 1111111111111111111111111

Sample Output :

3333333333333333333333333
1111111111111111111111111
2469135802469135802469135308641975308641975308642
2



你可以试看这个题目。

[ 本帖最后由 mash143 于 6-11-2009 09:45 PM 编辑 ]
回复

使用道具 举报

Follow Us
发表于 6-11-2009 09:45 PM | 显示全部楼层

回复 105# mash143 的帖子

对, 是 ctype.h 不是 stdlib.h

我搞错了
回复

使用道具 举报

发表于 6-11-2009 09:46 PM | 显示全部楼层

回复 107# onlylonly 的帖子

不要误会。不是针对哦。
回复

使用道具 举报


ADVERTISEMENT

发表于 6-11-2009 09:51 PM | 显示全部楼层

回复 108# mash143 的帖子

没什么好误会的, 写程式是有人替你找到bug, 你高兴还来不及呢。
回复

使用道具 举报

 楼主| 发表于 6-11-2009 09:54 PM | 显示全部楼层

回复 103# onlylonly 的帖子

哇。那么长@@果然很大分别。不过我该写哪一个output?因为它给的就是这养的。
回复

使用道具 举报

 楼主| 发表于 6-11-2009 09:56 PM | 显示全部楼层
原帖由 spannar90^_^ 于 6-11-2009 05:48 PM 发表
啊,有一个问题要问你,

#include
main()
{ float y;
  y=(float)20/3;
printf("%f\n",y);
printf("%.2f\n',y);
printf("S.2f\n",y);
printf("%-S.2f\n",y);
return 0;
}
当我去用C++时。他有出output。 ...

我该用哪一个output?
他给的已经是死板。
回复

使用道具 举报

发表于 6-11-2009 09:59 PM | 显示全部楼层

回复 110# spannar90^_^ 的帖子

其实这程式代码不很长, 是我在每一行加入了 comment, 好让你能够理解。

要那一种就看题目是 c, 还是 c++ 咯。

所以我建议你搞清楚你的课程, 教的是 c, 还是 c++ 。 因为这是两种不同的 language 来的。
回复

使用道具 举报

 楼主| 发表于 6-11-2009 09:59 PM | 显示全部楼层
#include<stdio>
void main[]
{int score[10], I, sum, num;
float ave;
sum=0
printf(“1: Please input number of student.=> “);
scanf(“%d”, &num);
for (i=0;i<num;i++)
{
printf(“1: input score here => “
scanf(“%d”, &score);
sum += score;
}
ave= (float)sum/(float)num;
printf(“The average is %6.2f \n”,ave);
}
然后这个题目,我只知道<stdio.>要加h.,void main()
其他就看不出来


[ 本帖最后由 spannar90^_^ 于 6-11-2009 10:04 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 6-11-2009 10:01 PM | 显示全部楼层

回复 112# onlylonly 的帖子

那个题目是六年前题目。现在,我老师出的paper是比较low的。啊!
回复

使用道具 举报

发表于 6-11-2009 10:14 PM | 显示全部楼层

回复 113# spannar90^_^ 的帖子

下次你在贴 code 是, 可以考虑[code]#include <stdio.h>
//blah ...................[/code]这样, 你的 code 会比较容易读, 而且[i] 也不会变成 italic
回复

使用道具 举报

 楼主| 发表于 6-11-2009 10:18 PM | 显示全部楼层

回复 115# onlylonly 的帖子

你所谓说的那个是马上可以检查的吗?还是比较方便读?
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 6-11-2009 10:19 PM | 显示全部楼层
你们除了pro这行的。ICT你们也是很强吗?
回复

使用道具 举报

 楼主| 发表于 6-11-2009 10:26 PM | 显示全部楼层
我的paper exam1是programming和ict。ict是问普通的问题。不过某一些就和bio有关的问题,尤其是病装问题。好怕怕
回复

使用道具 举报

发表于 6-11-2009 10:36 PM | 显示全部楼层
答案如下

#include<stdio.h>

int main()
{
    int score[10], i, sum, num;
    float ave;
   
    sum=0;
   
    printf( "1: Please input number of student.=> ");
    scanf("%d", &num);
    for (i=0;i<num;i++)
    {
        printf("1: input score here => ");
        scanf("%d", &score[ i ]);
        sum += score[ i ];
    }
    ave= (float)sum/(float)num;
    printf("The average is %6.2f \n",ave);
   
    return 0;
}
回复

使用道具 举报

 楼主| 发表于 6-11-2009 10:38 PM | 显示全部楼层
不好意思,让你考考眼力。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 5-12-2025 05:54 AM , Processed in 0.114295 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表