C++ :: Dequeuing Integer Values From Heap Results In Garbage Values

Apr 8, 2015

I've been working on a homework assignment that randomly generates integers and populates them into an array (array1). The program is then supposed to:

1.) copy those values to a second empty array (array2)

2.) sort the values already in array1 (using an inline function)

3.) enqueue the unsorted integers from array2 into a heap vector

4.) a third empty array (array3) is supposed to be populated with those unsorted integers (by dequeuing them from the heap), sorted in reverse order.

But no matter what I do, I always get garbage values like these:

I've tried using both a standard random number generator:

array1[i] = rand()%100+1;

And the d_random.h file my instructor gave us, but nothing works.

Here's the code from all 3 files:

HeapTester.cpp

Code:
#include <iostream> // Provides cin, cout
#include <cstdlib> // Provides EXIT_SUCCESS, rand, srand
#include "d_random.h"//Provides random number generator
#include "Heap.h"
using namespace std; // Use C++ Standard namespace
//Elements in each array.
const int arrayLength = 15;//100;

[Code] ....

Why I'm getting those garbage values?

View 6 Replies


ADVERTISEMENT

C++ :: Read Unknown Number Of Integer Values And Then Print Count Sum And Average Of Odd Values

Apr 9, 2014

write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!

View 1 Replies View Related

C :: Save Values From A Char Buffer Into Integer Values Of A Struct?

Jul 3, 2013

I'm attempting to save values from a char buffer into integer values of a struct.

This is what resides in the buffer "STD 2 2 2 2 2 2 2 " and this is my sscanf call

Code:
sscanf(buffer, "STD %d %d %d %d %d %d %d
", &dt_struct.date,
&dt_struct.mth,
&dt_struct.year,
&dt_struct.dow,
&dt_struct.hr,
&dt_struct.min,
&dt_struct.sec);

I then print the values back out in a string using sprintf.

Code:
sprintf(t_string, "STD %d %d %d %d %d %d %d
", dt_struct.date,
dt_struct.mth,
dt_struct.year,
dt_struct.dow,
dt_struct.hr,
dt_struct.min,
dt_struct.sec);

But this is what I get:
STD 0 0 2 0 0 0 2

Instead of what I want:
STD 2 2 2 2 2 2 2

View 7 Replies View Related

C++ :: Build Min Heap With No Repeating Values

Jul 10, 2013

10,11,20,1512,22,24,19,22

i want to write a c++ program to build min heap which gets above values from user. remember this program should not alloduplicate values to enter. it should discard duplicate values.

View 11 Replies View Related

C/C++ :: Vector Of Class Outputting Garbage Values

Jun 21, 2014

I have a class that uses std::vector. I push back class objects onto the vector but when I try to cout the data members (with get functions) I get garbage values.

Here is the class:

#ifndef JOBS_H
#define JOBS_H
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
class Jobs{

[Code] ....

I know I am missing the implementation of several functions but I'm just testing my vector to see if it is working and it isn't. The getBlockValue() function should output 0 for each job. When I push back one object the output is 0. When I push back 2 objects the output is 0. However when I push back 3 objects I get random values. Why is this? I thought vectors were dynamic?

View 8 Replies View Related

C Sharp :: Show Results From Values In Text Boxes On Clicking Or Pressing Tab Button

Feb 21, 2013

I am developing application software.entering two textbox value,while click or pressing tab button in third textbox, the result needs to show in third textbox.

View 1 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related

C++ :: Detection Of Integer Values?

Jun 23, 2013

i am having trouble finding a way to detect integers from an external text file. i currently have this code:

while(inputfile.get(wc))
{
char character = inputfile.get(wc);
if (character + 1 != NULL)
{
cout << character << endl;
}
}

this does not work as if (character + 1 != NULL) comes up with errors.

is there a way to detect ints?

View 3 Replies View Related

C++ :: Swap Values Of Integer And A Character

Oct 31, 2013

Im trying to swap the values of an integer and a character, however Im not sure where to insert the static_cast<type> part that I need for this to happen?

// Program to demonstrate a function template
#include <iostream>
using namespace std;
// Interchanges the values of variable1 and variable2
template<class T>
void swap_values(T& variable1, T& variable2)

[Code] ....

View 5 Replies View Related

C++ :: How To Read Integer Values From CSV File

Mar 14, 2014

I read one csv file in which it contains different types of data like string, integer etc.I want to fetch only integer data from that file and store in vector.Below i copy some code that read line from file,store in vector.I tried to convert string to integer or double and do some operations on it as i know that string values,but how to identify only integer values and store that in vector?

#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include<sstream>
#include<iterator>
#include<algorithm>
using namespace std;
int main() {
string line;
int cnt=0,val1,val2;

[Code] ....

input file like
Employee Code:121AEmployee Name :David
DateInTimeOutTimeShiftTotal DurationStatus
01-Apr-139:5919:53FS 9:53 Present

View 1 Replies View Related

C :: Possible To Mix Characters And Integer Values In A Text Document

Jul 23, 2013

I was just wondering whether or not it is possible to "mix" characters and integer values in a text document that is to be read by C.

I am to read and use values for length around the hip, neck and such, however, most of the tutoring examples I am finding online seem to strictly deal with either integers or characters alone.

Basically my text file looks a bit like:

Abdominal length: 90.000
Neck length: 26.500
and so on

So, before I move further into this subject, is it possible at all to isolate and use only the double values or will I have to format my text file differently?

View 9 Replies View Related

C/C++ :: Assigning Current Date To Integer Values

Sep 26, 2014

How can i assign current date as integer ?

for example:

today's date 26 Sep 2014 on a computer
i try to make as below
int day=26
int moth=9
int year=2014

I also research i think i will use time.h library surely

View 3 Replies View Related

C++ :: Assign Unique Integer Values For Words In Dictionary

Mar 25, 2013

I need to assign unique integer values to words in a dictionary that have the same alphabets, for example 'act' and 'cat' should have the same integer value. Would just adding the ascii values of the letters be sufficient?

View 1 Replies View Related

C++ :: Passing Values From Text File To Integer Array

May 24, 2013

I'm trying to passing values from a text file to an array. The values in txt file is;

0 2 3 5
1 2 5
0 1 3 6
1 3 5

I need to store these values in an array like that

Code:
int array[?][?]={{0,2,3,5},{1,2,5},{0,1,3,6},{1,3,5}};

View 1 Replies View Related

C# :: Align Integer / Decimal Values On The Left (Devex Gridview)

Mar 22, 2015

I want to learn ow to align an integer/decimal values on the Left inside devexpress gridview.

View 4 Replies View Related

C++ :: Write A Program That Replaces Values In A Vector With Their Absolute Values

Dec 4, 2013

This is my code: [tag]

Code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

[Code] .....

View 4 Replies View Related

C# :: Making String Equal Many Different Values Then Compare Those Values

Dec 18, 2014

I was wondering if this was even possible and if so, how do I do it.

else if (speech.ToLower().Contains("truck") && speech.EndsWith(number))
{
Here I would like to see if my speech had ended with any of the values i would have stored in the string "numbers". If it did, I would like to just take the value and add it to a new string called whatever
}

I have tried this a million different ways and I cant get it to work. I'm not even sure how I would go about storing tons of different numbers in one string, or if that's even possible.

View 10 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C/C++ :: Display Inputted Values Without Overwriting Other Inputted Values

Jun 16, 2014

How can I display my inputted values here without overwriting the other earlier inputted values. It should be displayed like this [URL].... but mine shows this [URL].... I've been stucked here for hours in thinking for an algorithm. Everything is working fine except the PDISPLAY part

#include<iostream>
#include<iostream>
#include<string>
#include<cctype>
#include<cstdlib>
#include <iomanip>
#include <windows.h>
#include<conio.h>

[Code]...

View 1 Replies View Related

C++ :: Looping With Different Values?

Dec 9, 2013

I want to write a loop to check for prime numbers. So I'm going to check only numbers ending with 1,3,7,9.

So I need a loop that will increment with 2,4,2,2 and again 2,4,2,2...

What king of loop is best, a 'for loop' or a 'while' with switches in it or something else?

Basically I need to increment three times with 2 and then with 4, three times with 2 and then with 4...

View 9 Replies View Related

C :: Values Are Not Calculating?

Nov 29, 2013

Finally got a programme partially working, why the values are not showing? Is this down to incorrect formula or i havent declared the values etc?

Code:
#include <stdio.h>
#include <math.h>
float timeconstant(float R, float C);

float R;
float C;
float time_c;

[Code] ....

View 2 Replies View Related

C++ :: Getting Values From XML File?

Apr 12, 2014

I'm a programmer on my high schools FIRST Robotics team. to give a bit of backstory if you don't know, we use C++ to program a 120 lb robot to compete in a competition released every year.

NOW - why I want to mess with an xml file. When we're messing with variable values to make sure everything moves at the right speed, stops at the right place, etc., we have to:

1. Change the file
2. Build code
3. Deploy code to the robot
4. Reboot the computer on the robot (FRC uses a 4 port cRIO by NI, takes ~ 50s to reboot)
5. Reconnect.

All in all, its about a 3-3.5 minute process to change values. Because of this, I would love to be able to store all my motor speeds, stopping positions, etc., in an xml file then simply ftp to the robot, mess with the xml, save it, and re-run the program.

SO! How would I even begin this process? I just want learning how to use one of those parsers like xerces to end up realizing that I can't use it in an application such as this.

View 3 Replies View Related

C++ :: Input Only Values Between 2 - 7

Jan 4, 2015

I want to input only values between 2 - 7 what is wrong?

do{
cout<<"Podaj wykladnik
";
cin>>b;
}while(b<=2 && b>=7);

View 2 Replies View Related

C/C++ :: Getting Values For Iterators

Dec 25, 2014

I'm having problem getting the values for iterators. This code:

auto sum = inputVec.begin() + itLast;

gave this error: no match for 'operator+'

#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main(){
vector<int> inputVec;

[Code] .....

View 4 Replies View Related

C/C++ :: Different Size Of Values

Nov 10, 2014

The problem is with that a. What is it, a pointer? What's the difference between the a in the main function and the a in the function?

#include <iostream>
#include "Header.h"
using namespace std;
short int capacity(int* a) {
int capacity;

[Code] ....

The function it returns i think the size of the pointer instead of returning the size of my array. I don't think i fully understood pointer arithmetic.

View 1 Replies View Related

C++ :: How To Add Values Of For Loop

Feb 9, 2014

I want to add each of the values that are calculated by the end of each for loop.

For example:

for(int i = 0; i < 10; i++)
{
int x;
}

I want to be able to add all of the x values calculated from the for loop together. How to do that?

View 6 Replies View Related







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