I am totally stuck. I have worked on this for a week. I clean up the bugs and find more. It didn't look too hard to start with. I have to write an OOP program that displays the default info and then asks users for input. I have two headers two function files and a driver file. When I started out adding things slowly, the program compiled but the output from studyCPP was garbage. Not sure how to fix that either.
Here are the last bastions of errors. Everytime I try and fix it, I just cause more.
1>c:\users\shell\documents\visual studio 2008\projects\quiz4-taketwo\lightcpp.cpp(35) : error C2664: 'strncmp' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>StudyCPP.cpp
1>c:\users\shell\documents\visual studio 2008\projects\quiz4-taketwo\studycpp.cpp(29) : error C2664: 'strncmp' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Any help or guidance is greatly appreciated. - Thanks, Mikhala
light.h
#ifndef LIGHT_H
#define LIGHT_H
#include<string>
using namespace std;
class LightBulb
{
public:
//no argument constructor
LightBulb();
//constructer with arguments
LightBulb(string, int);
void setWattage(int);
void setType(string);
int getWattage()const;
string getType()const;
void printL()const;
private:
int w; //wattage
string type;
};//end class LightBulb
#endif
study.h
#ifndef STUDY_H
#define STUDY_H
#include<string>
using namespace std;
#include"Light.h"
class Study:public LightBulb
{
public:
//no argument constructor
Study();
//constructor with arguments
Study(string, int, double, string);
//set functions
void setLength(double);
void setModel(string);
//get functions
double getLength()const;
string getModel()const;
//print function
void printS()const;
private:
double length;
string model;
};//end Study
#endif
lightCPP.cpp
#include "Light.h"
#include <iostream>
#include <string>
using namespace std;
LightBulb::LightBulb()
{
w=75;
type="incandescent";
}//end constructor
LightBulb::LightBulb(string typ, int ww)
:w(ww)
{
type=typ;
}//end constructor
void LightBulb::setWattage(int a)
{
w=a;
}//end setWattage
void LightBulb::setType(string ty)
{
string str[3] = {"Incandescent","Flourescent","LED"};
int n;
for (n=0 ; n<3 ; n++)
if (strncmp (str[n],ty,1) != 0)
{
cout<<("found %s\n",str[n]);
}
}//end setType
int LightBulb::getWattage() const
{
return w;
}//end getWattage
string LightBulb::getType() const
{
return type;
}//end getType
void LightBulb::printL() const
{
cout<<"\nLight Type is: " <<getType();
cout<<"\nWattage is: " <<getWattage();
}//end of print
studyCPP.cpp
#include "Study.h"
#include <iostream>
#include <string>
using namespace std;
Study::Study(string t, int wat, double len, string m)
:LightBulb(t, wat)
{
m="Table Top";
}//end constructor
void Study::setLength(double ln)
{
ln=13.5;
length=(ln>0? ln : 0.0);
cout<<"Length can't be zero or negative! Try again ";
}//end setLength
void Study::setModel(string md)
{
string str[3] = {"Clip-On","TableTop","Hanged"};
int n;
for (n=0 ; n<3 ; n++)
if (strncmp (str[n],md,1) != 0)
{
cout<<("found %s\n",str[n]);
}
}//end setModel
double Study::getLength() const
{
return length;
}//end getLength
string Study::getModel() const
{
return model;
}//end getModel
void Study::printS() const
{
LightBulb::printL();
cout<<"\nLength = " <<getLength();
cout<<"\nModel is: " <<getModel();
}//end print
driver.cpp
#include "Study.h"
#include <iostream>
#include <string>
using namespace std;
void main()
{
cout<<"\n*** Info about Program defined StudyLight ***\n\n";
Study myStudy("incandescent",75,13.5,"TableTop");
myStudy.printS();
cout<<endl<<endl;
//ask for user input
//define variables
int watt;
double len;
string typ, mod;
cout<< "\nEnter wattage ";
cin>>watt;
cout << "\nEnter LightBulb Type ";
cout << "\nI: Incandescent";
cout << "\nF: Flourescent";
cout << "\nL: LED";
cout << endl;
cin>>typ;
cout << "\nEnter Light Model ";
cout << "\nC: Clip";
cout << "\nT: TableTop";
cout << "\nH: Hanged";
cout << endl;
cin>>mod;
cout<< "\nEnter Study Light length ";
cin>>len;
//show Light Study from User input
cout<<"\n*** Info about your Study Light ***\n\n";
Study yourStudy(typ,watt,len,mod);
yourStudy.printS();
cout<<endl<<endl;
}//end main