当前位置:天才代写 > 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 > 面向对象编程代做 Advanced Data Structures代写

面向对象编程代做 Advanced Data Structures代写

2021-12-07 14:56 星期二 所属: 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 浏览:461

COEN 79 Object-Oriented Programming and Advanced Data Structures

Assignment #3 2 points per question, unless noted

面向对象编程代做 1.The sequence’s insert member function normally puts a new item before the current item. What does insert do if there is no current item?

1.

The sequence’s insert member function normally puts a new item before the current item. What does insert do if there is no current item?

 

 

2.(4 pts)  面向对象编程代做

Modify the following code to generate the given output. Do not modify the main function.

1. #include < iostream >
2. using namespace std;
3.
4. class box {
5.
6. public:
7.   // Constructor definition
8.   box(double l = 2.0, double b = 2.0, double h = 2.0) {
9.       length = l;
10.      breadth = b;
11.      1height = h;
12.      }
13.
14.   double volume() {
15.     return length * breadth * height; }
16.
17. private:
18.   double length;
19.   double breadth;
20.   double height;
21. };
22.
23. int main(void) {
24.   box Box1(3.3, 1.2, 1.5); // Declare box1
25.
26.   box Box2(8.5, 6.0, 2.0); // Declare box2
27.
28.   return 0;
29. }  

Output:

Number of box objects created so far: 1
Number of box objects created so far: 2

 

3.(6 pts)  面向对象编程代做

In the following code, indicate if the selected lines are legal or illegal:

#include <iostream>

class small
{
public:
  small( ) {size = 0;};
  void k() const;
  void h(int i);
  friend void f(small z);

private:
  int size;
};

void small::k() const
{
  small x, y;
  x = y; // LEGAL/ILLEGAL?
  x.size = y.size; // LEGAL/ILLEGAL?
  size = 3; // LEGAL/ILLEGAL?
};

void small::h(int i)
{

};

void f(small z)
{
  small x, y;
  x = y; // LEGAL/ILLEGAL?
  x.size = y.size; // LEGAL/ILLEGAL?
  x.size = 3; // LEGAL/ILLEGAL?
  x.h(42); // LEGAL/ILLEGAL?
};

int main() {
  small x, y;
  x = y; // LEGAL/ILLEGAL?
  x.size = y.size; // LEGAL/ILLEGAL?
  x.size = 3; // LEGAL/ILLEGAL?
  x.h(42); // LEGAL/ILLEGAL?

  return 0;
}

 

 

 

4.(4 pts)  面向对象编程代做

We create an array of fruit in the main function. How can we make sure that for all the items in array fruit_ptr the values of weight and color are equal to 1 and 2, respectively? Please show your solution. Do not modify the main function.

1. class fruit {
2. private:
3.   int weight;
4.   int color;
5. }
6.
7. main() {
8.   fruit * fruit_ptr;
9.   fruit_ptr = new fruit[100];
10. }

 

 

5.

Explain why heap variables are essentially global in scope. Please present an example as well.

 

 

6.

Is it possible to use the keyword “this” inside a friend function? Please explain your answer.

 

7.(4 pts)  面向对象编程代做

Does the following code compile? Does it run? Is there any problem with the code? If yes, how do you fix it?

1. #include < iostream >
2. using namespace std;
3.
4. class Computer {
5.    int Id;
6.
7. public:
8.    Computer(int id) { this -> Id = id; }
9.    void process() { cout << "Computer::process()"; }
10. };
11.
12. class Employee {
13.   Computer* c;
14.
15. public:
16.   Employee() { c = new Computer(123); }
17.   ~Employee() {}
18.   void foo() {
19.   cout << "Employee::foo()";
20.   c -> process();
21.  }
22. };
23.
24. int main() {
25.   Employee ob;
26.   ob.foo();
27.   return 0;
28. }

 

面向对象编程代做
面向对象编程代做

 

 

 

更多代写:cs论文修改  GMAT代考  英国Educational psychology代写  essay代写字数控制  报告Report代写  洛恩州立社区学院代写

合作平台:随笔代写 论文代写 写手招聘 英国留学生代写

 

天才代写-代写联系方式