User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,223 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,283 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 32359 | Replies: 16
Reply
Join Date: Jun 2007
Location: Home
Posts: 2,448
Reputation: zandiago is on a distinguished road 
Rep Power: 6
Solved Threads: 24
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: C / C++ FAQ's and Practice problems

  #11  
Oct 12th, 2007
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.
Last edited by zandiago : Oct 12th, 2007 at 12:18 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 26
Reputation: everlast is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
everlast's Avatar
everlast everlast is offline Offline
Light Poster

Question Re: C / C++ FAQ's and Practice problems

  #12  
Jan 4th, 2008
Originally Posted by iamthwee View Post
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.
Reply With Quote  
Join Date: Apr 2008
Location: Plymouth, UK
Posts: 22
Reputation: Drezta is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Drezta's Avatar
Drezta Drezta is offline Offline
Newbie Poster

Re: C / C++ FAQ's and Practice problems

  #13  
Apr 13th, 2008
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)
Reply With Quote  
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 39
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

Re: C / C++ FAQ's and Practice problems

  #14  
Apr 25th, 2008
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.
Reply With Quote  
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 410
Reputation: invisal will become famous soon enough invisal will become famous soon enough 
Rep Power: 5
Solved Threads: 36
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: C / C++ FAQ's and Practice problems

  #15  
Jul 22nd, 2008
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:
Last edited by invisal : Jul 22nd, 2008 at 1:49 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote  
Join Date: Jun 2008
Location: WA, USA
Posts: 777
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Rep Power: 4
Solved Threads: 76
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Master Poster

Re: C / C++ FAQ's and Practice problems

  #16  
Jul 22nd, 2008
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. >_>
Last edited by Alex Edwards : Jul 22nd, 2008 at 3:06 pm.
Reply With Quote  
Join Date: Sep 2008
Posts: 1
Reputation: Stellathomas is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Stellathomas Stellathomas is offline Offline
Newbie Poster

Re: C / C++ FAQ's and Practice problems

  #17  
32 Days Ago
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>
Last edited by happygeek : 32 Days Ago at 7:26 am. Reason: advertising removed
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)

simorb01

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC