Jump to content
  • Advertisement
Sign in to follow this  

OOP Problem

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm trying to make a very simple OOP program and I'm getting errors that I don't understand. I just started OOP and this is my first attempt. Please help mefind my problem or at least explain what the compiler error means. Any crticism of code is also welcome. By the way this is c++ using Visual C++. Code:
#include<iostream>
using namespace std;


class Book{
public:
	string L_Name, F_Name, Title, Pub_City, Ed, Year, Pub_Comp;
	int a, b, c, d, e, f, g, x;
	string Make_Bib(string, string, string, string, string, string, string, int, int, int, int, int, int, int, int);
	string Get_Values(string, string, string, string, string, string, string, int, int, int, int, int, int, int, int);
};

string Book::Get_Values(std::string, std::string, std::string, std::string, std::string, std::string, string, int, int, int, int, int, int, int){
	cout<<"If you don't know one piece of information put "unknown".  Press enter after each entry.\n"
	cout<<"Author's Last Name: ";
	getline (cin, L_Name);
	cout<<"Author's First Name: ";
	getline (cin, F_Name);
	cout<<"Title of Book: ";
	getline (cin, Title);
	cout<<"Publishing City: ";
	getline (cin, Pub_City);
	cout<<"Edition: ";
	getline (cin, Ed);
	cout<<"Year of Publication: ";
	getline (cin, Year);
	cout<<"Publishing Company: ";
	getline (cin, Pub_Comp);
	if (L_Name=="unknown")
		a=0;
	else
		a=1;
	if (F_Name=="unknown")
		b=0;
	else
		b=10;
	if (Title=="unknown")
		c=0;
	else
		c=100;
	if (Pub_City=="unknown")
		d=0;
	else
		d=1000;
	if (Ed=="unknown")
		e=0;
	else
		e=10000;
	if (Year=="unknown")
		f=0;
	else
		f=100000;
	if (Pub_Comp=="unknown")
		g=0;
	else
		g=1000000;
	x=a+b+c+d+e+f+g
}



string Book::Make_Bib(std::string L_Name, std::string F_Name, std::string Title, std::string Pub_Comp, std::string Year, std::string Ed, std::string Pub_City, int a, int b, int c, int d, int e, int f, int g){
switch (x)
case 100:
	cout<<Title;
	break;
case 111:
	cout<<L_Name;
	cout<<", ";
	cout<<F_Name;
	cout<<". ";
	cout<<Title;
	cout<<".";
	break;
case 10111:
	cout<<L_Name;
	cout<<", ";
	cout<<F_Name;
	cout<<". ";
	cout<<Title;
	cout<<". ";
	cout<<Ed;
	cout<<".";
	break;
case 1001111:
	cout<<L_Name;
	cout<<", ";
	cout<<F_Name;
	cout<<". ";
	cout<<Title;
	cout<<". ";
	cout<<Pub_City;
	cout<<": ";
	cout<<Pub_Comp;
	cout<<"."
	break;
case 1101111:
	cout<<L_Name;
	cout<<", ";
	cout<<F_Name;
	cout<<". ";
	cout<<Title;
	cout<<". ";
	cout<<Pub_City;
	cout<<": ";
	cout<<Pub_Comp;
	cout<<", ";
	cout<<Year;
	cout<<".";
	break;
case 1111111:
	cout<<L_Name;
	cout<<", ";
	cout<<F_Name;
	cout<<". ";
	cout<<Title;
	cout<<". ";
	cout<<Ed;
	cout<<". ";
	cout<<Pub_City;
	cout<<": ";
	cout<<Pub_Comp;
	cout<<", ";
	cout<<Year;
	cout<<".";
	break;
default:
	cout<<"Not Enough Info";
	break;
}
int main()
{
	Book book;
	book.Get_Values();
	book.Make_Bib();
	return 0;
}

Compiler Error: 1>------ Build started: Project: Bibliography Maker, Configuration: Debug Win32 ------ 1>Compiling... 1>Bibliography Maker.cpp 1>.\Bibliography Maker.cpp(13) : error C2511: 'std::string Book::Get_Values(std::string,std::string,std::string,std::string,std::string,std::string,std::string,int,int,int,int,int,int,int)' : overloaded member function not found in 'Book' 1> .\Bibliography Maker.cpp(5) : see declaration of 'Book' 1>.\Bibliography Maker.cpp(62) : error C2511: 'std::string Book::Make_Bib(std::string,std::string,std::string,std::string,std::string,std::string,std::string,int,int,int,int,int,int,int)' : overloaded member function not found in 'Book' 1> .\Bibliography Maker.cpp(5) : see declaration of 'Book' 1>.\Bibliography Maker.cpp(134) : error C2660: 'Book::Get_Values' : function does not take 0 arguments 1>.\Bibliography Maker.cpp(135) : error C2660: 'Book::Make_Bib' : function does not take 0 arguments 1>Build log was saved at "file://c:\Documents and Settings\Ryan\My Documents\Visual Studio 2005\Projects\Bibliography Maker\Bibliography Maker\Debug\BuildLog.htm" 1>Bibliography Maker - 4 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Advertisement
When posting code please post it between [source][/source] tags. Right now it's very difficult to read, unless that's how you actually format your code, in which case I would suggest proper formatting.

On to the actual problem you have a bunch of useless, unnamed parameters in Get_Values, get rid of them.

Also you're not actually setting any values in Make_Bib, you're just printing off parameters, all the variables in the class still have their default setting. If Make_Bib's job is just to print out values, make it parameterless as well.

You might also want to consider better naming, usually one-letter variable names are frowned upon.

Share this post


Link to post
Share on other sites
Ok I think your code is overly complicated.

How about replacing "unknown" with an empty string, so people can just hit return. In turn this could simplify the code:


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

class Book {
// why make this public?
//public:
private:
// i use my own naming convention here
string lastName, firstName, title, city, edition, year, publisherCompany;

// hopefully these arent needed =)
//int a, b, c, d, e, f, g, x;

public:
void Make_Bib();
void Get_Values();
};

void Book::Get_Values()
{
cout << "If you don't know one piece of information leave it blank. Press enter after each entry.\n";

cout << "Author's Last Name: ";
getline (cin, lastName);

cout << "Author's First Name: ";
getline (cin, firstName);

cout << "Title of Book: ";
getline (cin, title);

cout << "Publishing City: ";
getline (cin, city);

cout << "Edition: ";
getline (cin,edition);

cout << "Year of Publication: ";
getline (cin, year);

cout << "Publishing Company: ";
getline (cin, publishingCompany);
}



void Book::Make_Bib()
{
if( !lastName.empty() )
cout << lastName << ' ';

if( !firstName.empty() )
cout << firstName << ' ';

if( !title.empty() )
cout << title << ' ';

if( !city.empty() )
cout << city << ' ';

if( !edition.empty() )
cout << edition << ' ';

if( !year.empty() )
cout << year << ' ';

if( !publishingCompany.empty() )
cout << publishingCompany;

cout << '.' << endl;
}

int main()
{
Book book;
book.Get_Values();
book.Make_Bib();

// we dont need this line
// the c++ standard says that main will always return 0 if it doesnt return
// any other value explicitly
// return 0;
}




You will need a bit more logic in your Make_Bib() function to correct the punctuation, but not as much as you were trying to do.

Share this post


Link to post
Share on other sites
Another Error:
I fixed all the compiler errors, tried to run it, and then got a window saying bibliography maker.exe needs to close. I then tried debugging and it says I need binary information to debug.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!