C++开发者转战Objective-C:从C++到iOS编程入门指南

需积分: 12 0 下载量 120 浏览量 更新于2024-07-24 1 收藏 901KB PDF 举报
"《从C++到Objective-C》是一系列针对iOS开发者的文章,旨在帮助那些已经熟悉C++的程序员更好地理解和掌握Objective-C。作者认为,由于Objective-C与C++有相似之处,特别是都具有面向对象的特性,通过C++作为切入点学习Objective-C更为合适。该系列文章并非详尽的手册,而是侧重于通过对比C++来讲解Objective-C的高级概念,例如类的实现、动态机制等。 文章首先提到了Smalltalk,它是面向对象编程的先驱,Objective-C正是在此基础上发展起来的。Objective-C的目标是在C语言的基础上添加面向对象特性,从而克服C语言的局限性。虽然C++是更广为人知的选择,但Objective-C更接近Smalltalk的动态性和灵活性。Objective-C 2.0是该系列文章的基础,强调的是语言本身以及它在Mac OS X开发中的应用,即Cocoa框架。 Cocoa是一个类库,它为Objective-C提供了丰富的工具和API,使得开发人员能够构建高效、现代的Mac应用程序。类比于C++与Qt、Java与Spring的关系,Cocoa和Objective-C构成了开发平台的核心组件。学习者可以通过这一系列文章,不仅了解Objective-C语言,还能掌握如何利用Cocoa库进行实际的iOS开发,提升编程技能和效率。 这个系列文章适合C++开发者转型至iOS开发,或者想要深入了解Objective-C与C++差异的读者。通过对比学习,读者可以更好地理解Objective-C的面向对象特性和设计哲学,为后续深入iOS开发打下坚实基础。"

Create a class called Rational for performing arithmetic with fractions. Use integer variables to represent the private data of the class – the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should store the fraction in reduced form. For example, the fraction 2/4 would be stored in the object as 1 in the numerator and 2 in the denominator. In order to compute the reduced form, you need to write a reduction function which uses the Euclidean algorithm to get the greatest common divisor (GCD) of the numerator and denominator first and then divides GCD to get the reduced numerator and denominator. Provide public member functions that perform each of the following tasks: (a) Subtract a Rational number from the other Rational number. The result should be stored in reduced form. (b) Divide a Rational number by the other Rational number. The result should be stored in reduced form. (c) Print Rational numbers in the form a/b, where a is the numerator and b is the denominator. (d)Compare two Rational numbers to make sure which one is smaller or they are equal. (1 for the first number, 2 for the second number and 0 if they are equal) Please also write a main function to prompt the user to input two Rational numbers . Subtract one number from the other from these two numbers using (a) and then print the result using (c). Divide one number from the other from these two numbers using (b) and then print the result using (c). Compare these two Rational numbers using (d) and indicate which one is smaller or they are equal. 用c++5.11寫出,且使用using namespace std;

2023-06-02 上传