| |

VerySource

 Forgot password?
 Register
Search
View: 937|Reply: 5

The 2 homework questions left by the teacher, why ca n’t I compile and run? I do n’t understand the questions, pleas

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-16 08:40:01
| Show all posts |Read mode
First, the definition of known classes is as follows:
class Base {
protected:
  int iBody;
public:
  virtual void printOn () = 0;
  Base (int i = 0): iBody (i) ()
};
class Sub1: public Base {
  // ...
public:
  void printOn ();
  Sub1 (int i, char * s);
};
class Sub2: public Base {
  // ...
public:
  void printOn ();
  Sub2 (int i, short s);
};
Try to complete the definition and implementation code of the classes Sub1 and Sub2, so that they can meet
Requirements for the following procedures and the results of the operations described in the comments:
main ()
{
  Sub1 s1 (1000, "This is an object of Sub1");
  Sub2 s2 (2000, 10);
  s1.printOn ();
  // This shows: <1000: This is an object of Sub1>
  s2.printOn (); // Now: <10 and 2000>
 }

 Second, define the class template SortedSet, that is, an ordered collection of elements, the type of the collection elements
The maximum number of sum elements can be determined by the user. Require this type of template to be provided externally
The following three operations:
        insert: add a new element to the appropriate position, and guarantee the collection element
            Prime values ​​do not repeat;
       get: Returns the address of the smallest element larger than the given value. If not, return
            Back to 0
       del: delete the element equal to the given value, and keep the remaining elements
            Orderly.
Reply

Use magic Report

0

Threads

25

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-20 15:27:01
| Show all posts
One
class Base {
protected:
  int iBody;
public:
  virtual void printOn () = 0;
  Base (int i = 0): iBody (i) ()
};
class Sub1: public Base {
  // ...
protected:
  char * pChar;

public:
  void printOn ();
  Sub1 (int i, char * s);
};
class Sub2: public Base {
  // ...
protected:
  short ss;
public:
  void printOn ();
  Sub2 (int i, short s);
};

Sub1 :: Sub1 (int i, char * s)
{
iBody = i;
pChar = s;
}

void Sub1 :: printOn ()
{
printf ("<% d:% s>\n", iBody, pChar);
}

Sub2 :: Sub2 (int i, short s)
{
iBody = i;
ss = s;
}

void Sub2 :: printOn ()
{
printf ("<% d and% d>\n", iBody, ss);
}
// Try to complete the definition and operation code of the classes Sub1 and Sub2, so that they can meet
// Requirements for the following program and the results of the operation described in the comments:
main ()
{
  Sub1 s1 (1000, "This is an object of Sub1");
  Sub2 s2 (2000, 10);
  s1.printOn ();
  // This shows: <1000: This is an object of Sub1>
  s2.printOn (); // Now it displays: <10 and 2000>
 }
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-20 17:45:01
| Show all posts
I wrote the same as above, but why did I compile it and then Execute it? Is it something wrong with my Visual C ++?
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-22 17:09:01
| Show all posts
Endless cycle!
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 11:36:01
| Show all posts
Single step debugging, if not, go to the library to check how to debug.
Reply

Use magic Report

0

Threads

24

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-25 14:00:02
| Show all posts
Homework problems, it is best to do it yourself, debug it yourself, if you find the reason, you will improve.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list