C++转Objective-C:iOS开发者必读的入门教程

4星 · 超过85%的资源 需积分: 0 47 下载量 17 浏览量 更新于2024-07-28 2 收藏 945KB PDF 举报
"《从C++到Objective-C(中文版)》是一本面向iOS、iPhone、iPad和Apple平台开发者的入门教程,特别针对那些已有C++编程经验的开发者。作者DevBean强调,由于Objective-C与C++有紧密的联系,且继承了Smalltalk的面向对象思想,因此他选择以C++作为起点,帮助读者更好地理解和学习Objective-C。这个系列并不旨在提供全面的手册,而是通过对比C++来深入解析Objective-C的高级概念,例如类的实现。 文章首先回顾了Smalltalk的历史,它是第一个真正的面向对象语言,随后衍生出了C++和Objective-C。C++因性能优化而广为人知,而Objective-C则更注重易用性和动态性,特别是在Cocoa框架的支持下,用于MacOSX开发。Cocoa是一个庞大的类库,与Objective-C的关系类似于Qt与C++,以及Spring与Java的关系。 通过本系列,读者将学习到Objective-C的基本概念,如消息传递机制、类别(Categories)、继承和封装等,这些都是Objective-C独有的特性。尽管C#在某些方面与Objective-C更为接近,但作者还是选择C++作为对比,因为C++的背景知识对理解Objective-C有直接的帮助。虽然阅读本系列不能代替深入研究Objective-C的所有细节,但它将为后续的学习提供坚实的基石,帮助读者在阅读其他资料时能更深入地理解Objective-C的精髓。 这是一套适合C++开发者转型iOS开发或初次接触Objective-C的实用教程,通过对比学习,可以帮助读者快速掌握Objective-C的核心概念,并为iOS应用开发打下坚实的基础。"
2023-07-22 上传

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 上传