|  | |
01-12-2005, 10:29 AM
|
#1 (permalink)
|
Newb Techie Join Date: Jan 2005 Posts: 9
| c++ basic problems cann anyone give some basic problems in c++.
basic? .... array,string,class,structure......
I bought a book on c++ by Robert Lafore and problems are very few........
c++ programming on the run............................................... .
can i make a complete game using c++ alone (like quake3 arena) |
| |
01-12-2005, 10:39 AM
|
#2 (permalink)
|
True Techie Join Date: Jan 2005 Posts: 113
| No, you cannot make a game like Quake 3 arena with C++ alone, as you would need some experience both building game engines, and doing anything associated with graphical parts of a game. OpenGL or DirectX programming would be required to make a game like Quake 3, or any game with 3d or 2d graphics for that matter.
C++ alone will only give you text-based games, and nothing more, nothing less.
Here is a basic problem:
Make an item shop in which the player starts out with a set amount of gold, and can repeatedly purchase items until the gold does not allow to do so, or until it reaches 0. Once it is no longer possible to purchase items or the gold is 0, give some output stating that fact. Also, each time the player spends gold on an item, make it so that the output given updates the gold each time something is purchased so that the player can keep up with how much is left, and how much has been spent.
I'm working on C++ too, fun fun fun!
__________________ I\'m not a vegetable! |
| |
01-12-2005, 12:11 PM
|
#3 (permalink)
|
Newb Techie Join Date: Jan 2005 Posts: 9
| i will post the codee tomorrow...............
looks like pretty intresting problem |
| |
01-12-2005, 03:54 PM
|
#4 (permalink)
|
True Techie Join Date: Jan 2005 Posts: 113
| Yeah, not that hard, mainly for beginners.
Good luck!
__________________ I\'m not a vegetable! |
| |
01-12-2005, 11:49 PM
|
#5 (permalink)
|
Super Techie Join Date: Jan 2005 Posts: 295
| Here is another one for you:
Reverse Polish Calculator
Implement the following stack functions.
empty() //returns true if stack is empty and false otherwise
push(argument) //pushes item argument on the stack
pop() //removes (but does not return) element on top of stack
top() //returns (but does not remove) element on top of stack
One very common use of a stack is found in calculators such as the Hewlett Packard calculators. Calculators that use a stack use reverse polish (or prefix) notation for arithmetic expressions. Reverse polish notation allows expressions to be entered without the use of parentheses. We are used to working with expressions in infix notation where a binary operator is placed between left and right operands. Parentheses are used to specify the order of operations. An infix expression is of the form LBR (left op, binary operator, right op) which corresponds to the postfix expression LRB (left op, right op, binary operator). Consider the following
Infix expression Postfix Expression
(a+b) ab+
(x - y - z) xy-z-
(x-y-z)/(u+v) xy-z-uv+/
(a^2 + b^2)*(m-n) a2^b2^+mn-*
Use ^ for exponentiation
To evaluate a postfix expression, P, you scan from left to right. When you encounter an operand, X, while scanning P, push it on to the evaluation stack, S. When you encounter an operator, B, you pop the topmost operand on the stack into a variable which represents the left operand, L. Finally, perform the operation B on L and R getting expression LBR, and push the result back on to the evaluation stack, S.
Make sure your postfix expression can handle:
- signed numbers
- multiple digit numbers
- floating point numbers
Delimit the items in the string with a blank space. The evaluation will be in two stages.
stage 1: Remove any excess blank spaces and any invalid characters from the string.
stage 2: Evaluate the postfix expression and display the answer.
Example:
Enter a postfix expression: -3.5 (2) * 12.75 +
Converted string: -3.5 2 * 12.75 +
Result: 5.75
__________________ \"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla |
| |
01-13-2005, 02:21 AM
|
#6 (permalink)
|
Newb Techie Join Date: Jan 2005 Posts: 9
| #include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
int gold=1000;
void main()
{
clrscr();
int ch,i=0,j; char items[100][20];
while(1)
{
cout<<" WELCOME TO MY SHOP"<<endl;
cout<<"what would you like to buy : "<<endl;
cout<<" 1.knife(50 golds)\n"<<" 2.pistol(200 golds)\n";
cout<<" 3.shotgun(300 golds)\n"<<" 4.assault_rifle(500 golds)\n";
cout<<" 5.machinegun(800 golds)\n";
cout<<" 6.check my balance and collected items\n"<<" 7.exit\n";
cin>>ch;
switch(ch)
{
case 1: gold=gold-50;
if(gold<=0)
{
cout<<"Sorry! You dont have enough gold"<<endl;
gold=gold+50;
break;
}
strcpy(items[i],"knife");
i++;
break;
case 2: gold=gold-200;
if(gold<0)
{
cout<<"Sorry! You dont have enough gold"<<endl;
gold=gold+200;
break;
}
strcpy(items[i],"pistol");
i++;
break;
case 3: gold=gold-300;
if(gold<0)
{
cout<<"Sorry! You dont have enough gold"<<endl;
gold=gold+300;
break;
}
strcpy(items[i],"shotgun");
i++;
break;
case 4: gold=gold-500;
if(gold<0)
{
cout<<"Sorry! You dont have enough gold"<<endl;
gold=gold+500;
break;
}
strcpy(items[i],"assault_rifle");
i++;
break;
case 5: gold=gold-800;
if(gold<0)
{
cout<<"Sorry! You dont have enough gold"<<endl;
gold=gold+800;
break;
}
strcpy(items[i],"machinegun");
i++;
break;
case 6: cout<<" your balance and collected items......"<<endl;
cout<<"BALANCE : "<<gold;
cout<<"\tCOLLECTED ITEMS ...."<<endl;
for(j=0;j<=i;j++)
{
cout<<items[j]<<endl;
}
break;
case 7: exit(0);
}
}
}
this is form my point of view what do you think red recon |
| |
01-13-2005, 11:29 AM
|
#7 (permalink)
|
True Techie Join Date: Jan 2005 Posts: 113
| You did it correctly!
I'll post up my version of the item shop when I get time later on today.
__________________ I\'m not a vegetable! |
| |
01-13-2005, 08:25 PM
|
#8 (permalink)
|
Super Techie Join Date: Jan 2005 Posts: 295
| Are you gonna try my one as well?
__________________ \"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla |
| |
01-13-2005, 08:42 PM
|
#9 (permalink)
|
Newb Techie Join Date: Jan 2005 Posts: 9
| yes i will try it it seems simple...
but if i am going to store the operands as a string then how will the compiler know that this is a number.wait i think i can use structure or union here.so ill post the code today.......... |
| |
01-15-2005, 03:09 AM
|
#10 (permalink)
|
Newb Techie Join Date: Aug 2004 Posts: 22
| wa....
its intersting^^
i think iam gonna try it on java...
-vip- |
| |  | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |