constructor failing and multiple errors

Write your question here.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include "Workout.h"
using namespace std;


int main()
{
    string name;
    int repetition;
    
    
    cout << "\t\t Bicept Curls"<<endl;
    cout << "Please enter your name and the times did you work out: ";
    cin >> name >> repetition;
    
    Workout lifter;
    lifter.setName( name );
    lifter.repeatMany( repetition );
    
    cout << lifter.name() << ", your Bicept Curls excercise moment right now is:";

    return 0;
}



workout.cpp
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
#include <iostream>
#include <string>
#include "worKout.h"
using namespace std;

Workout::Workout()
{
    myName = "?name?";
    myRepetitionCount = 0;
    mySetCount = 0;
}


Workout::Workout(string initName, int repetition, int set)
{
    myName = initName;
    myRepetitionCount = repetition;
    mySetCount = set;
}

void Workout::repeatOnce()
{
    myRepetitionCount = repetition = 1;
}

void Workout::repeatMany(int count)
{
    myRepetitionCount = repetition + repetition*count;
    mySetCount = myRepetitionCount/10;
}

void Workout::displayStats()
{
    return myRepetitionCount;
    return mySetCount;
}

void Workout::clearStats()
{
    myRepetitionCount = 0;
    mySetCount = 0;
}

string Workout::name() const
{
    return myName;
}

void Workout::setName( string initName )
{
    myName = initName;
}



workout.h

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
#ifndef Workout_h
#define Workout_h
#include <string>
using namespace std;

class Workout {
public:
    
    Workout();
    
    Workout(string initName, int repetition, int set);
    
    void repeatOnce();
    void repeatMany(int count);
    
    void displayStats();
    void clearStats();
    
    
    string name() const;
    void setName( string initName );
    
    int repet() const;
    int sets() const;
    
    
private:
    string myName;
    int myRepetitionCount;
    int mySetCount;
    
    
};


#endif /* Workout_h */ 



sample driver:
Workout lifter( "bicept curl" ); // a common workout...
lifter.repeatOnce( );
lifter.displayStats( ); // shows first line of output below
lifter.repeatMany( 8 );
lifter.displayStats( ); // shows second line of output below
lifter.repeatOnce( );
lifter.displayStats( ); // shows third line of output below
lifter.repeatMany( 10 );
lifter.displayStats( ); // shows fourth line of output below
lifter.clearStats( );
lifter.displayStats( ); // shows fifth line of output below


aiming output:
bicept curl- reps: 1 sets: 0
bicept curl- reps: 9 sets: 0
bicept curl- reps: 0 sets: 1
bicept curl- reps: 0 sets: 2
bicept curl- reps: 0 sets: 0



I'm trying to build a project Workout, but coding is keep failing and I don't know why Workout(); constructor is not working. and for some reason, string class is not functioning also.

-------
Undefined symbols for architecture x86_64:
"Workout::repeatMany(int)", referenced from:
_main in main.o
"Workout::setName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in main.o
"Workout::Workout()", referenced from:
_main in main.o
"Workout::name() const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
--------

please guide me.

Last edited on
It looks like you didn't add workout.cpp to your project.

Thannks! solve the problem.
Topic archived. No new replies allowed.