Hi Everyone I have am doing an object oriented C++ program and I have no idea as to how start it............. ....
This program prints a motion verb ( fly, run, swim, crawl, walk, or roll ), waits for a second,
then prints the name of an entity and repeats the verb (for example: fly ..1s.. pigeon fly!.. ).
The player has ½ second to type ‘y’ for yes or ‘n’ for no. (case insensitive)
- If the answer is correct, the player scores, if incorrect, or if there was no answer within the ½ second, the
player looses a point. When correct, all the motions the entity can perform are printed.
- When wrong, Ka..BOOM! is printed instead.
The default number of questions per player is 20, but the number can be changed by passing a different
number on the command line when starting the program.
At the end of the run the player’s score (and the score of previous players if there were any) is printed, the
question: “Another player (Y/N): “ is asked. The game exits if ‘n’ is typed.
The output should look something like this:-
Player 1 starting.
You must answer with the letter ‘y’ for YES, or ‘n’ for NO.
Press [Enter] when ready to start:
1 – fly pigeon fly!.. y
- I walk - I fly
2 – swim Wheelbarrow swim.. n
- I roll
3 – crawl ball crawl!..
Ka...BOOM!
4 – fly plane fly!.. y
- I roll - I fly.
5 – run boat run!.. n
- I roll.
6 – walk engine walk!..
Ka..BOOM!
7 – roll stone roll!.. y
- I roll.
. . .
16- crawl time crawl!.. y
- I crawl - I fly.
17- swim goose swim!.. n
Ka..BOOM!
18- run lizard run!.. y
- I run - I crawl.
19- run nose run.. y
- I run
20- fly goose fly!.. y
- fly - I walk – I run – I swim.
Player 1 *** score: 16 ***
Well done! Start another player (Y or N)? y
Player 2 starting
You must answer with the letter ‘y’ for YES, or ‘n’ for NO.
Press [Enter] when ready to start:
1 – crawl giraffe crawl!.. y
Ka..BOOM!
I am not that good at coding so i tried and made an overview of what the main driver should look like
main{
start_function( a,b)
{
check here wherther the player is old or new------>Connector
where a = value of yes or no, taken by cin>>
if the vaue is yes....
}
you are back in main >>>here
now start the for...while/Do...while[(condition for 1/2 min)& this shld take care of the initial 30 seconds also]
{
call function2(loop for 20 questions)
else if right answer add a point
Also call a function to print what the object does (for ball, it will be I ROLL)
keep adding ( + or -)points in a variable
End for loop of questions
}
display final score
ask to replay ------------>connector
}
But as said above I have no idea on the coding part of the whole program and would like some help here please
Also apart from this can anyone suggest a good compiler, I use Visual Basic C++ if thats good
May 21 '07
45 3989
ok i ll go through the stuff till u get back then i have to sleep. see ya l8r
Get rid of the *. Make it return a 'string' not a 'string*'.
doesnt work i have to change it in all files ie. motion.h, motion.cc and flymotion.h and after doing that too i am getting more errors which is way out of my understanding!! !
EDIT: P.S. If you want, you can take a look at a preliminary document I am writing regarding Parsing in C++ here. It is in review so that is why it is located in the Editors Corner.
Again, i am not that familiar with parsing so i will have a look 2morrow as soon as i am out of bed since nothing is getting inside at this time of the night. Good night
ps- if u want i can post the errors i get when i change to string from string* , i didnt as there are 4-5 of them and i got confused lookin at them hence put back string*.
AdrianH 1,251
Recognized Expert Top Contributor
Ok, when you state a type (whether it is a return type, parameter type or variable type) there are three ways of declaring it in C++, by value, by reference and by indirection (I'm not sure if indirection is the standard term though).
By value means that you have an object. If you initialise an object by another object a constructor is invoked to initialise the object. If is initialised with another object of the same type the copy constructor is invoked to copy the object. The copy constructor is just a special constructor that takes a const type reference. More on that type later. E.g. -
// Takes a string by value, constructor is invoked in this case (copy
-
// constructor if passed a string).
-
//
-
// Returns a string by value, copy constructor is invoked.
-
string fn1(string param)
-
{
-
return param;
-
}
-
-
int main()
-
{
-
string var1("hello"); // Constructor to init var1 to contain "hello".
-
-
string var2 = "hello"; // Even though this looks like an assignment, it is
-
// still an initialisation, so the same constructor
-
// as above is called.
-
-
string var2(var1); // var1 is a string, so the copy constructor is
-
// invoked.
-
-
string returnValue
-
= fn1(var1); // fn1 is passed var1 which is a string. param is the same
-
// type, thus to initialise param, the copy constructor is
-
// invoked. This is known as passing by value.
-
//
-
// fn1 returns a string, param is also a string, the return
-
// value is initialised using the copy constructor.
-
return 0;
-
}
-
By reference means that you are borrowing the actual object. Thus, if you modify it (and it is not a const type reference), the original object will be modified. Behind the scenes, this may look like a const pointer (see by indirection). It is almost always initialised with an actual object. -
void fn2(string& param1, string const & param2)
-
{
-
param1="bye"; // Not invoking constructor, invoking the assignment operator.
-
// If no assignment operator function defined, it will destroy
-
// var1 and invoke the copy constructor on the memory space of
-
// var1.
-
-
param2="lala"; // Invalid operation, param2 is a constant, thus cannot be
-
// changed. Comment out to get to compile.
-
}
-
-
int main()
-
{
-
string var1("hello"); // Constructor to init var1 to contain "hello".
-
string var2("bye-bye");
-
string& var3(var1); // Init to reference var1 (also known as an alias)
-
string& var4 = var2; // Init to reference var2
-
fn2(var1, var2);
-
-
cout << "var1: " << var1 << endl; // outputs "var1: bye"
-
cout << "var2: " << var2 << endl; // outputs "var2: bye-bye"
-
cout << "var3: " << var3 << endl; // outputs "var3: bye"
-
cout << "var4: " << var4 << endl; // outputs "var4: bye-bye"
-
-
return 0;
-
}
-
By indirection means that you indirectly point at the object you are referring to. To get access to the object, you either use the dereference operator (‘*’), or the member selection operator (‘->’) which is only valid for non-base types. The value of the pointer can be any value between 0 (usually called NULL) and the maximum addressable space value. -
void fn3(string* param1, string const * param2)
-
if (param1 == NULL) {
-
cout << "param1 is NULL" << endl;
-
}
-
else {
-
cout << "param1 points at string '" << *param1
-
<< "'. Its length is " << param1->length()
-
<< ". Adding ' there' to it." << endl;
-
*param1 += " there";
-
}
-
-
if (param2 == NULL) {
-
cout << "param2 is NULL" << endl;
-
}
-
else {
-
cout << "param2 points at string '" << *param2
-
<< "'. Its length is " << (*param1).length() // also valid
-
<< ". Cannot add ' there' to it." << endl;
-
//*param2 += " there"; // INVALID since pointing at a const value.
-
}
-
}
-
-
int main()
-
{
-
string var1("hello");
-
string var2("bye-bye");
-
string* var3(&var1); // Init to point at var1
-
string* var4 = &var2; // Init to point at var2
-
fn3(var1, var2);
-
-
cout << "var1: " << var1 << endl; // outputs "var1: bye"
-
cout << "var2: " << var2 << endl; // outputs "var2: bye-bye"
-
cout << "var3: " << var3 << endl; // outputs "var3: bye"
-
cout << "var4: " << var4 << endl; // outputs "var4: bye-bye"
-
-
return 0;
-
}
-
NOTE: there are no constructors that will convert a string* to a string (although one could theoretically be made, it makes little sense and could result in inadvertent conversions) or a string to a string* (there is no automated way to make such a conversion).
I hope that what I have written will help point you in understanding what you are doing wrong.
Adrian
ok I changed string* to string......... ........ now i get these errors
flymotion.cc: In static member function 'static FlMotion* FlyMotion::inst ance()':
flymotion.cc:li ne 20:error: cannot allocate an object of type 'flymotion'
flymotion.cc:li ne 20:error: because the following virtual functions are abstract:
Motion.h:line 17:error: virtual bool Motion::contain s(std::string) const
AdrianH 1,251
Recognized Expert Top Contributor
ok I changed string* to string......... ........ now i get these errors
flymotion.cc: In static member function 'static FlMotion* FlyMotion::inst ance()':
flymotion.cc:li ne 20:error: cannot allocate an object of type 'flymotion'
flymotion.cc:li ne 20:error: because the following virtual functions are abstract:
Motion.h:line 17:error: virtual bool Motion::contain s(std::string) const
You didn't declare and define bool FIMotion::conta ins(string) const function.
Won't be in for the rest of the day.
Adrian
Won't be in for the rest of the day.
Adrian
hhmmmmmm just when i need u............. o well i aint sleeping for 48 hrs so whenever u come back i ll still be here
Savage 1,764
Recognized Expert Top Contributor
hhmmmmmm just when i need u............. o well i aint sleeping for 48 hrs so whenever u come back i ll still be here
What a irony,eh?
PS:Subscribing
Savage
What a irony,eh?
PS:Subscribing
Savage
better get to work then i was slackin cuz i thought adrian wasnt around, well next post in an hr or so............. ..
You didn't declare and define bool FIMotion::conta ins(string) const function.
the bool FlyMotion::cont ains(string) is declared in Motion.h line 17 but i cant figure out what to define in it?? any suggestions??
- #ifndef MOTION_H
-
#define MOTION_H
-
-
#include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
class Motion
-
{
-
friend ostream &operator << (ostream &out, const Motion &m);
-
-
public:
-
Motion();
-
virtual ~Motion(){};
-
virtual string toString() const = 0;
-
virtual bool contains(const string key) const = 0;
-
};
-
-
-
#endif
- #include <iostream>
-
#include <sstream>
-
#include <string>
-
-
#include "Motion.h"
-
-
ostream &operator << (ostream &out, const Motion &m)
-
{
-
out << "- I " << m.toString();
-
return out;
-
}
- #ifndef FLYMOTION_H
-
#define FLYMOTION_H
-
-
#include <iostream>
-
#include <string>
-
-
using namespace std;
-
-
#include "Motion.h"
-
-
class FlyMotion : public Motion
-
{
-
public:
-
static FlyMotion* instance();
-
virtual string toString() const;
-
virtual bool contains(const string key) const;
-
-
//protected:
-
FlyMotion();
-
FlyMotion(const FlyMotion&);
-
~FlyMotion(){};
-
-
private:
-
static FlyMotion *inst;
-
// return &inst;
-
};
-
-
-
#endif
- #include <iostream>
-
#include <sstream>
-
#include <string>
-
-
#include "FlyMotion.h"
-
-
using namespace std;
-
-
FlyMotion* FlyMotion::inst = 0;
-
-
FlyMotion::FlyMotion()
-
{
-
inst = 0;
-
}
-
-
FlyMotion* FlyMotion::instance()
-
{
-
if(inst == 0)
-
{
-
inst = new FlyMotion;
-
}
-
return inst;
-
}
-
-
-
string FlyMotion::toString() const
-
{
-
ostringstream outStr;
-
-
outStr << Motion::toString() << "fly " << flush;
-
-
return outStr.str();
-
}
------ Build started: Project: Project1, Configuration: Debug Win32 ------
Linking...
FlyMotion.obj : error LNK2019: unresolved external symbol "public: __thiscall Motion::Motion( void)" (??0Motion@@QAE @XZ) referenced in function "public: __thiscall FlyMotion::FlyM otion(void)" (??0FlyMotion@@ QAE@XZ)
FlyMotion.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall FlyMotion::cont ains(class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> >)const " (?contains@FlyM otion@@UBE_NV?$ basic_string@DU ?$char_traits@D @std@@V?$alloca tor@D@2@@std@@@ Z)
FlyMotion.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> > __thiscall Motion::toStrin g(void)const " (?toString@Moti on@@UBE?AV?$bas ic_string@DU?$c har_traits@D@st d@@V?$allocator @D@2@@std@@XZ) referenced in function "public: virtual class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> > __thiscall
FlyMotion::toSt ring(void)const " (?toString@FlyM otion@@UBE?AV?$ basic_string@DU ?$char_traits@D @std@@V?$alloca tor@D@2@@std@@X Z)
LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStar tup
C:\Documents and Settings\Admin\ Desktop\c++\Pro ject1\Debug\Pro ject1.exe : fatal error LNK1120: 4 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Admin\ Desktop\c++\Pro ject1\Project1\ Debug\BuildLog. htm"
Project1 - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: vbian |
last post by:
Hi,
I'm looking for information about companies using dotnet for the next
generation of games. I've been impressed by the managed examples that
come with the dx9 sdk, they're a huge step up from those available with
the dx8 and below sdk's.
There also seem to be a number of books covering this subject, but then
I've still got a copy of "C++ real-time graphics" which probably didn't
inspire the original wolfenstein ;)
If you can...
|
by: noob23434 |
last post by:
Hi all
I've been told that the best platform to make games on (strategy games)
is a c++. I want to start making games using my mac and I was wondering
if anyone could tell me what software is the best to get started with?
Kind regards
Marc
|
by: jaso |
last post by:
Hi,
I'm making this video game in C.
The game contains a player, enemies and bullets. These objects,
which are arrays of structures, are initialized, updated and drawn
in a game loop. Now I am unsure on where to declare these things.
I could declare them in main() like this
#define NUM_ENEMIES 10
#define NUM_BULLETS 20
|
by: JJ |
last post by:
Having done most of the background sql coding I'm now ready to start
designing my asp.net web pages.
A basic question though - is there a way of having 'common' elements on
pages (e.g. a header)?
This used to be done using frames, but I undertand these are now not
advised.
Basically what I want is to have some text/code that is common to all pages,
but that I only need to update in one place?
|
by: YellowFin Announcements |
last post by:
Introduction
Usability and relevance have been identified as the major factors
preventing mass adoption of
Business Intelligence applications. What we have today are traditional
BI tools that don't work
nearly as well as they should, even for analysts and power users. The
reason they haven't
reached the masses is because most of the tools are so difficult to use
and reveal so little
| |
by: =?Utf-8?B?cGNnYW1lcg==?= |
last post by:
Is VB good for game development? Or is C# or some other language better?
I'm a beginner programmer and would like to get into game development. I
can't find any decent tutorials, so links would be very helpful.
Thanks
|
by: Advertiser for `2D Games Development Central` |
last post by:
New to game development? Need a headstart in creating that first game
of yours? Want to meet others who share a passion for playing and
creating games? Need support, but don't know where go for it? Are you
just passionate about games?
2D Game Development Central is a newly founded group on Google Groups
that is dedicated to the creation of games, especially with regards to
2D. We offer you the chance to join a community of newcomers just...
|
by: pereges |
last post by:
I want to begin by making simple 2D games for Dos. What particular
features of C should I look to strengthen ? I am not asking about the
graphics bit but in general.
|
by: Benjamin Vigneaux |
last post by:
Well, I'm very interested in game development, I'm just starting out though,
browsing here and there for tutorials, references, etc.. and learning about
the game development industry...
What i've realized is that, apparently, most of the games out there are
likely to be coded in C++, is this because the language offers features
which are better suited for game development? or just because it has been
out in market for a longer period of...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |