|
Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4).
-Only integers need to be supported
-The following operators should be supported: +, -, *.
-Expressions within parenthesis should be evaluated first.
-Then the resulting expressions should be evaluated from left to right (no operator precedence)
-Example:
4+(4-(2*3)+1)+4 = 7
The code should be written in such a way to support additional operators.
Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance
tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’]
and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.
modified 17-Mar-16 14:43pm.
|
|
|
|
|
Your homework should serve the purpose that you learn something. And that something isn't supposed to be how to get other people to doing your homework for you.
Your assignments will get more difficult over time - so if you don't start doing them yourself now you'll never be able to.
So sit down, think about it and try something. If you then encounter a specific problem, feel free to ask - that's the idea of these forums.
Also, there are a lot of articles here on CodeProject about expression evaluation. Take a look at those if you struggle to find a starting point.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
|
I use Visual Studio 2012 and Microsoft DirectX SDK (June 2010). I created an applicatin with a 3d cube as an object. In the example that I use it is moved the point of view of the camera.
In my case I would like to move the object by the keaboard along X and Y axis without moving the camera view.
Could you please help?
Here is my code:
...
CubeDemo::CubeDemo(HINSTANCE hInstance, std::string winCaption,
D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP), MAX_SPEED(1500.0f), ACCELE(1000.0f)
{
// 5 units off the ground.
mCameraHeight = 5.0f;
buildVertexBuffer();
buildIndexBuffer();
onResetDevice();
InitAllVertexDeclarations();
}
...
void CubeDemo::updateScene(float dt)
{
// One cube has 8 vertices and 12 triangles.
gDInput->poll();
// Check input.
if( gDInput->keyDown(DIK_W) )
{
// Code for moving the 3D object along X axis???
}
if( gDInput->keyDown(DIK_S) )
{
// Code for moving the 3D object along Y axis???
}
buildViewMtx();
}
void CubeDemo::buildViewMtx()
{
D3DXVECTOR3 pos(10, 0, 10);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
}
void CubeDemo::drawScene()
{
HR(gd3dDevice->Clear(0, 0,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0));
HR(gd3dDevice->BeginScene());
HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPos)));
HR(gd3dDevice->SetIndices(mIB));
HR(gd3dDevice->SetVertexDeclaration(VertexPos::Decl));
D3DXMATRIX W;
D3DXMatrixIdentity(&W);
HR(gd3dDevice->SetTransform(D3DTS_WORLD, &W));
HR(gd3dDevice->SetTransform(D3DTS_VIEW, &mView));
HR(gd3dDevice->SetTransform(D3DTS_PROJECTION, &mProj));
HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME));
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12));
HR(gd3dDevice->EndScene());
HR(gd3dDevice->Present(0, 0, 0, 0));
}
Reagards
|
|
|
|
|
You move an object by repainting it at successive different points of the view screen.
|
|
|
|
|
I know but I need any example or tutorial easy to import in my code.
|
|
|
|
|
Member 12268183 wrote: I need any example or tutorial Then you need to use Google to search for them.
|
|
|
|
|
What is the main purpose of this forum then? I thought that using forums people could reach the needed information faster. Unfortunately here the situation is different.
|
|
|
|
|
Member 12268183 wrote: What is the main purpose of this forum then It is to help people with problems in the code that they write themselves. It is not a coding service, or a Google substitute. Since you do not have any code written, and I do not have a tutorial or sample code, then Google is the best place to look.
|
|
|
|
|
You need to TRASNLATE the object's POSITION.
while (DIK_W)
for(i=0; i < iMax; i++)
{
D3DXVECTOR3 pos(10, i, 10);}do
Or something like that ...
The World as we think we know it Has a lot more to it than meets the eye.
A Mad Scientist who has seen it for himself....
|
|
|
|
|
|
http://cgp.wikidot.com/circle-to-circle-collision-detection
|
|
|
|
|
Thank-you for reply.
But I have already implemented it for Circle Vs. Circle.
I am searching for
1. Ellipse Vs. Ellipse
2. Ellipse Vs. Circle.
|
|
|
|
|
<a href="http://mathworld.wolfram.com/Circle-EllipseIntersection.html">Circle-Ellipse Intersection -- from Wolfram MathWorld</a>[<a href="http://mathworld.wolfram.com/Circle-EllipseIntersection.html" target="_blank" title="New Window">^</a>]
Abit of math formula. This website contain alot math for different shape interaction and not only what needed and more
|
|
|
|
|
I have successfully added more than one items in listbox but i can not play them. the player is playing only first file. i want it to play next song when i click next button and previous song when i click previous button.
moreover, it should also automatically play next song...
if you can only help me with next and previous button.. it would be really helpful.......
this is my first logical post here. so i really expect some help from here...
|
|
|
|
|
This is the Managed C++/CLI forum. You probably need a different forum for your question.
|
|
|
|
|
I am writing a managed WPF Application. It is compiled against 'AnyCPU' as is common with C#.
I would like to add/develop a C++/CLI component to my app.
However C++/CLI is bound to an architecture (x86/x64/arm).
Is there a... relatively easy way for me to ship all 3 architecture and have the system load the right DLL at runtime?
|
|
|
|
|
You can try using the AddDllDirectory[^] method as the start of your application and add a directory containing the library for the current architecture. Just read the notes lower on the page on how to add the path to the default paths.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Here is a class that can help with the idea in my previous post:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace GryphonSoft.Utility.Runtime.InteropServices
{
public static class DllSearchPath
{
#region Fields
private static Dictionary<string, IntPtr> _dllPathCookieDict;
private static SetDefaultDllDirectories_Delegate _SetDefaultDllDirectories;
private static AddDllDirectory_Delegate _AddDllDirectory;
private static RemoveDllDirectory_Delegate _RemoveDllDirectory;
#endregion
#region Constructor
static DllSearchPath()
{
_dllPathCookieDict = new Dictionary<string, IntPtr>(StringComparer.OrdinalIgnoreCase);
IntPtr kernel32 = LoadLibrary("Kernel32.dll");
_SetDefaultDllDirectories = Marshal.GetDelegateForFunctionPointer<SetDefaultDllDirectories_Delegate>(GetProcAddress(kernel32, "SetDefaultDllDirectories"));
_AddDllDirectory = Marshal.GetDelegateForFunctionPointer<AddDllDirectory_Delegate>(GetProcAddress(kernel32, "AddDllDirectory"));
_RemoveDllDirectory = Marshal.GetDelegateForFunctionPointer<RemoveDllDirectory_Delegate>(NativeMethods.GetProcAddress(kernel32, "RemoveDllDirectory"));
_SetDefaultDllDirectories(0x00001000);
}
#endregion
#region Delegates
private delegate bool SetDefaultDllDirectories_Delegate(int DirectoryFlags);
private delegate IntPtr AddDllDirectory_Delegate(string NewDirectory);
private delegate bool RemoveDllDirectory_Delegate(IntPtr Cookie);
#endregion
#region P/Invoke
[DllImport("Kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("Kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
#endregion
#region Public API
public static void AddDllDirectory(string dir)
{
IntPtr cookie = _AddDllDirectory(dir);
if (cookie == IntPtr.Zero) throw new Win32Exception();
_dllPathCookieDict.Add(dir, cookie);
}
public static bool RemoveDllDirectory(string dir)
{
IntPtr cookie;
if(!_dllPathCookieDict.TryGetValue(dir, out cookie))
{
return false;
}
if (!_RemoveDllDirectory(cookie)) throw new Win32Exception();
_dllPathCookieDict.Remove(dir);
return true;
}
#endregion
}
}
Alter the namespace as needed.
I just threw this together in a utility library I am writing, as I think it might be useful in other places as well.
Feel free to use it any way you want. I am going to tri-license the library under the GPLv3, LGPLv3 and MIT licenses, so it is free for commercial use.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Nice Brisingr ! with not too much work you could publish it as an article here (I know Im bookmarking it or squirreling this code away)
|
|
|
|
|
I am planning on writing an article on the library when I get it closer to completion. That may be a while, though.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
interesting....
though I thought of handling the AppDomain.CurrentDomain.AssemblyResolve event and load my assembly with a path of my choosing.
Finding out whether the app is running as x86, x64, arm with GetType().Module.GetPEKind(out pek, out ifm);
|
|
|
|
|
Hi guys ! I need suggestion for making a semester project. Can anyone give a source code of some exception c program that can run in visual studio 2013 ultimate.
Please help me out with it,quickly.
|
|
|
|
|
Sorry, this site does not provide code to order, especially for homework projects.
|
|
|
|