题目实验一C++基本语法.docVIP

  • 19
  • 0
  • 约2.59千字
  • 约 4页
  • 2016-12-15 发布于天津
  • 举报
题 目:实验一:C++基本语法 姓 名: 姚 永 红 学 号: 200308722 班 级: 0387班 专 业: 信息与计算科学 指导老师: 朱 国 仲 日 期: 2006-5-17 实验一:C++基本语法 一、实验目的 1、复习C语言基础语法 2、掌握C++与C语言不同之处 3、熟悉VisualC++6.0或BC3.1编辑器,程序调试环境 二、实验环境 编译器环境:Microsoft Visual C++(6.0及以上版本) 操作系统版本:Microsoft Windows XP/2000/2003 主要硬件:CPU:AMD Sempron(tm) 2400+ Processor 内存:256M—512M BIOS:Phoenix-Award BIOS v6.00PG 硬盘:ST340014A(80G) 三、试验题目 1、比较两个int型数的大小,并输出较小的那个数; 2、比较一个int型数与一个float型数的大小,并输出较大的那个数; 3、输入一个摄氏温度,输出对应的华氏温度; 4、输入公里数,输出对应的英里数; 5、输入一个int数,将其低四位置1 (一)、实现方法: 在程序中自定义一个类,让它包括上述这五个题目内容;然后在一个主函数中实现这五个题目想要的结果。 (二)、实验结果如下图所示: (三)、程序实现的关键代码: #includeiostream.h class Tfirst { public: void smaller(); public: void bigger(); 定义一个类 void dgrree(); 包含题目中 void miles(); 所要求的 void low1(); private: char* str; }; void Tfirst::smaller() { int x,y; str = new char[30]; // 分配空间 str=****************************************; cout(1)strendl please input two int numbers : endl; cinxy; if (xy) cout the small one is: xendl; else coutthe small one is: yendl; } void Tfirst::bigger() { int x; float y; cout(2)strendlplease input a int number : endl; cinx; coutplease input a float number : endl; ciny; if((float) x y) coutthe bigger one is the int number: xendl; else coutthe bigger one is the float number: yendl; } void Tfirst::dgrree() { float C; double F; cout(3)strendl 请输入一个摄氏温度 : endl; cinC;{ F = 9.0/5.0*C+32; cout 转换后的华氏温度为: Fendl; } void Tfirst::miles() { float gl; double yl; cout(4)strendl 请输入一个公里数 : endl; cingl; yl = gl/1.60934; cout 转换后的英里数为: ylendl; } void Tfirst::low1() { int Y_number,B_number,R_number; B_number = 15; cout(5)strendl请输入一个整型数 : endl; cinY_number; R_number = Y_number | B_number; cout低四位置一后变为 : R_numberendl; } void main() { Tfirst s; s.smaller(); s.bigger(); s.dgrree(); 调用类中成员函数 s.miles(); s.low1(); } 四、分析总结 这次是第一次上机做实验,所以老师出的题目都是比较简单的;甚至这些题目用C语言都能做出来。通过这次实验主

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档