D
D
Durilka962020-11-19 18:56:03
OOP
Durilka96, 2020-11-19 18:56:03

Why is V::set() not a member of "V"? Where is the mistake?

I can't find the error, can you tell me where?

// Выполнил   Вариант №21
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>

class V {
  float y;

public:
  V();
  V(const V &);

  V(float yn) {
    y = yn;
  }

  float inc() {
    return++y;
  }
  friend void inc(V&);
  friend int cmpL(V, V);
  void set(int);
  V div(V, V);
};

V::V(const V &p) {
  y = p.y;
}

V V::div(V p1, V p2) {
  V rez(0);
  if (p2.y != 0) {
    rez.set(p1.y / p2.y);
  }
  return rez;
}

void inc(V& p) {
  printf("%i\n", p.y);
}

int cmpL(V p1, V p2) {
  if (p1.y < p2.y) {
    return p1.y;
  }
  else {
    return p2.y;
  }
}

void V::set() {
  y = z;
}

void main() {
  system("chcp 1251");
  printf("Программу выполнил  Вариант №21\n");
  V *p1, *p2;
  p1 = new V(13);
  p2 = new V(22);
  V p3(20);
  inc(*p1);
  p2->set(16);
  inc(*p2);
  p3 = p3.div(*p1, *p2);
  inc(p3);
  printf("%i\n", cmpL(*p1, *p2));
  system("pause");

}

The tasks to be performed are:
1. Define a class constructor.
2. Define a class copy constructor using the external method of defining it.
3. Make the inc component function friendly.
4. Define two pointers (p1 and p2) to class objects and initialize them.
5. Display the values ​​of the y component of p1 using
a friend function.
6. Define a set component function that allows you to change the value
of the y component.
7. Write a set function call statement for the p2 object.
8. Write a div component function (using an external definition) that divides the values ​​of the y components of p1 and p2, and
returns the result. Display the result on the screen.
9. Write a cmpL friend function that compares less than
the values ​​of the y components of objects p1 and p2 and returns the result. Display the result on the screen.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2020-11-19
@galaxy

You have set() declared like this void set(int);, implemented like this void V::set() {, and called like this rez.set(p1.y / p2.y);(i.e. set(double)).

J
jcmvbkbc, 2020-11-19
@jcmvbkbc

Where is the mistake?

The fact that the class declares void set(int)a is defined by -- void V::set(). The declaration must match the definition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question