Hi, first of all i'm sorry I didn't include details about the problem i'm having in the title but it feels hard to explain without a wall of text & code for reference, plus the question I have to do for context.
Question (inb4 dwight schrute)
A class called 'sample' with the data a, b and c and two methods as defined below. Define a new member method 'term()' which calculates the value of the term (2b - 4ac) and displays it.
Define the method outside of the class definition. Write the main method to create an array of 2 objects called D of class 'sample' and display the values and find the solution to the term (2b - 4ac)
Code
#include <iostream>
using namespace std;
class sample {
int a, b, c;
public:
void setdata(void)
{
cout << "Enter values of a, b and c: ";
cin >> a >> b >> c;
cout << "\n";
};
void display(void)
{
cout << "\nData a ,b ,c : " << endl;
cout << a << b << c << endl;
};
int term();
};
int sample::term();
int term(int a, int b, int c)
{
int result = (2*b - 4*a*c);
return result;
};
int main()
{
sample d[2];
d.setdata();
d.display();
d.term();
}
You can probably spot a few very obvious errors straight off the bat, and as for what the problem is right now i'm not sure, all I know is what the error messages tell me. Here are the errors I am getting.
Errors
*Line 27 Error: declaration of 'int sample::term()' outside of class is not definition
Line 38 Error: request for member 'setdata' in 'd', which is of non-class type 'sample[2]'
Line 39 Error: request for member 'term' in 'd', which is of non-class type 'sample[2]'*
That's all, thanks for reading if you did. I know it is a bit of a TL;DR.