文档详情

《C++程序设计》实验报告模板(刘伟).doc

发布:2015-09-22约6.46千字共12页下载文档
文本预览下载声明
CENTRAL SOUTH UNIVERSITY 《C/C++程序设计》实验报告 实验名称 对象和类的更多内容 学生姓名 甘婷 学生学号 3901120508 专业班级 软件工程1205班 指导教师 刘伟 完成时间 201年月日 实验 练习10.1 代码如下: 头文件:class MyInteger { public: ?int value; ?MyInteger(); ?int getValue(); ?bool isEven(); ?bool isOdd(); ?bool idPrime; ?bool static isEven(int); ?bool static isOdd(int); ?bool static isPrime(int); ?bool static isEven(MyInteger); ?bool static isOdd(MyInteger); ?bool static isPrime(MyInteger); ?bool equals(int); ?bool equal(MyInteger); ?int static parseInt(string); }; ? ?源文件:#includeMyInteger.h int MyInteger::MyInteger() { ?value = 1; } int MyInteger::MyInteger(int newValue) { ?value = newValue; } int MyInteger::getValue() { ?return value; } bool MyInteger::isEven() { ?return(value%2==0); } bool MyInteger::isOdd() { ?return(value%2!=0); } bool MyInteger::isPrime() { ?for(int i=2;i value; i++) ?{ ? return(value % 1 != 0); ?} } bool static MyInteger::isEven(int) { ?return(1%2==0); } bool static MyInteger::isOdd(int) { ?return(1%2!=0); } bool static MyInteger::isPrime(int) { ?for(int i = 2; i 1;i++) ?{ ? return(1 % i !=0); ?} } bool static MyInteger::isEven(MyInteger) { ?return(value%2 == 0); } bool static MyInteger::isOdd(MyInteger) { ?return(value%2 != 0); } bool static MyInteger::isPrime(MyInteger) { ?for(int i =2; ivalue; i++) ?{ ? return( value % i != 0); ?} } bool MyInteger::equals(int) { ?return(value == newValue); } 练习10.3 代码如下: 头文件:#ifndef STACK_H #define STACK_H class StackOfIntegers { public: StackOfIntegers(); bool isEmpty(); int peek(); void push(int value); int pop(); int getSize(); private: int elements[100]; int size; }; #endif 声明:#includeiostream #includeStackOfIntegers.h using namespace std; int main() { StackOfIntegers stack; cout 输入一个整数 :; int value; cin value; ? ? for(int i = 2; i = value; i++) { ? ? ? ? while(value % i == 0); { stack.push(i); value = value / i; } } while(!stack.isEmpty()) cout s
显示全部
相似文档