lil help here

jwilson02

Newbie
Joined
Nov 17, 2004
Messages
87
Reaction score
0
ok im new to the coding scene and im giving my self some homework to help me out with some c++ coding...
I made this problem up. Ok you your library contains anywhere from 10-20 books.. each book has 300-500 pages...however, each book only has 25 words per page. So, what is the least amount of words you can have, and what is the greatest amount of words you can have? im trying to code a program that u enter these parameters, and it spits out 2 answers...least and greatst amount of words.
Pseudocode will help also!

I think i need to this so far...

int books, pages;
final int words;

...then i dont know where to start...LOL
 
Something a little like this

Code:
int minbooks, maxbooks;
int minpages, maxpages;
int wordsperpage;
float minpages, maxpages;

cout << "Enter Minimum number of books";
minbooks << cin; //Can't remember how that 1 works :)

cout << "Enter Maximum number of books";
//read max books

//repeat for pages and words per page

//now mulitply together to get answers

//print answer using cout;

Its hard to do it without writing code :)

I've never seen the final keyword. Don't think its used in C++;

DISCLAIMER: I'm not very good at C++ coding so don't quote me on any syntax :)
 
Code:
class Book
{
    int maxPages;
    int minPages;
}    

class libraryBook : public Book
{
public:
    void ChangeNumberPages(int pages);
    void SeeNumberOfPages( void );
    void SetMinMaxPages(int minimum, int maximum);
    
private:
    int numberOfPages;
};

void libraryBook::ChangeNumberPages(int newPages)
{
    numberOfPages = newPages;
}

void libraryBook::SeeNumberOfPages( void )
{
    cout << "This book has " << numberOfPages << "in it. \n";
};

void SetMinMaxPages(int minimum, int maximum)
{
    minPages = minimum;
    maxPages = maximum;
}

Then just create an array of books. Ah, I see. Hold on...

Also, while we code things for you(which I find fun), you should be learning C++.... final? Are you on crack? :D Just kidding ^_^
 
sorry my bad...final is java based..thanks guys, yeah i know u guys like coding..i found this problem fun too;) Ill think of some more to come...im in the midst of changing from java to c++
 
btw im looking for code that processes all variables possible, then spits out the min and max value...
 
This one's much better:

Code:
#include <iostream>

class libraryBook
{
public:
    void ChangeNumberPages(int pages);
    void SeeNumberOfPages( void );
    void SetMinMaxPages(int minimum, int maximum);
    void WordsPerPage(int wpp);
    int GetMaxPages() { return maxPages; }
    int GetWordsPerPage() { return wordsPerPage; }
    
private:
    int numberOfPages;
    int wordsPerPage;
    int words;
    int maxPages;
    int minPages;
};

void libraryBook::ChangeNumberPages(int newPages)
{
    numberOfPages = newPages;
}

void libraryBook::SeeNumberOfPages( void )
{
    std::cout << "This book has " << numberOfPages << "in it. \n";
};

void libraryBook::SetMinMaxPages(int minimum, int maximum)
{
    minPages = minimum;
    maxPages = maximum;
}

void libraryBook::WordsPerPage(int wordspp)
{
    int wordsPerPage = wordspp;
}    
    
    
    
    
int main()
{
    libraryBook myBook;
    using std::cout;
    using std::cin;
    
    cout << "How many words per page, sir?";
    int wppb;
    cin >> wppb;
    
    myBook.WordsPerPage(wppb);
    
    cout << "How many pages would you like?";
    int nop;
    cin >> nop;
    
    myBook.SetMinMaxPages(nop, nop + 10);
    
    cout << "You have " << myBook.GetMaxPages() * myBook.GetWordsPerPage() << "words\n\n";
    system("PAUSE");
    
}

If I was 100% sure as to what to do, I would - you should figure the rest out. (note - this actually might be an app I find usefull... )
 
looking good...only thing is that i think u missed that 15-20 books needs to be in the equation...so like (15-20books)*(300-500pages)*(25wordsperpages) gives an list of answers....the lowerst and highest are all i need...so would arrays be better?
 
Yeah, create an array. What is your goal - to find how many words in the whole 'library'?
 
well actually...might use somethin like it....say if u were to get a stats message implemented in dm....code would scan shots fired, shots hit, kills, and deaths...find highest score and lowest score from these, output lowest as "Noob Award" Output Highest as "Godlike award" something like that
im sure it will be much more complicated than that but u gotta start somewhere eh?
 
Back
Top