1 Attachment(s)
C++ error...cant find it in my code HELP
Code:
//header file
#ifndef MID_TERM_H
#define MID_TERM_H
class Mid_Term
{
public:
//no argument constructor
Mid_Term();
//constructor with arguments
//Mid_Term(color, type);
// member functions
void settype(char type);
void setcolor(char color);
char getcolor();
char gettype();
//data members
private:
char c1;
char t1;
};
#endif
Code:
//function file
#include "mid_term.h"
//no argument constructor
Mid_Term::Mid_Term()
{
c1=' ';
t1=' ';
}
//constructor with arguments
//"set" functions (normally without return type)
void Mid_Term::settype(char a)
{
t1=a;
}
void Mid_Term::setcolor(char b)
{
c1=b;
}
// "get" functions (normally have return type)
char Mid_Term::getcolor()
{
return c1;
}
char Mid_Term::gettype()
{
return t1;
}
Code:
//main file
#include<iostream>
#include<fstream>
#include<iomanip>
#include"mid_term.h"
using namespace std;
void main()
{
//define variables
char aa;
char type;
char color;
char response;
float size;
float price;
char imported;
Mid_Term mt;
//cl /EHsc midtermDriver.cpp
//print title
cout<<"Rebecca Zbyradowski\nCIS326\nMidterm\n\n";
cout<<"Default Object\n\n"<<endl;
cout<<"Type: Cheerleading\nColor: White\nPrice: $39.99\nSize: 9\nThis shoe is imported"<<endl;
cout<<"-----------------------------------------"<<endl;
//set up loop so program can end
do{
cout<<"To Design your own footwear please enter values\n"<<endl;
cout<<"Please select type:\n\n";
//Print Type
cout<<"F:Flipflops\nS:Sandals\nD:Dress\nB:Boots\nT:Tennis\nH:Hiking\nK:Basketball\nC:Casual\nL:Cheadleader\nO:Football\n";
cin>>type;
mt.settype(type);
cout<<"\nPlease select Color:\n\n";
cout<<"W:White\nB:Black\nY:Yellow\nN:Brown\nR:Red\nG:Gray\nP:Purple\nS:Silver\n";
cin>>color;
mt.setcolor(color);
cout<<"\n\nWhat is the size?\n";
cin>>size;
cout<<"\n\nWhat is the price?\n";
cin>>price;
cout<<"Is this footwear imported?\n";
cin>>imported;
cout<<"*** Your footwear specifics***\n\n";
//char type1;
//type1=shoe.gettype();
switch (type)
{
case 'F':
case 'f':
cout<<"Type: Flipflop\n";
break;
case 'S':
case 's':
cout<<"Type: Sandals\n";
break;
case 'D':
case 'd':
cout<<"Type: Dress\n";
break;
case 'B':
case 'b':
cout<<"Type: Boots\n";
break;
case 'T':
case 't':
cout<<"Type: Tennis\n";
break;
case 'H':
case 'h':
cout<<"Type: Hiking\n";
break;
case 'K':
case 'k':
cout<<"Type: Basketball\n";
break;
case 'C':
case 'c':
cout<<"Type: Casual\n";
break;
case 'L':
case 'l':
cout<<"Type: Cheerleader\n";
break;
case 'O':
case 'o':
cout<<"Type: Football\n";
break;
default:
cout<< endl << endl;
cout<< "TYPE: Invalid Choice entered." << endl;
break;
}//end switch
//char color1;
//color1=shoe.getcolor();
switch (color)
{
case 'W':
case 'w':
cout<<"Color: White\n";
break;
case 'B':
case 'b':
cout<<"Color: Black\n";
break;
case 'Y':
case 'y':
cout<<"Color: Yellow\n";
break;
case 'N':
case 'n':
cout<<"Color: Brown\n";
break;
case 'R':
case 'r':
cout<<"Color: Red\n";
break;
case 'G':
case 'g':
cout<<"Color: Gray\n";
break;
case 'P':
case 'p':
cout<<"Color: Purple\n";
break;
case 'S':
case 's':
cout<<"Color: Silver\n";
break;
default:
cout<< endl << endl;
cout<<"COLOR: Invalid choice!"<< endl;
}
cout<<"Price: $"<<price<<endl;
cout<<"Size: "<<size<<endl;
if (imported == 'y')
{
cout<<"The shoe is imported.\n"<<endl;
}
else
{
cout<<"The shoe is made locally.\n"<<endl;
}
cout<<"Do you want to try again? (y/n)\n";
cin>>response;
}while (response != 'n');//end of do while loop
}//end main
I am getting an error when i trry to run it and i cant understand why..HELP
I have screen shot of error...
Re: C++ error...cant find it in my code HELP
Dude or Dudette, please reformat the code in your post. It's terrible and very difficult to read. :thumbd:
Re: C++ error...cant find it in my code HELP
Quote:
Originally Posted by
kempofighter
Dude or Dudette, please reformat the code in your post. It's terrible and very difficult to read. :thumbd:
soryy i was pretty mad at this code...i fixed it
Re: C++ error...cant find it in my code HELP
You are getting linker errors because something in the main function is trying to access something else that wasn't compiled. Did you compile the file containing the mid_term class definition? Aside from the code tags, it would be even easier if you would use the autoformat feature of your code editor to eliminate the unnecessary spacing and bracket alignment issues. Then copy and paste them and apply code tags.
Re: C++ error...cant find it in my code HELP
Quote:
Originally Posted by
kempofighter
You are getting linker errors because something in the main function is trying to access something else that wasn't compiled. Did you compile the file containing the mid_term class definition? Aside from the code tags, it would be even easier if you would use the autoformat feature of your code editor to eliminate the unnecessary spacing and bracket alignment issues. Then copy and paste them and apply code tags.
yea that didnt work....seems noo one knows
Re: C++ error...cant find it in my code HELP
The image you posted indicates very clearly that the compiler has no idea what a Mid_Term class is since the constructor and all of its member functions are unresolved at link time. Are all of the files being compiled within the project? Is mid_term.cpp being compiled? Copy and paste the entire compiler output into a post. The picture is difficult to read. I don't see where it is showing the output of the compiler. I'm only seeing linker output.
Re: C++ error...cant find it in my code HELP
Quote:
Originally Posted by
kempofighter
The image you posted indicates very clearly that the compiler has no idea what a Mid_Term class is since the constructor and all of its member functions are unresolved at link time. Are all of the files being compiled within the project? Is mid_term.cpp being compiled? Copy and paste the entire compiler output into a post. The picture is difficult to read. I don't see where it is showing the output of the compiler. I'm only seeing linker output.
1>------ Build started: Project: newtry, Configuration: Debug Win32 ------
1>Compiling...
1>Skipping... (no relevant changes detected)
1>main.cpp
1>Build log was saved at "file://c:\Users\Becky\Documents\Visual Studio 2008\Projects\newtry\newtry\Debug\BuildLog.htm"
1>newtry - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
all my files come back this way
Re: C++ error...cant find it in my code HELP
You have 2 source files and both of them need to be built then linked together.
It seems strange though that you are using the command-line linker.
By the way, while we are here make main() return int not void and make your two get functions const.