320 likes | 463 Views
程序设计 I 实验. 中山大学 2013-2014 学年 第 2 学期 教师:刘晓铭 学生: 13 级计科 3 班 + 国防生. 基本安排. 无指定教材 随堂实验 在线编程练习 http://soj.me/course_detail.php?course_id=102. 实验 1 : 编程环境与在线测评系统使用. 实验目的 通过上机解题熟悉编程环境,掌握在线测评系统的使用方法。 编程环境 推荐 Dev-C++ or Visual Studio 2008. 实验内容. 安装编程环境 DEVCPP
E N D
程序设计I实验 中山大学 2013-2014学年 第2学期 教师:刘晓铭 学生:13级计科3班+国防生
基本安排 • 无指定教材 • 随堂实验 • 在线编程练习 http://soj.me/course_detail.php?course_id=102
实验1: 编程环境与在线测评系统使用 • 实验目的 • 通过上机解题熟悉编程环境,掌握在线测评系统的使用方法。 • 编程环境 推荐Dev-C++ or Visual Studio 2008
实验内容 • 安装编程环境DEVCPP • 使用网页浏览器打开在线测评系统sicily (http://soj.me),注册帐号,登录后完善帐号信息; • 使用DEVCPP,编写在线系统上指定作业题的对应程序,编译、运行,并观察程序输出 • 在线系统上提交指定的作业题。
实验环境 • 普通PC机,Windows操作系统,C++编程环境DEVCPP
实验评测 • 采用在线评测系统sicily (http://soj.me)对提交的代码进行在线实时评测
作业题1-1 • Problem A+B • Description Your task is to Calculate a + b. • Input The input will consist of a pair of integers a and b, separated by a space in one line. • Output Output a+b in one line. • Sample Input 1 5 • Sample Output 6
作业1-1参考代码(1) #include <cstdio>using namespace std; int main() { int a, b; scanf("%d%d",&a,&b); printf("%d\n",a+b); return 0;}
作业1-1参考代码(2) #include <iostream>using namespace std; int main() { int a, b; cin >> a >> b; cout << a+b << endl; return 0;}
参见问题1 Q:编译后运行.exe程序,一闪而过,看不到输出结果? A:加入system(“pause”)语句,使程序退出前暂停。为使用system函数,需包含进头文件cstdlib #include <iostream>#include <cstdlib> using namespace std; int main() { int a, b; cin >> a >> b; cout << a+b << endl;system(“pause”); return 0;}
参见问题2 Q:编译错误expected ‘;’ before “return”? #include <iostream>using namespace std; int main() { int a, b; cin >> a >> b; cout << a+b << endl return 0;} A:每条语句要以分号(;)结尾
Dev-C++实验步骤 参考教材“1.10 Developing C++ Programs Using Dev-C++”(p23) (0)运行Dev-C++ (1)创建程序 (2)编辑源代码程序 (3)保存源程序 (4)编译 (5)运行程序
Visual C++实验步骤 参考教材“1.9 Developing C++ Programs Using Visual C++”(p17) (0)打开Visual Studio 2008 开始菜单->所有程序->Visual Studio 2008 (1)创建项目 (2)编辑源代码程序 (3)保存源程序 (4)编译 (5)运行程序