C/C++ :: Applying Limit To Recursive Depth?

Jul 9, 2014

I wrote this code, but now need to apply a limit to the recursive depth. This is the format that I have to use. How would I pass a limit so that it stops after a given number? I'm just confused about where to apply it.

int compute_edit_distance(char *string1, char *string2, int i, int j, int limit) {
if (strlen(string1) == i) return strlen(string2) - j;
if (strlen(string2) == j) return strlen(string1) - i;
if (string1[i] == string2[j]) return compute_edit_distance(string1, string2, i + 1, j + 1, limit);

[Code] .....

View 4 Replies


ADVERTISEMENT

C/C++ :: Applying Texture To Sphere?

Apr 19, 2015

I am currently trying to apply a texture to a sphere I made, and have been following various tutorials. My program no longer crashes (used to be a problem but I figured it out), but the texture isn't being applied to the sphere. I used glut and SOIL to do this, but I am pretty sure that I am missing some necessary code from my own program for the textures to work. Because my program is a bit different from the tutorials though, I can't figure out what it is that I am missing. Below is what I have written to this point. It all compiles, and it successfully displays two objects (a sphere, and a pyramid), but neither object has textures, the pyramid simply has the colors it was set with (supposed to, I want to texture map the sphere first), while the sphere is a solid blue. What am I missing or what do I need to move?

#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

[code]....

View 9 Replies View Related

C++ :: Tic Tac Toe Game - Applying OOP And Arrays

Sep 25, 2012

Objective : Code a game allowing two human players to play tictactoe.

Create 2 classes:
-Create a 3 x 3, 2-D array board class to play the game.
-Player; has a private string name data member and a method that reads the players’ row and column selections from the keyboard.

Create 2 player objects from this class. Name the players Orestes and Xerxes.

Think carefully about board and player classes responsibilities and how they interaction with one another. The players do not collaborate with one another but they collaborate with the board.

My Problem : The program compiles with the header file, but it the displaying is wrong as you will see when you enter your row and column.

Sources
Header file:

Code:
#include <iostream>
#include <string>
using namespace std;
class Board {
public:
void display(char Z[][3], int row, int col);

[Code] ....

View 1 Replies View Related

C# :: Applying Dijkstra Algorithm To Graphs?

Jan 30, 2015

I'm attempting to build a tool for a Minecraft mod called Thaumcraft. In it, there are various aspects of magic that are used in a little research minigame; basically, you have to link Aspect A to Aspect B by the aspects either used to make them, or the aspects that use them in their creation. I figured the easiest way to find a path from A to B would be to relate them via graph object, the code for which I found here, minus the IEnumerable<T> dependency on the Graph<T> class itself, because that requires I build an IEnumerator<T> class and it seems difficult I can do without.

Must be between MinSteps and MaxSteps (say, between 3 and 5 steps).Must use either a source aspect (as in, the current aspect requires it to be built), or a destination aspect (as in, the current aspect is used in its creation).An aspect requires two other aspects of a lower tier to create it.The only exceptions to the above rule are the Primal aspects, which require no aspects to build them.

Here's my Aspect class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Pathfinder

[code].....

View 2 Replies View Related

C/C++ :: Applying Heat Flux On A Surface

Apr 21, 2014

I am trying to write udf for heat flux on X-Y plane in Fluent having the formula

Q(Y) = (0.304)/(deltaY + deltaY/2)^-3
Where deltaY = 50cm and
Y = 10m

but I am unable to do it. Can write udf for heat flux? Y is the length on Y-axis and X whixh is equal to 5m is length on X-axis. Q is heat flux goes through X-Y plane in Z direction. Geometry is a cube with dimension 10*5*0.005 all are in meters.

View 1 Replies View Related

C++ :: Applying Bubble Sort On Linked List

Feb 27, 2015

I'm trying to apply a bubble sort on a linked list. It works in the first traversal, but then after the code cPtr = nPtr;, it inputs repeated digits at the end of the (semi-sorted) linked lists.

View 1 Replies View Related

C++ :: Game Freezes When Applying Surface From One Object Onto Another?

May 28, 2013

Been trying to figure out why my program freezes. I know exactly what line of code is causing it, but I can't figure out WHY it's causing it. It compiles fine, there are no errors returned, and then the game just stalls and I have to ctrl+alt+del to kill it.

Anyway, what I have set up is something like this:

main.cpp
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "SDL_image.h"
#include "SDL_rotozoom.h"

[Code]....

This is the line of code that's freezing the program. Simply put, so that you don't really have to go through it piece by piece, what I have done is:

*each player gets their own drawing surface called PlayScreen
*each player gets an array of 360 drawing surfaces called ShipPic. These are to keep the game from having to render the rotation pics of the ship on the fly.
*Get_Ship clips the requested ship picture out of the ship sprite sheet and puts it in ShipPic[0] for the original angle.
*the original picture is rotated by 1 degree and put into the 360 ShipPic slots.
*when the player rotates their ship, the angle changes, and it calls the ShipPic with the same number as the player's angle and places it on the screen.

All of this works perfectly.

Then, in Player::draw_screen(), I have it set up so that each player looks at all the other players and gets their distance. If they're within range, it takes the other player's picture rotated by the other player's angle and puts it on the current player's PlayScreen. This is where it freezes.

I've checked for NULL pictures, I've checked to be sure the angle is between 0 and 359, nothing makes any difference. I know it's reading the other player's information since I can output all of the player's X & Y coordinates, angles, the width/height of their pictures, etc. on each other's screens. So they're definitely talking.

To test the code, I've changed it from

Apply_Surface(ShipX, ShipY, p[i].ShipPic[(int)p[i].angle], PlayScreen);
to
Apply_Surface(ShipX, ShipY, p[ID].ShipPic[(int)p[ID].angle], PlayScreen);

And it works perfectly, placing the player's OWN picture in for the other players. So the function works. It's just when I try to take another player's picture and place it on the current player's screen that it freezes.

I've tried quite a few different ideas, such as creating a temp drawing surface to blit the other player's picture onto, but again, it freezes as soon as I try using the other player's pictures.

View 5 Replies View Related

C :: Depth-first Search Of A Graph

May 18, 2013

You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].

Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???

View 1 Replies View Related

C :: Depth First Search Implementation

Mar 12, 2013

I'm having problems with implementing depth first search.

Code:
6 10 //6vertices 10edges
0 2 //vertex and its adjacent vertex
1 0
1 2
2 3
2 4
3 1
4 1
4 3
4 5
5 3

Output to terminal: 0 2 3 1 4 5
but it should be: 0 2 4 5 3 1

Here's my code:

#include<stdio.h>
#include<assert.h>
/* maxVertices represents maximum number of vertices that can be present in the graph. */
#define maxVertices 100
void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)

[Code] ....

View 1 Replies View Related

C++ ::  Depth First Search - Won't Compile

Jan 13, 2013

I've been trying to implement this Depth First Search graph algorithm using STL, and I get some error from Visual C++ 2012 at compilation.

The code is:

#include <fstream>
#include <stack>
#include <vector>
#include <algorithm>

[Code].....

And the error says something like this:

Debug Assertion Failed!

Program: C:WindowsSYSTEM32MSVCP110D.dll
File: d:...vs2012vcincludedeque
Line: 1497

Expression: deque empty before pop

View 1 Replies View Related

C++ :: Height Or Depth Of Binary Tree

Feb 23, 2014

I'm in interested to know what will be the height of binary tree with say 5 nodes (consider it balanced) is it 2 or 3?

9
/
5 13
/
3 7

and for following tree also:

2
/
7 5
/
2 6 9
/ /
5 11 4

is it 3 or 4?

i'm asking because, not able to find correct/one answer.

the algorithm i find is:

depth(struct tree*t) {
if ( t == NULL) return 0;
return max( depth(tree->left), depth(tree->right) ) + 1;
}

According to it, ans for second will be 4

But as per image on wikipedia [URL] .... the ans is 3

View 6 Replies View Related

C++ :: Program To Display N Depth Pyramid

Feb 21, 2013

Write a program that displays n depth * pyramid.

For example,Input: 4
Output:
*
***
*****
*******

This is what i have so far but it not giving me what i want.

#include <iostream>
using namespace std;
int main() {
int star;
int count=1;
cout<<"Enter the number: ";
cin>>star;

[Code] ....

View 1 Replies View Related

C++ :: Calculating depth Of Binary Tree

Apr 1, 2013

i have come across this code for calculating the depth of a binary tree.

int maxDepth(Node *&temp) {
if(temp == NULL)
return 0;
else {
int lchild = maxDepth(temp->left);
int rchild = maxDepth(temp->right);

[Code] ....

In these recursive calls i am really clue less about how the statements i numbered from 1 to 4 would be executed...in every recursive call...???

Lets temp has left depth of 3 and right depth of 100 then...in last 97 recursive calls max(temp->left) would be doing...????? how these recursive mechanism work here... I want to know specifically how these left node and right node recursive calls are co-ordinating with each other????

View 2 Replies View Related

C++ :: Depth And Breadth First Search Program

Mar 15, 2014

I am not sure how to have to user input numbers into a tree and to have it print out the steps it takes to reach the goal

Header File

#include <iostream>
#include <stack>
using namespace std;
bool recursive_depth(int);
bool is_goal(int);
void input_tree();
void print_tree();

[Code] .....

View 4 Replies View Related

C/C++ :: How To Implement Depth-First-Search With Adjacent Matrix

Nov 1, 2014

What I have done : Created functions to accept inputs from user and read,print out adjacent matrix.

What I need : How do I start DFS in adjacent matrix so that I can output the vertices of each connected component of a graph? I'm confused with adjacent matrix and the term 'component'.

#include <stdio.h>
#include <iostream>
#define maxV 8
using namespace std;
int V,E,x,y;
int a[maxV][maxV];

[Code] .....

View 7 Replies View Related

C++ :: Convert SUDOKU Solver From Depth-First To Breadth-First

Mar 5, 2013

Code:
/* Sudoku solver using dept-first search*/

#include <iostream>
#include <stack>
using namespace std;
struct valpos//structure which carries information about the position of the cell and its value {
int val;
int row;
int col;

[Code] ....

View 3 Replies View Related

C++ :: Set Limit On What Can And Can't Be Deleted

Nov 11, 2013

Is there any way to set a "lock" on certain couts from system ("cls"). You can this with const to "lock" a variable to a certain value so I am wondering if that is true for couts from system ("cls"). This would make my program much simpler to write.

View 2 Replies View Related

C++ :: Setting Limit On Cin?

Feb 22, 2013

I want to set limit on cin for example

int i;
cout<<"Please enter 4 digits id: ";
cin>>i

If user enter more then 4 digits it must give an error

View 5 Replies View Related

C :: Print Primes In Limit

Jul 13, 2013

What's actually wrong with the program....I'm trying to print the primes in limit of L1 and L2 ;L1<L2.... */

Code:

#include<stdio.h>
#include<math.h>
void main(){
int L1,L2,n=0
printf("Enter Limits by a space:
}

[code]....

View 3 Replies View Related

C++ :: Find The Sum Of Primes Below Limit

Apr 15, 2013

I have to find the sum of primes below limit. My program works fine when I try to find primes less than 10. However, when I run it for the sum of primes less than 100, I get 166337 when I am supposed to get 1060. My program works on modular arithmetic, where any prime greater than 3 can be expressed as 1 or 5 mod 6.

Here is my code:

#include <iostream>
using namespace std;
int main(){
unsigned long long prime, sum;
int limit = 100;

[Code] ....

OUTPUT:
SUM: 166337

View 4 Replies View Related

C++ :: Arrays Elements Value Limit

Apr 26, 2013

I have created a new array and have wrote a code which will decrease || increase the value of the array element. I been trying to figure out how to set the value limit. For Example:

int[] stock = new int[] { 10, 10, 10, 10 };

How to set a limit on the elements that they will never go below to the negative integers and over 10?

View 1 Replies View Related

C++ :: How To Put A Limit Of 100 Questions To Be Outputted

May 8, 2014

Why is this code crashing ? and how do I put a limit of 100 questions to be outputted but not for the test to end ? Also this doesn't seem to be randomizing at all ?

#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
vector<string> questions;
vector<string> answers;

[Code] .....

View 11 Replies View Related

Visual C++ :: How To Add A Limit On Size

Feb 15, 2013

Im working on a small code and am trying to limit the size of the mysql databse string its pulling.

It can only be 119 characters, or less if its more i would like to do nothing, but if its meets the requirements it runs the script.

Code:
int32 message_id;
string_t message ="Is requesting some one to respond.";<_______________TEMP SHOULD BE THE POSTERS MESSAGE
string_t username = "Guest";<_______________TEMP SHOULD BE THE POSTERS NAME
// char will not be logged in so get the id manually

[Code] ....

So here is where I'm heaving the problem

if(message is less then 119 characters run script )<<___________THIS IS THE CODE LINE IM TRYING TO LEARN
{
char buf[110];
sprintf(buf,"[Web Chat] %s %s",username.c_str(), message.c_str());

[code].....

View 2 Replies View Related

C :: Limit Action Within A Range Of Time

Mar 8, 2014

My question is : can you limit an action to a certain time range?

For example, the user has to put character via getchar() within 3 seconds, otherwise the code will move on?

View 1 Replies View Related

C :: Program To Play Lottery - Limit Between 100-99?

Feb 2, 2015

Suppose you want to develop a program to play lottery. The program randomly generates a Lottery of a three-digit number( any number from 100 to 999), prompts the user to enter a three-digit number, and determines whether the user wins according to the following rule:

1. If the user matches the lottery in exact order , the awards is $100,000.
2. If the user input matches the lottery digits, the awards is $50,000.
3. If two digit in the user input matches a digit in the lottery, the awards is $30,000.
4. If one digit in the user input matches a digit in the lottery,
the awards is $10,000.

Sample:
The winning number is 865.

Your ticket is 865 then 100000
Your tickect is 686, or 568,.. all digits are right but not in order
You get 50000
Your ticket is 860, or 186 .. then 30000
Your ticket is 800, 706, 600.. just one digit much you get
10000
Else
0

Im using if/else statements. Which syntax would I use to figure out the limit between 100-99?

View 1 Replies View Related

C++ :: Limit In Number Of Objects Of Class?

Jul 8, 2013

Is dere is any limit in number of objects of a class?

View 16 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved