Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 11-05-2005, 06:51 PM   #1 (permalink)
Cro
Registered User
 
Join Date: Oct 2005
Posts: 5
OS: XP


Red Faced Help with c++...methods, constructors,arrays, classes...

hi guys.. im just having a nightmare solving this assignment i have.... Ive done quite alot but now im stuck.. i hope somebody can help me... pleaes bare with me:

ok so here is the situation:

1 - i created the CBook.h in which i created definitions for ADT for a book.
- you can see the file code below...im not sure about the authors as it
needs to be an array of up to 4 authors..(i dont think i did that :( )
2 - i also created the CBook.cpp where i wrote the class implementations:
- here im not sure about the "isAuthor" method as it needs to accept
all the values a book object needs and assigns them to the object.
3 - finally the main program the book.cpp file (the driver program).
- the thing that needs to be done here is:

1 - Create an array that contains one author to be used to pass to the setBookInfo method. Declare a signle book object using values you make up. Assign the object values using the setBookInfo method. Display the contents of the object.

2 - Declare an array in the driver program of 15 book objects called bookArray. Declare an integer which keeps track of how many elemnts are in the array. Write a function called populateArray which accepts the book array and a reference argument of the count of how many elements. The function will open the supplied file and assign the book information to book objects wihin the array.

3 - the main program should loop around displaying all the book information read in.

4 - Ask the user to enter the name of an Author. Write a loop that will look to see which books have that author and for each such book displays the book title.

Now here is how the input file looks: without the comments

5 -- this just says that there is 5 records
C++Programing: From Problem Analysis to Program Design -- this is the title
ABC -- this is the publisher
2000 -- this is the year
52.50 -- this is the price
20 -- this is the quantity
1 -- this says that there is one author
Malik, D.S. -- this is the author // and then so on... with the others
Fuzzy Discrete Structures
Physica-Verlag
2000
89.00
10
2
Malik, Davender
Mordeson, John
Fuzzy Mathematic in Medicine
Physica-Verlag
2000
89.00
10
3
Mordeson, John
Malik, Davender
Cheng, Shih-Chung
Harry John and The Magician
McArthur A. Devine Books
1999
19.95
10
3
Goof, Goofy
Pluto, Peter
Headington, Mark
Dynamic InterWeb Programming
GNet
1998
39.99
25
1
Alvin Monkey



the CBook.h file:

Code:
#include <string>

using namespace std;

#ifndef CBOOK_H
#define CBOOK_H

//////////////////////////   1    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
class CBookProperties
{
	public:
		CBookProperties(); //constructor for unassigned
		
		//Gets----------------
		string getTitle() const;
		string getPublisher();
		double getPrice();
		int getQuantity();
		//--------------------

		//Sets----------------
		void setTitle(string title);
		void setPublisher(string publisher);
		void setPrice(double price);
		void setQuanity(int quantity);

		void setBookInfo(string title, string publisher, string authors, int year, double price, int quantity);
		//--------------------

		bool isAuthor(string) const; // for checking if the author name exists
		bool isInStock(int) const; // 
		void makeSale();

		void printInfo(); // displays the information

		static int count;

	private:
		string bookTitle;
		string bookPublisher;
		string authors;
		int publicationYear;
		double price;
		int quantityInStock;
		int numOfAuthors;
};
#endif
the CBook.cpp file:

Code:
#include "CBook.h"
#include <iostream>
#include <iomanip>

using namespace std;

int CBookProperties::count = 0;

//////////////////////////////////////   2   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
CBookProperties::CBookProperties()
{
	bookTitle = "*unassigned*";
	bookPublisher = "*unassigned*";
	authors = "*unassigned*";
	publicationYear = 0;
	price = 0.00;
	quantityInStock = 0;
	numOfAuthors = 0;
}

////////////////////////   3   -   Set Methods   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
void CBookProperties::setTitle(string inTitle)
{
	bookTitle = inTitle;
}

void CBookProperties::setPublisher(string inPublisher)
{
	bookPublisher = inPublisher;
}

void CBookProperties::setPrice(double inPrice)
{
	price = inPrice;
}

void CBookProperties::setQuanity(int inQuantity)
{
	quantityInStock = inQuantity;
}

/////////////////////////   4   -   Get Methods   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
string CBookProperties::getTitle() const
{
	return bookTitle;
}

string CBookProperties::getPublisher()
{
	return bookPublisher;
}

double CBookProperties::getPrice()
{
	return price;
}

int CBookProperties::getQuantity()
{
	return quantityInStock;
}

/////////////////////////   5   -   setBookInfo method   \\\\\\\\\\\\\\\\\\\\\\\\\\/
void CBookProperties::setBookInfo(string inTitle, string inPublisher, string author, int year, double inPrice, 
								  int inQuantity)
{
	bookTitle = inTitle;
	bookPublisher = inPublisher;
	authors = author;
	publicationYear = year;
	price = inPrice;
	quantityInStock = inQuantity;
	//count++;
}

/////////////////////////   6   -   isAuthor method   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
bool CBookProperties::isAuthor(string inName) const
{
	if(authors == inName)
		return true;
	return false;
}

/////////////////////////   7   -   isInStock method   \\\\\\\\\\\\\\\\\\\\\\\\\\\\/
bool CBookProperties::isInStock(int inStock) const
{
	if(quantityInStock >= 1)
		return true;
	return false;
}

/////////////////////////   8   -   makeSale method   \\\\\\\\\\\\\\\\\\\\\\\\\\\\/
void CBookProperties::makeSale()
{
	quantityInStock--;
}

/////////////////////////   9   -   printInfo method   \\\\\\\\\\\\\\\\\\\\\\\\\\\/
void CBookProperties::printInfo()
{
	cout << endl << fixed << showpoint << setprecision(2)
		 << "****************************" << endl
		 << "Title: " << bookTitle << endl
		 << "Publisher: " << bookPublisher << endl
		 << "Year of Publication: " << publicationYear << endl
		 << "Number of Authors: " << numOfAuthors + 1 << endl
		 << "Authors:" << endl << authors << endl
		 << "Price: " << price << endl
		 << "Quantity in Stock: " << quantityInStock << endl
		 << "****************************" << endl << endl;
}
the book.cpp file:

here i played with the main program but im really stuck::

Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include "CBook.h"

using namespace std;

//void populateArray(

void main()
{
	string title;
	string publisher;
	string authors;
	int year;
	double price;
	int quantity;

	int index = 4;

    ifstream infile;
	infile.open("C:\\Documents and Settings\\Magas\\Desktop\\SCHOOL\\C++Assign3\\Assignment3\\bookData2.txt");

	CBookProperties myArray[4];

	//infile >> title >> publisher >> year >> price >> quantity;
	for(int i = 0; i < index; i++)
	{

		getline(infile, title);
		getline(infile, publisher);
		infile >> year;
		infile >> price;
		infile >> quantity;
		
		myArray[i].setBookInfo(title, publisher, authors, year, price, quantity);
	}

	for(int i = 0; i < index; i++)
		myArray[i].printInfo();
}
please if somebody can help me a little bit with the main program ... and please if you can check if i did everything correctly up until now? .... any help is very much appreciated...
Cro is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 04:38 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

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