Homework

I can't get the below code to compile and run, I keep getting a LNK2019 error in visual studio. Does anyone know why this is? The goal for this question is to tell the output of the program. Below is the code for the program.

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

#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

class temporary
{
public:
	void set(string, double, double);
	void print();
	double manipulate();
	void get(string&, double&, double&);
	void setDescription(string);
	void setFirst(double);
	void setSecond(double);
	string getDescription() const;
	double getFirst()const;
	double getSecond()const;
	temporary(string = "", double = 0.0, double = 0.0);
private:
	string description;
	double first;
	double second;
};


#include <iostream>
#include <iomanip>
#include "junk.h"
using namespace std;

int main() {
	temporary object1;
	temporary object2("rectangle", 8.5, 5);
	temporary object3("circle", 6, 0);
	temporary object4("cylinder", 6, 3.5);
	cout << fixed << showpoint << setprecision(2) << endl;
	object1.print();
	object2.print();
	object3.print();
	object4.print();
	object1.set("sphere", 4.5, 0);
	object1.print();

}

closed account (E0p9LyTq)
What is the exact error you are getting?

A LNK2019 error is an unresolved external symbol error, likely the way you have your project/solution set up in VS.
These are the three exact errors I'm getting.

1>junk.obj : error LNK2019: unresolved external symbol "public: void __thiscall temporary::set(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double,double)" (?set@temporary@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@NN@Z) referenced in function _main

1>junk.obj : error LNK2019: unresolved external symbol "public: void __thiscall temporary::print(void)" (?print@temporary@@QAEXXZ) referenced in function _main

1>junk.obj : error LNK2019: unresolved external symbol "public: __thiscall temporary::temporary(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double,double)" (??0temporary@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@NN@Z) referenced in function _main
closed account (E0p9LyTq)
You have declared your temporary class, where are the methods being defined?

You don't have any of the class methods (functions) with their code shown.
This is all the code in the text book provided me, I'm not sure what to do to make this print.
closed account (E0p9LyTq)
If you don't include the code for your class methods, VS won't be able to find it.
Hmm...since this is the exact code given, do you think that the answer to this question is that it doesn't print anything because the class has no defined member functions?
closed account (E0p9LyTq)
It doesn't print anything because the code fails to compile.
Topic archived. No new replies allowed.