finding errors i don't know how to fix

I have a homework i need to solve, but i get this in build messages "||=== Build file: "no target" in "no project" (compiler: unknown) ===|"
I don't understand where i did my mistake, and i keep doing the same mistake everytime i do my homework, I need assistance in defining my errors and fixing them.
Thank you!

[/code]
#include <iostream>
#include<cassert>
using namespace std;

class setType
{
private:
int length;
double *p;
public:
void set(int);
void print() const;
setType(int length=1);
bool belongsTo(double);
};

void setType::set(int l)
{
length=l;
delete []p;
p=new double[length];
assert(p!=NULL);
cout<<"Enter the 5 elements of the set: ";
for(int i=0; i<length; i++)
{
cin>>p[i];
}
}

void setType::print() const
{
cout<<"The Element of the set are: {";
for (int i=0; i<length; i++)
{
cout<<p[i]<<" ";
}
cout<<"}";
}

bool setType::belongsTo(double v )
{
for(int i=0; i<length; i++)
{
if(v==p[i])
return true;
}
}
setType::setType(int l)
{
length=l;
delete[]p;
p=new double[length];
assert(p!=NULL);
for(int i=0; i<length; i++)
{
cin>>p[i];
}
}
int main()
{
double value;
setType one;

one.set(5);
one.print();

cout << "Enter a value to check if it is an element of the set or not: ";
cin >> value;

if(one.belongsTo(value))
cout << value << " is an element of the set." << endl;
else
cout << value << " is not an element of the set." << endl;

return 0;
}
What compiler and IDE do you use ?
code blocks , GNU GCC Compiler
closed account (48T7M4Gy)
You were pretty close. I removed the asserts for my convenience. You need to include a destructor which is where the delete [] goes, not where you had it. I deleted the set() method for my convenience too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>

using namespace std;

class setType
{
private:
    int length;
    double *p;
public:
    setType(int);
    void print() const;
    bool belongsTo(double);
};

setType::setType(int l)
{
    length = l;
    p = new double[length];
    
    cout<<"Enter the 5 elements of the set: ";
    for(int i=0; i<length; i++)
    {
        cin>>p[i];
    }
}

void setType::print() const
{
    cout<<"The Element of the set are: {";
    for (int i=0; i<length; i++)
    {
        cout<<p[i]<<" ";
    }
    cout<<"}";
}

bool setType::belongsTo(double v )
{
    for(int i=0; i<length; i++)
    {
        if(v==p[i])
            return true;
    }
    
    return false;
}

int main()
{
    double value;
    setType one(5);
    
    one.print();
    
    cout << "\nEnter a value to check if it is an element of the set or not: ";
    cin >> value;
    
    if(one.belongsTo(value))
        cout << value << " is an element of the set." << endl;
    else
        cout << value << " is not an element of the set." << endl;
    
    return 0;
}
Last edited on
thank you!
Topic archived. No new replies allowed.