1章节面向对象程序的设计概论.pptVIP

  • 1
  • 0
  • 约8.51千字
  • 约 35页
  • 2017-03-27 发布于四川
  • 举报
1章节面向对象程序的设计概论

华中科技大学计算机学院 李胜利 第一章 面向对象程序设计概论 1.1 OOP(Object-Oriented Programming)的基本思想和有关概念 1.1.1 面向过程程序设计与面向对象程序设计 1.1.2 面向对象程序设计的有关概念 1.2 C++对OOP方法的支持 1.3 C++对C语言的改进 1.4 C++程序的编辑、编译和运行 1.5 C++程序结构的特点 1.6 Visual C++程序运行步骤 小结 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 1.1.1 面向过程与面向对象程序设计 例1.1:输入任意短语或句子,计算短语包含多少个字(word)和字符(character)。注意:输入短语时,字和字之间只能空一格。 #include stdio.h //面向过程程序 void main() { char ch; int wdcount,chcount; wdcount=1; chcount=0; printf(***:Please input any phrase:\n); while((ch=getchar())!=\n) { chcount++; if(ch== ) wdcount++; } printf(\n*:The number of word is %d\n,wdcount); printf(\n*:The number of char is %d\n,chcount); } ***Please input any phrase... I am a teacher. *:The number of word is 4 *:The number of char is 15 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 1.1.1 面向过程与面向对象程序设计(续1) void main() { count A;//定义对象 A.process();//调用公有成员函数 A.display(); } 面向对象程序设计方法 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 1.1.1 面向过程与面向对象程序设计(续2) #include stdio.h #include iostream using namespace std; class count //定义类 { public: //公有成员 count(); //构造函数 void process(); //成员函数 void display(); private: //私有成员 int wdcount,chcount;//数据成员 }; count::count() { wdcount=1; chcount=0; } Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 1.1.1 面向过程与面向对象程序设计(续3) void count::process() //成员函数的实现 { char ch; cout***:Please input any phrase…endl; while((ch=getchar())!=\n) { chcount++; if(ch== ) wdcount++; } coutendl; } void count::display() { cout\n*:number of word is wdcountendl; print

文档评论(0)

1亿VIP精品文档

相关文档