I am a beginner programmer working on an assignment for school. At least most of my code is correct, but I can't get it to run, so I can't start testing things to see what is and isn't working. I'm sure there are some things wrong, but I'm not trying to have anyone do my homework, I would just really like to understand how to link properly and get it running.
I have to use a user made static library and link it to the project. I believe I have done this through project/properties/linker/input/additional dependencies, and adding C:\Users\Josh\Documents\Visual Studio 2010\Projects\studystaticlibrary\Debug\studystaticlibrary.lib
I also added all the project folders into project/properties/c++/general/additional include directories.
The header file shows up under external dependencies, and auto-complete works when using the class in the header.
However, I receive this error message about 10 times for all the class methods except the get methods:
1>Assignment 4.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentWeeklyActivity::Write(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?Write@StudentWeeklyActivity@@QAEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _wmain
1>Assignment 4.obj : error LNK2019: unresolved external symbol "public: void __thiscall StudentWeeklyActivity::Read(class std::basic_istream<char,struct std::char_traits<char> > &)" (?Read@StudentWeeklyActivity@@QAEXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _wmain
and here is my code:
static library: StudentWeeklyActivity.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
|
#ifndef STUDENTWEEKLYACTIVITY_H
#define STUDENTWEEKLYACTIVITY_H
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
class StudentWeeklyActivity {
string *FirstName;
string LastName;
int *credits, *sleeping, *working;
int StudyHomework;
public:
string GetFirstName() const;
void SetFirstName(string first);
string GetLastName() const;
void SetLastName(string last);
int GetCredits() const;
void SetCredits(int cred);
int GetSleeping() const;
void SetSleeping(int sleep);
int GetWorking() const;
void SetWorking(int work);
int GetStudyHomework() const;
void SetStudyHomework(int study);
StudentWeeklyActivity();
~StudentWeeklyActivity();
string GetFullName();
void Read(istream &i);
void Write(ostream& o);
void Report(ostream& o);
};
#endif
|
static library: StudentWeeklyActivity.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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include "StudentWeeklyActivity.h"
#include <iostream>
string StudentWeeklyActivity::GetFirstName() const {
return *FirstName;
}
void StudentWeeklyActivity::SetFirstName(string first){
*FirstName=first;
}
string StudentWeeklyActivity::GetLastName() const {
return LastName;
}
void StudentWeeklyActivity::SetLastName(string last) {
LastName=last;
}
int StudentWeeklyActivity::GetCredits() const {
return *credits;
}
void StudentWeeklyActivity::SetCredits(int cred) {
*credits=cred;
}
int StudentWeeklyActivity::GetSleeping() const {
return *sleeping;
}
void StudentWeeklyActivity::SetSleeping(int sleep) {
*sleeping=sleep;
}
int StudentWeeklyActivity::GetWorking() const {
return *working;
}
void StudentWeeklyActivity::SetWorking(int work){
*working=work;
}
int StudentWeeklyActivity::GetStudyHomework() const {
return StudyHomework;
}
void StudentWeeklyActivity::SetStudyHomework(int study) {
StudyHomework=study;
}
StudentWeeklyActivity::StudentWeeklyActivity(){
FirstName=new string;
credits=new int;
sleeping=new int;
working=new int;
*FirstName="";
LastName="";
*credits, *sleeping, *working, StudyHomework=0;
}
StudentWeeklyActivity::~StudentWeeklyActivity(){
delete FirstName;
delete credits;
delete sleeping;
delete working;
}
string StudentWeeklyActivity::GetFullName(){
string fullname;
fullname=GetFirstName() + " " + LastName;
return fullname;
}
void StudentWeeklyActivity::Read(istream &i) {
i>>*FirstName>>LastName>>*credits>>StudyHomework>>
*sleeping>>*working;
}
void StudentWeeklyActivity::Write(ostream& o) {
o<<*FirstName<<endl<<LastName<<endl<<*credits<<StudyHomework<<
*sleeping<<*working;
}
void StudentWeeklyActivity::Report(ostream& o) {
o<<"Student Activity Report"<<endl<<"-----------------------"<<endl;
o<<endl<<"Name: "<<GetFullName()<<endl;
o<<endl<<setw(12)<<"Activity"<<setw(20)<<"Hours"<<endl;
o<<setw(12)<<"--------"<<setw(20)<<"-----"<<endl;
o<<setw(12)<<"Credits"<<setw(20)<<*credits<<endl;
o<<setw(12)<<"Studying"<<setw(20)<<StudyHomework<<endl;
o<<setw(12)<<"Sleeping"<<setw(20)<<*sleeping<<endl;
o<<setw(12)<<"Working"<<setw(20)<<*working<<endl;
o<<setw(12)<<"Other"<<setw(20)<<168-*credits-*sleeping-*working-StudyHomework<<endl;
o<<setw(12)<<"Total"<<setw(20)<<168<<endl<<endl;
//Analysis
o<<"Analysis"<<endl<<"--------"<<endl;
int studydiff, sleepdiff, workdiff = 0;
studydiff=*credits * 2 - StudyHomework;
sleepdiff=56-*sleeping;
workdiff=*working-20;
o<<endl<<"Studying difference: "<<studydiff*-1<<endl;
if (studydiff<=0)
o<<"OK"<<endl;
else if (1<=studydiff<=4)
o<<"Slightly less than the optimal amount of studying/homework time being spent."<<endl;
else if (5<=studydiff<=9)
o<<"Significantly less than the optimal amount of studying/homework time being spent."<<endl;
else if (10<=studydiff<=19)
o<<"Not enough time being spent on studying/homework. Grades may be affected."<<endl;
else if (studydiff>=20)
o<<"Unsatisfactory. Grades will most likely be affected."<<endl;
else
o<<"Error producing analysis."<<endl;
o<<endl<<"Sleeping Difference: "<<sleepdiff*-1<<endl;
if (sleepdiff<=0)
o<<"OK"<<endl;
else if (1<=sleepdiff<=6)
o<<"Slightly less than optimal."<<endl;
else if (7<=sleepdiff<=14)
o<<"Significantly less than optimal."<<endl;
else if (sleepdiff>=14)
o<<"Unsatisfactory. Student does not get enough sleep."<<endl;
else
o<<"Error producing analysis."<<endl;
o<<endl<<"Working difference: "<<workdiff*-1<<endl;
if (workdiff<=0)
o<<"OK"<<endl;
else if (1<=workdiff<=4)
o<<"Slightly too much work."<<endl;
else if (5<=workdiff<=9)
o<<"This amount of work could affect grades."<<endl;
else if (10<=workdiff<=19)
o<<"Hard to do this amount of work and be a full-time student."<<endl;
else if (workdiff>=20)
o<<"Way too much work for a full-time student. Grades will most likely be affected."<<endl;
else
o<<"Error prdocing analysis."<<endl;
}
|
sorry this is so long, I have to put the main cpp in another post, just over the limit.