C++ Virtual Function, Inheritance and Overloading Questions

已完成 已发布的 Apr 30, 2002 货到付款
已完成 货到付款

I am in need of the answers to the 5 questions listed by 2:00 Wednsday May 1st. All answers must fulfill the question completely. The questions involve C++ Classes, Inheritance, Operator Overloading and Class Templating. There are only two questions which require actual code segments.

## Deliverables

1.(Simple function) Assume that you are given an array arr of integers. Give C++ code for a function max that takes an integer size (which is the size of the array arr) and arr as arguments and returns the maximum element in the array. 2.(Template) Template the function max you wrote in question 1 to work for any type (not just integers). You may assume that the operators =, <, >, <=, o (and whatever else you might need) are already overloaded for every type. 3. (OO design) Consider an (ordinary) calculator that uses "infix" arithmetic, ie. You type 1+2 and press = and you get 3. Assume that it supports +, -, * and / operations. Consider "Arithmetic Expression" (AE) to be a class in this example. Simple examples of AEs are 3+4, 6-5,7*8 and 9/10. Let's call these examples as PlusExpression (PE), MinusExpression (ME), TimesExpression (TE) and DivideExpression (DE), respectively. Thus, we could consider PE, ME, TE and DE to be derived classes of AE. But then, the calculator also allows complicated AEs like 3+4-5. It consists of (3+4)-5, which now contains a PE (3+4), the answer to which is 7) and then a ME (7-5). Thus, sometimes AE could be considered as the base class for PE, ME, TE and DE (example of inheritance). Sometimes it contains combinations of these (example of containment). Here's a problem that has containment and inheritance very much intertwined. How would you model this seemingly inconsistent behavior? Write enough so that it would be a simple matter for a person to translate your idea into code. 4. (Operator Overloading) Given the class stack definition: class Stack { private: // Do not worry about what is here // It is a stack of "char"s public: Stack(); //Constructs stack of 100 elements Stack(n); //Constructs stack of n elements Push(char c); //Push c onto the stack. //If stack is full, does nothing char pop(); //Pops and returns an element from the // stack. If stack is empty, does nothing char top(); //Just returns the top element from stack //Does not pop it off int num(); //Returns the number of elements in stack //For a newly constructed stack the //answer is zero bool IsFull() const; // Is stack full? bool IsEmpty{) const;// Is stack empty? Assume that the above member functions are already implemented. Overload the operator + to operate on two Stacks so that it returns a new Stack where each element is equal to the sum of the respective elements in the two Stacks. You will first need to make sure that the three Stacks have the same number of elements. In other words, you will use it as Stack sl(l), s2(l), s3(l); S3 = s1 + s2; This also means that the old elements of s3 are to be over-written, if necessary. 5. Consider the following program: #include main() { cout<<"Hello,world\n"; } How would you modify it to produce the output: Initialize Hello, World Clean up without changing main () in any way? You must explain where and what exactly you will modify. All questions must be answered completely and submitted as a Microsoft Word Document to receive full compensation.

## Platform

Microsoft Word 97 or higher

## Deadline information

Must be completed by the deadline

C 编程 工程 微软 MySQL PHP 软件构架 软件测试 视窗桌面

项目ID: #2849359

关于项目

8个方案 远程项目 活跃的May 1, 2002

授予:

vw139994vw

See private message.

$7 USD 在14天内
(60条评论)
4.5

有8名威客正在参与此工作的竞标,均价$14/小时

oleg21

See private message.

$17 USD 在14天内
(137条评论)
7.0
sanatanvw

See private message.

$17 USD 在14天内
(72条评论)
5.5
iodra

See private message.

$17 USD 在14天内
(26条评论)
3.8
shuvovse

See private message.

$15.3 USD 在14天内
(11条评论)
3.8
sofivabiz

See private message.

$12.75 USD 在14天内
(6条评论)
3.6
compwizvw

See private message.

$12.75 USD 在14天内
(8条评论)
3.2
talivw

See private message.

$12.75 USD 在14天内
(7条评论)
2.6