1,105,344 Community Members

C / C++ FAQ's and Practice problems

Member Avatar
~s.o.s~
Failure as a human
10,399 posts since Jun 2006
Reputation Points: 2,496 [?]
Q&As Helped to Solve: 992 [?]
Skill Endorsements: 72 [?]
Administrator
Featured
 
17
 

Hello to all programmers out there. Considering the growing request for practice problems by the beginners, we ( Me, Joey, Niek, Aaron..) have decided to start a sticky which will host some common practice problems which would help the beginners in understanding the programming concepts in a better way. (Did I mention 'Practice makes a man perfect' ? ;) )

The practice problems enlisted will have their own difficulty level or the skill level required(beginner to expert). However feel free to jump to any of them if you think you are up for it.

Please don't post "Thank you" posts in this thread since this is meant to be used as a guide for all beginners. Also if you have already developed a solution and want to get it verfied, don't post it here -- create a new thread. Any "Thank you", "Help Me", "Spam" posts will be prompty deleted. I hope you understand this.

Some general guidelines while attempting the problems for beginners or those who have just started programming:

  • The use of all non standard headers and functions is discouraged. Implement the problem with only standard C / C++ functions. A list of standard C / C++ functions and headers can be found here.
  • Don't use system("pause") to pause your program if possible. Use getchar( ) if you are using C and cin.get( ) if you are using C++.
  • The prototype of the entry point of the program i.e. the main function is int main( void ) . Anything else is non standard and incorrect. See here for explanation.
  • If possible stay away from using scanf( ) for accepting input from the user. The fgets( ) and sscanf( ) combination works the best here. It also gives you more control over the way you interpret and analyse the user input. For a detailed tutorial look here.
  • Try giving meaningful names to the variables you use. Though it may seem like a lot of work using names like 'my_string' when 'a' seems to be doing the job pretty well, it would save you from a lot of head banging in the future specially when you can tell what a varaible is meant to do in a program just by looking at its name.
  • If possible do initialize variables when you declare them -- especially pointers. It would save you from a lot of trouble when you variables start returning junk values and you have no idea where they came from.
  • After you are done with pointers in your program, don't forget to ground them (set them to NULL) to prevent their inadvertent use after they have lost their meaning or outside their context. This will definately save you from pulling your hair out when the program becomes large and accessing stray pointers would only result in hard to find bugs.
  • Don't forget to check for return values of functions. Even though it may look to you that the function would never fail, if they do, there sure would be some obscure, hard to find bugs. One classic eg. is checking for return value of the malloc function which returns NULL if allocation fails. Ditto for fopen( ) .

Now, some practice problems from my side:

  • Write a program which finds the factorial of a number entered by the user. (check for all conditions) (Beginner).
  • Create a program which generates fibonacci series till a number 'n' where 'n' is entered by the user. For eg. if the user enters 10 then the output would be: 1 1 2 3 5 8 (beginner)
  • Write a program to simulate a simple calculator. It should accept two number from the user along with the required operation to be performed. Addition, Subtraction, Division and Multiplication are the basic operations that should be implemented. Feel free to implement the other operations (Beginner)
  • Create a simple Palindrome checker program. The program should allow the user to enter a string and check whether the given string is a palindrome or not. Only digits and alphabets should be considered while checking for palindromes -- any other characters are to be ignored. (Intermediate)
  • Implement your own strstr function. (Intermediate)
  • Write a program which will print all the pairs of prime numbers whose sum equals the number entered by the user. ( suggested by Aniseed ) (Intermediate)
  • Write a program which will perform the job of moving the file from one location to another. The source and destination path will be entered by the user. Perform the required error checking and handle the exceptions accordingly. (Intermediate)
  • Write a program which performs addition, subtraction, multiplication of matrices. The dimensions of both the matrices would be specified by the user (dynamic memory allocation required). Use of structure or a class to define the matrix would be a good idea. (Expert)

Hope this guide helped you.

--Sanjay

Member Avatar
John A
Vampirical Lurker
5,285 posts since Apr 2006
Reputation Points: 1,896 [?]
Q&As Helped to Solve: 408 [?]
Skill Endorsements: 12 [?]
Team Colleague
 
4
 

Here is my contribution. Many of these problems occur frequently on the forums, but I thought these were worth saving and so I reproduced some of them here.

  • Write a program that allows you to input students' scores and weights. The program should then calculate a weighted average and score based on the data inputted by the user. (Beginner)
  • Make a program that allows the user to input either the radius, diameter, or area of the circle. The program should then calculate the other 2 based on the input. (Beginner)
  • Create a program that implements a database in C++. The fields are hard-coded, and the data is saved in a binary file. Although this isn't really flexibility, you aren't relying on any external libraries or functions. (Beginner)
  • Create a few classes that model playing cards. Then use this framework to create your favorite card game. (Intermediate)
  • Write a program that accepts XHTML, parses and removes the tags. Then it prints out the remaining text. (Intermediate)
  • Write a program which reverses the numerals in an integer, that is 326 becomes 623, etc.. (Intermediate)
  • Create a sophisticated linked list class. You should be able to insert and delete nodes anywhere in the list, and the nodes should have pointers to nodes both in front and behind them. (Intermediate)
  • Create a binary tree which has search and sorting functions. (Expert)
  • Create a Quine, that is, a program that prints out its own source code. (Expert)
Member Avatar
iamthwee
Posting Sage
7,080 posts since Aug 2005
Reputation Points: 1,307 [?]
Q&As Helped to Solve: 595 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 

Personally, the semantics behind a specific programming language do not interest me in the slightest. The link provided is good for extending one's problem solving skills in any programming language.

http://www.topcoder.com/

Sign up and go to > software competitions > problem and set analysis and pit your wits against some of the best in the world.

There was a massive archive of problems from Olympiad Informatics but I can't seem to find it. Hmm.

ithelp
Posting Virtuoso
1,910 posts since May 2006
Reputation Points: 757 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 19 [?]
Banned
 
-2
 

Here is another problem find ten things which you can do in C but not in C++

Member Avatar
jetru
Light Poster
27 posts since Jun 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-3
 

projecteuler.net

for the math freaks!

Member Avatar
thekashyap
Practically a Posting Shark
809 posts since Feb 2007
Reputation Points: 193 [?]
Q&As Helped to Solve: 77 [?]
Skill Endorsements: 0 [?]
 
0
 

Some for graphics ppl:

  • Write a program to draw a rectangle, ellipse, square, circle, point and line based on user input. (Beginner)
  • Write a program to emulate Microsoft Paint. It should be possible to switch between different tools (circle, rectangle, eraser...) using pre-defined key strocks. - Intermediate
  • Write a program to plot a simple x-y graph for a harcoded function (e.g. y=cos(x)). It should be possible to zoom in on any part of the graph. - Intermediate.
  • Write a program to plot a graph of given equation of form y=f(x) and a range for x as command line arguments. (e.g. my_graph_plotter -eq="y=x*x" -xmin=-10, -xmax=10) - Expert. (PS: more to do with equation solving than graphics)
  • Write the classic brick-break-out game. E.g. see DX Ball. - Expert.
Member Avatar
c4swimmers_net
Newbie Poster
2 posts since Apr 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Few Interesting & Challenging programming problems :

Level: Beginners or Newbie C/C++ Programmers

ithelp
Posting Virtuoso
1,910 posts since May 2006
Reputation Points: 757 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 19 [?]
Banned
 
-1
 

Few more
1. How to call a C++ function which is compiled with C++ compiler in C code?
2. When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)
3. How do you initialize a static member of a class with return value of some function?
4. How can one application use same apis provided my different vendors at the same time ?

Member Avatar
chikkubhai
Newbie Poster
4 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Few more
1. How to call a C++ function which is compiled with C++ compiler in C code?
2. When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)
3. How do you initialize a static member of a class with return value of some function?
4. How can one application use same apis provided my different vendors at the same time ?

What are the answers for you questions?

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 81 [?]
Team Colleague
 
0
 

>What are the answers for you questions?
This thread isn't about answers, it's about providing questions for you to answer on your own. If you're having trouble, start your own thread to get help.

Member Avatar
zandiago
Nearly a Posting Maven
2,463 posts since Jun 2007
Reputation Points: 115 [?]
Q&As Helped to Solve: 55 [?]
Skill Endorsements: 0 [?]
Featured
 
0
 

For those who loves games: (beginners)
1. Tic Tac Toe program.
2. how about writing a c++ game that asks the user to guess a number between 1 and a 100. If you guessed correctly, it will say you win. If your too high or too low it will also let you know. i've done this program before, so i can help you with it. If you try your best, we'll help you along.

Member Avatar
everlast
Light Poster
26 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Personally, the semantics behind a specific programming language do not interest me in the slightest. The link provided is good for extending one's problem solving skills in any programming language.

http://www.topcoder.com/

Sign up and go to > software competitions > problem and set analysis and pit your wits against some of the best in the world.

it's extremely interesting, but how does a self-taught beginner like me place oneself in such a great project?

thanx for the link and the advice, i hope to be able to use it some day if i learn hard. :)

Member Avatar
Drezta
Newbie Poster
24 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

those competitions look really interesting especially with the big prizes and tee-shirts lol.

but some tasks that have helped me:

develop a program that uses a randomly generated number to select 1 of 3(or more)
functions to show the user. (simple)

develop a program to convert currency X to currency Y and visa versa (beginner)

Member Avatar
mustafaneguib
Junior Poster
115 posts since Apr 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

hey all, how are you all doing??

i would like to share with you guys some of the inlabs that i have done in my university in the past.

(question 1)

The statement is below of the question. it is quite an easy program, but just one misplaced variable can cause headaches, to many people, like what happened to me an my friends. Though i only asked my lab instructor only after failing to figure out what the problem was in the program.

An integer number is said to be perfect number if its factors including 1 (but not the number itself) sum to the number. For example, 6 is a perfect number because 1+2+3=6. Write a function perfect that determines if parameter number is a perfect number, and returns a boolean value true if number is perfect other wise returns false. Use this function in a program that prints perfect numbers between 1 and 1000.

Note: Don’t take any input from user

use functions. you dont need to use any pointers or any advanced level of c++. this was supposed to be a basic program to teach us how to use functions.


(question 2)

i havent tried this question as it was given to the other section from mine, but never the less i copied the file ad brought it hoping to try the problem when i get the time.
This is also a simple program to make.

A new firm has been setup in the city, which sells wooden panels. The firm provides to the customers with services to repair and tile the walls. You are asked to write a program for the firm to print Bills for the customers. The bills include the detail of total cost of tiling the walls. Input to program is the measurements of the room i.e length and width of the wall of the room to be tiled. The bill is then calculated based on following details.
• The wooden panels come in two sizes in width i.e. one-foot panel and 3-inches panel.
• The length/height of the panels can be of any size, according to the height of the wall.
• Number of one-foot and 3-inches panel required to cover the wall depends on the width of the wall.
• Width of the wall is measured in feet and inches.
• Height of wall is measured in feet (assuming that measurements do not include fractions).
• Some part of the wall may be left uncovered if it is less than 3 inches in width.
• Cost of the panels depends on the length/height of the panel. One-foot panel costs 10 Rs. per feet, and 3-inches panel costs 5 Rs. per feet.
To write the program, you need to implement following functions.
• Function to take input: This function takes input for height of the room and width of the two walls. You need to use reference parameters in this function and it will be a void function.
void input (int & feet_wall, int & inches_wall,
int & lenght)
• Function to calculate number of one-foot and 3-inches panels required for the room: As this function calculates more than one value, you need to implement this function using reference parameters.
void NumberOfPannels (int feet_wall, int inches_wall, int length, int & numberofOne_footPanel,
int & numberof3-inchesPanel )
• Function to calculate the total cost. This function also needs reference parameters, as the cost of two types of are required to be calculated separately, which are later required in other function.
void Cost (int numberofOne_footPanel,
int numberof3-inchesPanel, int length, int & costOfOneFootPanel, int & costOf3-inchesPanel )
• Function to print the Bill. This will be a void function which needs not to return any value. The function should print the bill in following format.
BILL:
Height of wall: 8 feet
Width of wall:
Feet: 12 feet
Inches: 8 inches
No of one-foot panels required: 12 panels
No of 3-inches panels requires: 2 panels
Length of panels: 8 feet
Cost of one-foot panels: 960 Rs.
Cost of 3-inches panels: 80 Rs.
Total Cost: 1040 Rs.
The main function should not contain any functionality. It should consist of series of function calls.

thats all for now, i hope to bring more new stuff and share more programs.

Member Avatar
invisal
Posting Pro
568 posts since Mar 2005
Reputation Points: 292 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 0 [?]
 
3
 

Text-based Role-Playing Game Project (For Beginners)
Firstly, this game will start with an introductatory storyline of the game to attract player interest. Then, it asks a player to enter his or her name and which class the player want to choose. There are going to be 3 classes for player: Warrior, Mage and Archer. Each class has it own unique abilities.

Class System

  • Warrior:

    Having the high hitpoint and equip with heavy weapons and armors.
    Starting State:

    • Hitpoint: 50 (increased by 10+level*7 for each level)
    • Mana: 10 (increased by 1.25*level for each level)
    • Attack: 20 - 25 (increased by 2*level for each level)

    Skill:

    • Evading: (Passive)
      • Level 1: Raise Defense level by 10%. If a shield is not equipped, the effect will decrease by half.
      • Level 2: Raise Defense level by 15%. If a shield is not equipped, the effect will decrease by half
      • Level 3: Raise Defense level by 25%. If a shield is not equipped, the effect will decrease by half
    • Sword Dance: (Active)
      • Level 1: Swinging your sword rapidly cause the target to get hitted 2 times. (cost 5 mana)
      • Level 2: Swinging your sword rapidly cause the target to get hitted 3 times. (cost 8 mana)
      • Level 3: Swinging your sword rapidly cause the target to get hitted 4 times. (cost 12 mana)
    • Shock Stun: (Active)
      • Level 1: Concentrate all your energy force into your weapon and hit hardly to the target cause them unable to move in the next turn and deal 100 damage (cost 10 mana)
      • Level 2: Concentrate all your energy force into your weapon and hit hardly to the target cause them unable to move in the next turn and deal 300 damage (cost 18 mana)
      • Level 3: Concentrate all your energy force into your weapon and hit hardly to the target cause them unable to move in the next 2 turn and deal 500 damage (cost 25 mana)
  • Mage:

    Born with an intellegent mind able to understand the using of force of nature in the battle.
    Starting State:

    • Hitpoint: 20 (increased by 5+level*2.5 for each level)
    • Mana: 30 (increased by 3*level for each level)
    • Attack: 5 - 10 (increased by 0.75*level for each level)

    Skill:

    • Hell Fire: (Active)
      • Level 1: Burn your target with a incredible flame, the target recieve 150 damage and another 25 damages for the next time. (cost 10 mana)
      • Level 2: Burn your target with a incredible flame, the target recieve 250 damage and another 25 damages for the next 2 time. (cost 20 mana)
      • Level 3: Burn your target with a incredible flame, the target recieve 350 damage and another 35 damages for the next 3 time. (cost 30 mana)
    • Frostbite: (Active)
      • Level 1: Frozen your target deal 100 damage and the target damage will be reduce by 20% in the next turn. (cost 7 mana)
      • Level 2: Frozen your target deal 150 damage and the target damage will be reduce by 30% in the next turn. (cost 9 mana)
      • Level 3: Frozen your target deal 200 damage and the target damage will be reduce by 65% in the next turn. (cost 12 mana)
    • Thunder Burst: (Active)
      • Level 1: Call the force of Thunder and Lightening to hit the target. Dealing 50 damages and having 20% chance of stunning the target so that it unable to move in the next turn. (cost 5 mana)
      • Level 2: Call the force of Thunder and Lightening to hit the target. Dealing 100 damages, having 35% chance of stunning the target so that it unable to move in the next turn and having 20% chance of drain 20% of the target max hitpoint. (cost 8 mana)
      • Level 2: Call the force of Thunder and Lightening to hit the target. Dealing 150 damages, having 50% chance of stunning the target so that it unable to move in the next turn and having 50% chance of drain 35% of the target max hitpoint. (cost 15 mana)
  • Archer:

    Having the advantage of shooting from distance give Archer an ability to shoot 2 times before the battle begin.
    Starting State:

    • Hitpoint: 25 (increased by 5+level*3 for each level)
    • Mana: 5 (increased by 1.5*level for each level)
    • Attack: 30 - 40 (increased by 3*level for each level)

    Skill:

    • Dodge: (Passive)
      • Level 1: With his flexible movement, giving him 10% chance of dodge the attack and 30% chance of reduce 20 damages.
      • Level 2: With his flexible movement, giving him 20% chance of dodge the attack and 30% chance of reduce 30 damages.
      • Level 3: With his flexible movement, giving him 30% chance of dodge the attack and 30% chance of reduce 40 damages.
    • Accurate: (Passive)
      • Level 1: Increasing his aim accuracy. Giving him 20% chance of dealing 1.25x critical hit.
      • Level 2: Increasing his aim accuracy. Giving him 30% chance of dealing 1.50x critical hit.
      • Level 3: Increasing his aim accuracy. Giving him 50% chance of dealing 1.75x critical hit.
    • Blow Arrow: (Active)
      • Level 1: Shooting the arrow with the strongest force. Dealing 150 damages and having 30% chance of pull the target one step backward giving him another turn to shoot the target. (cost 5 mana)
      • Level 2: Shooting the arrow with the strongest force. Dealing 225 damages and having 50% chance of pull the target one step backward giving him another turn to shoot the target. (cost 8 mana)
      • Level 3: Shooting the arrow with the strongest force. Dealing 325 damages and having 75% chance of pushing the target one step backward and 25% chance of pushing the target two steps backward giving 1 or 2 turn to shoot the target. (cost 15 mana)

NOTE: By programming these skills in this game, it help you understanding and learning more complex way of using condition and also improve your random number skill.

Item System:
Invest your own items and weapons for each class:

  • Warrior Items: Weapon, Shield and Armor. (Armor and Shield reduce the income damage).
  • Mage Items: Staff and Jewelry. Staff increase the damage of each skills and mana regenerate for each turn while Jewelry increase the mana capacity.
  • Archer Items: Bow.
  • Other Items: Mana potion and HP potion.

Inn System:
Most of the time, player will be seriously injured after plenty of battle. Entering and staying at the Inn will fully recover player's mana and hitpoint in exchange with 5 golds.

Battle System:
Since it is a simple text-base roleplaying game, the battle system will be based on turn-base system. Player and monster will take turn attack each other. Each turn, the game will ask player to choose normal attack, using skill to attack, or using potion. In some case, such as the target was stunned or have been pushed away, the player has extra turns to attack the target. When the monster die, the player will earn money.

Other Useful Link:


Member Avatar
Alex Edwards
Posting Shark
971 posts since Jun 2008
Reputation Points: 321 [?]
Q&As Helped to Solve: 109 [?]
Skill Endorsements: 2 [?]
 
1
 

Here's a toughy.

Write the Snaker program, using either a JFrame, GraphicsProgram or a JApplet (any GUI of your choice really).

Your snaker object will start off as one circle. That circle represents a head.

The body grows by encountering "snake-food" on the screen. When the head runs over the snake-food, the snake-food is consumed and a body-part is appended to the end of the snaker.

The snaker is moved by the keyboard, and can only move in the up, down, left and right directions. It has a static speed and the body parts always follow the same path as the one before it (except for the head). The snaker starts off without motion, then gains moment (permanently) after the first key is pressed.

In addition, there is no such thing as snap-movement. The snaker cannot move down if it is currently moving up, left if it is moving right... etc. This should be self-explanatory.

Also, the body cannot move immediately. In order to specify a new direction, the snaker must first clear the radius (or length) of the body-part before it in order to move forward.

Whatever part of the Snaker appears off of the screen on one side of the pane must appear on the other side.

Points are calculated when the Snaker consumes food and as time goes on.

The game is over if the Snaker runs into itself.

Your Snaker must consist of a LinkedList, and a Thread. Also implement a timer that tracks the time elapsed in the game.

Your Snaker must also implement the Serializable or Externalizable interfaces to save the current locations of the body parts, the direction of the head, and the score if the player decides to exit. Your Snaker GUI will need to implement a WindowListener that listens for things such as loss of focus (where the game should pause) and the window close operation (where the window will automatically save the game to a random object-file (that is not already named in the current directory) then exit once it is called).

Edit: Wow I'm very sorry! I thought this was for Java and not C++ O_O

Ok instead of a JFrame it can be a Win32 project. >_>

Member Avatar
Stellathomas
Newbie Poster
1 post since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

BTW there is another way to handle this whole thing: compile all your code (even your C-style code) using a C++ compiler. That pretty much eliminates the need to mix C and C++, plus it will cause you to be more careful (and possibly —hopefully!— discover some bugs) in your C-style code. The down-side is that you'll need to update your C-style code in certain ways, basically because the C++ compiler is more careful/picky than your C compiler. The point is that the effort required to clean up your C-style code may be less than the effort required to mix C and C++, and as a bonus you get cleaned up C-style code. Obviously you don't have much of a choice if you're not able to alter your C-style code
-------------------
Stellathomas

<SNIP>

Member Avatar
freudian_slip
Light Poster
36 posts since Oct 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

it's extremely interesting, but how does a self-taught beginner like me place oneself in such a great project?

thanx for the link and the advice, i hope to be able to use it some day if i learn hard. :)

As of top coder, there is a "practice" room where there are thousands and thousands or maybe just hundreds of problems you can solve. and they are also divided into sections for beginners, intermediates and experts. It's highly recommended that you check it out and start solving those practice problems. Though, I have yet to do it myself..

Member Avatar
bonnie1702
Newbie Poster
17 posts since Aug 2008
Reputation Points: 26 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
3
 

Hey all!
Here is a challenge problem to try. Its actually one of the questions on my last assignment which I have already completed and handed in.

Write a program that involves two classes and simulates the operation of a petrol (gas) pump.
A customer will arrive at a random time after the start of the simulation, and will purchase a random amount of petrol.
There is only one petrol pump, which has an underground tank that stores the petrol for sale. The capacity of the underground tank is 500 litres
Declare c++ classes for the Pump (with tank included) and the Customer, which is outlined further down.
Before the next customer purchases petrol, the program must display the amount of petrol remaining in the tank, and the price per litre for the petrol.
If the amount of petrol in the supply tank is greater than the amount the customer requests to purchase, the purchase request should be completed, otherwise only the amount of petrol in the supply tank should be sold.
After the petrol requested is provided, the details of the purchase should be displayed:
this will include:
number of litres provided
total cost of petrol provided

When the simulation finishes, the program should display:
the number of customers that purchase petrol
the total amount of money from the petrol sales

1. Write the declaration for the Customer class.
2. Define the class fully, so that it can be used as part of your code solution to this question.
For each new customer arriving at the pump, create a new instance of this Customer
class, and delete it when your program no longer requires this object.
3. Write the declaration for the Pump class.
4. Define this Pump class fully
5. Write the main function for this program that will:
Create an instance of the Pump class (to represent the petrol pump in the simulation).
At random intervals during the simulation, create a new instance of the Customer class,
to represent each new customer arriving at the petrol pump. Also, the code must delete
each instance of the Customer class after it is no longer required.
Call the appropriate class methods to control the interactiion between these classes to
simulate the operation of the petrol pump (providing petrol to customers when they
arrive).

Have a go and good luck! Most of us in class found it quite challenging, but in the end we more or less got it working right.
cheers
nm:)

Member Avatar
minas1
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

Text-based Role-Playing Game Project (For Beginners)
Firstly, this game will start with an introductatory storyline of the game to attract player interest. Then, it asks a player to enter his or her name and which class the player want to choose. There are going to be 3 classes for player: Warrior, Mage and Archer. Each class has it own unique abilities.

What about defense?

You
Post:
Start New Discussion
View similar articles that have also been tagged: