No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
43 Posted Topics
I am trying to get the height of a BST using a stack. I was told that I should use preorder and measure find the largest size of the stack. However, this does not seem to work. Any ideas of what I am doing wrong. [CODE] int PBT::maxDepth() { if … | |
I commented by the last line. I am trying to print out the string in reverse. [CODE] #include <iostream> using namespace std; void add(string n); int main() { string B ="ABCDEF"; add(B); } void add(string n) { if(n.length() <= 1) { cout<<n[0]<<endl; return; } else { cout<<n[n.length()-1]; add(n[n.length()-1]); //this lines … | |
I checked my php.ini file and there is no ; in front of extension=php_mysql.dll or extension=php_mysqli.dll. I think the I am getting this error because my figuration File (php.ini) Path is C:\Windows. How would I change it to C:\Apache2.2\php\php.ini? Also, once I have done this do I need to recompile … | |
I am trying to only have the words print out if they occur the same number of times as in the fibonacci sequence. If a words show up 1,2,3,5,8 etc then it will print up. I have gotten the program to print up the words based on how many times … | |
For this program I am trying to figure out how to sort/print the words out based on frequency of appearance in ascending order. As of now I can only get the words to sort/print based on alaphabetical order [CODE] from collections import Counter import string while True: filename=raw_input('Enter a file … | |
I am trying to combine the string NCards and Scards into one string called Tcards. I am using # include <cstring> and I get an error. How would I fix this. All the variables are strings. [CODE] void deck::deal() { Tcards=strcpy(Scards, Ncards); }[/CODE] | |
I am reading in from a file and when I use .eof() it read everything from the file the I get a run time error of Exc-Bad-Access. When I run a for loop instead the program runs with not errors. Any hints? [CODE] while (!inputFile.eof()) { inputFile>>number>>lowerRange>>higherRange>>cond>>aFName>>aLName>>phase; active=(cond=='t'); sAds[i] = … | |
I want to read in multiple lines from a file, but I am only able to get my program to read the first line. The program prints out two other lines but the values are zero. [CODE] double cost[3]; int lowerRange[3]; int higherRange[3]; bool active[3]; ifstream inClientFile("ad.txt", ios::in); for (int … | |
How do I display the results of list<t>. I put rangeChecker objects in range and now I want to display the rangeChecker objects in range. How whould I do that? [CODE] static void display(RangeChecker[] rangeChecker, int SIZE) { //displays values for x, y, z, and how many times z was … | |
I always thought that if I used a switch statement and enter an option not specified the default would catch it. However, if I press enter then enter an option I get a run time error. How would I fix this? I am only including part of the code, if … | |
I am putting 20 objects in an array then I am using a bubble sort (not the most efficient, I know) to organize the set from highest to lowest. I am wondering if there is a way to do this without using sets (mutators)? Code is below. using System; using … | |
I am trying to write a trigger that updates a column called CUST_BALANCE in a table called CUSTOMER when new data is entered into another table called INVOICE. What I want to do is when new data is inserted into INVOICE it will take the value in column INV_AMOUNT and … | |
Is their a way where the user could type Low to use the enum instead of typing 1? I know how to do this with strings, but am having trouble trying to figure it out using enums. [CODE] public enum Volume : byte { Low = 1, Medium, High } … | |
I am getting this error object reference not set to an instance of an object and cannot figure out how to fix it. I can get the program to when I only have one Timepiece object, but when I try more I get the error message. I left a note … | |
I am using split to split a string into a int, int, string. When I try int, string, string my program works fine. When I try int, int , string I get a run time error of an input string was not in a correct format. I am leaving a … | |
When I read in this file it reads in the entire line. [CODE] string filename ="f:\\date.txt"; FileStream f = new FileStream(filename, FileMode.Open); StreamReader stream = new StreamReader(f); int line; int[] array = new int[15]; for (int i = 0; i < 15; i++) { line = stream.Read(); // header line … | |
My program runs, but I am getting this message which I am fairly sure means that I have a memory leak and it is coming from my destructor. Assignment2(779) malloc: *** error for object 0x100100120: pointer being freed was not allocated I don't know what I am doing wrong. Since … | |
I am writing a program using vector and am wondering if my destructor is correct, or do I need to add another line. The clear, clears all the elements in the vector, but do I need to add another line to delete the vector, and if I do what line … | |
Can someone explain to me what is going on in this code. I am leaving comments by each line. [CODE] void qs::quicksort(int set[], int start, int end){ stack<int>s;//starts a stack to hold them elements s.push(start);//why push two elements, why not one so the while loop works s.push(end); while (!s.empty()) { … | |
I am having trouble with my quicksort. When I run my program it sorts them once( the lower half of the numbers are on one side, the higher half on the other). How can I get it to sort again without using a recursive function. [CODE] void qs::quicksort(int set[], int … | |
Can someone explain and give an example of how double hashing works. I understand linear, quadratic, and chain. | |
My profesor added this line of code to a bubble sort saying that it made it more efficient by tracking the last swap. I don't understand how this would work [CODE] void bubble_sort(int a[], int n){ while (0<n-1) { int last =0; for (int i=0; i<n-1; i++) { if (a[i]>a[i+1]) … | |
I am having trouble figuring out what the recursive function does in the insert sort. Wouldn't the recursive line block the rest of the code from working. I am just looking for a quick explanation. [CODE] void insertion_sort-recur(int a[], int n){ if(n<=1) return; insertion-sort_recur(a, n-1);//how does this line work temp=a[n-1]; … | |
I am pretty sure that the answer for this is n^3, because the 3rd for loop is executed n times and the middle is executed n+4 times and the top one is executed n times. I understand how to use sigma notation for the bottom and top for loop because … | |
Re: Good thing its not due till friday. If you want to get the most out of this sight, you need to post a small question and be 80% of the way done;) | |
I an trying to find the height in a binary search tree. I figured out how to count the leaves going directly left and directly right, but cannot figure out how to get he leaves in the middle. [CODE] int BST::height(){ int tall =0; int tall1=0; BinNodePtr ptr=myRoot; if (ptr->left … | |
I am using an overloading operator to add two polynomials. I have gotten it to work, but I am wondering if I can improve on my if statement by not changing the value of degree for the rest of my program. The if statement is used if the second polynomial … | |
I am multiplying two polynomials and cannot figure out how to add the exponents. The loop is to multiply the coefficients and degree is for the total degrees used in the polynomial. But I can't figure out what I should use to add the exponents. [CODE] Poly Poly:: operator*(const Poly& … | |
I am writing a program where the user inputs two polynomials, then the program adds them, multiplies them, and evaluates one of them. I am having two problems. First, I can't think of how to add the exponents in the overloaded method for *. Second when the two polynomials multiply … | |
I am trying add two polynomials by overloading the + operator. When I run the program it only adds the first coeficients. I cannot figure out why it is only returning the first coeficient. [CODE] //header file #include <iostream> using namespace std; #ifndef _POLY_H #define _POLY_H const int CAPACITY =100; … | |
I am having trouble with the evaluate class. An error message is coming back for the pow(x, degree). I have included the cmath library and have cast x and degree into double. Any hints or tips would be greatly appreciated. I have tested the program without the pow(x, degree) and … | |
When I compile I get this error message for istream error: no match for 'operator>>' in 'in >> ((Rock*)this)->Rock::myName' I did not include the program with main because I have not used it yet. [CODE] #ifndef ROCK_H #define ROCK_H #include<iostream> using namespace std; enum RockName {BASALT, DOLOMITE, GRANITE, GYPSUM, LIMESTONE, … ![]() | |
I am getting this error message error: expected primary-expression before 'enum' I can't figure it out. [CODE] #ifndef ROCK_H #define ROCK_H enum RockName {BASALT, DOLOMITE, GRANITE, GYPSUM, LIMESTONE, MARBLE, OBSIDIAN, QUARZITE, SANDSTONE, SHALE, ROCK_OVERFLOW}; class Rock { public: Rock() {myName = BASALT;} Rock(enum RockName) {myName= RockName;}//here is where I am … | |
I'm getting error: no match for 'operator>>' in 'std::cin >> aTable[i][j]' for [CODE] #include <iostream> using namespace std; const int NUM_ROWS=15; const int NUM_COLUMNS=15; typedef int TwoDimArray[NUM_ROWS][NUM_COLUMNS]; void printTable(int rows, int cols, TwoDimArray aTable); int main () { int rows, columns; TwoDimArray aTable[rows][columns]; cout<<"Enter rows and columns"; cin>>rows>>columns; for (int … | |
I want to center this. [CODE]cout<<a<<" "<<"+ x = "<<b<<endl;[/CODE] a and b are both int. How would I go about this. Most of the information I found on the web is about centering strings, I tried the code but did not have any success. | |
I understand that you are allocating memory for Stack, buy do not understand after :: and I thought that you only used :: when declaring classes not in the classes. [CODE] myTop= new Stack::Node(original.top());[/CODE] I can post the function class of the entire program if need be. | |
The if statment I am using in my main program is not working, it should return the else value, but is returning the information in the if part of the statment and then it causes a run time error. I am not sure what is going wrong. [CODE] que1.add("Fish"); que1.add("Whale"); … | |
I am tring to remove three string from a que using nodes. When I try to remove the third one it does so, but then I get a debugging error. I think the problem is that I am not deleting the last node but I cannot figure out what I … | |
The if statment I am using in my main program is not working, it should return the else value, but is returning the information in the if part of the statment and then it causes a run time error. I am not sure what is going wrong. [CODE] que1.add("Fish"); que1.add("Whale"); … | |
que.print is not working and I cannot figure out why not I posted a lot of code because I cannot figure out where the error is, I think it is in que.cpp, but I am nto sure what is wrong. Here is the main [CODE]#include "Stack.h" #include "Que.h" #include<string> #include … | |
I want to print out the letter B, instead I get a blank line. Any tips would be great [CODE] #include <iostream> using namespace std; void add(string n); int main() { string B; add(B); } void add(string n) { if(n.length() <= 1) { cout<<n[0]<<endl; } }[/CODE] | |
I am trying to use pow(2,a); and I am getting a error 'pow' ambigous call to over load function. I don't understand why, I added the cmath libarary. Here is the code. [CODE] #include <iostream> #include <cmath> using namespace std; int binaryToDec(int); int main() { binaryToDec(1110); return 0; } int … | |
I am trying to learn about recursives and found this code on the internet. It works, but am not sure why. Could some one explain to me why this works. I have posted comments by the function to explain what I do not understand. [CODE] #include <iostream> using namespace std; … |
The End.