C++ :: Sorting Dynamic Stack Items?
Sep 26, 2013
Create a program that contains the following functions:
-create two dynamic stacks with integer data contained in an external file.
-Sort items in stacks by the selection sort method
-Record outputs in an external file.
Main function main ()-menu selection functions and check the status of the data
I shouldn`t use arrays or STL only can use vectors but i dont know how to do it howw to make dynamic stack with vectors and how to sort it with selection sort?
View 1 Replies
ADVERTISEMENT
Nov 18, 2014
I do some research about getting the coordinates from the list items but without success. I would like to make that when i press down my mouse button that little blocks fall "out" my mouse and stack on top of eachother.
that first works. When i press the mouse button i draw squares and the fall to the bottom of the screen, but the stack part not.
here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
[Code]....
View 14 Replies
View Related
Nov 17, 2013
I am fairly new to dynamic memory allocation and I keep getting a segmentation fault in this code of mine. This is what the method should do:void sort StringsByReversePoints(char **myWords): This function sorts the char* values (i.e. strings) of myWords in descending order of point value by calling getWordPoints as a helper function and comparing adjacent words. This simple (but inefficient) sorting algorithm starts at the beginning of myWords array and sweeps to the end comparing adjacent values and swapping if they are out of order. After N (length of the array) sweeps the array is fully sorted. Note that efficiency can be improved by a factor of 2 by shortening each successive sweep by one, since the first sweep will have guaranteed the minimum point value word is the last element of the array, the next sweep guarantees the last two elements are correct, and so on....Additionally, if a given sweep results in zero swaps then the array is sorted and you can return immediately.
View 5 Replies
View Related
Jan 4, 2013
I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.
unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{
[Code].....
View 2 Replies
View Related
Oct 7, 2014
i'm implementing a playerclass for a game.. in the game there are multiple player types, weapons ect.. i just wanted to turn my players weapons into a dynamically allocated c_str. once i added my: Destructor, Copy Constructor and Overloaded Assignment Operator. My initial values became corrupted and i cannot fix them.
Player2.cpp
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include "player2.h"
#include "dice.h"
#include "gamespace.h"
[code]....
View 1 Replies
View Related
Mar 10, 2014
I rote this code in my program
JSONNode::const_iterator iter = root.begin();
for (; iter!=root.end(); ++iter) {
const JSONNode& arrayNode = *iter;
std::string type = arrayNode["type"].as_string();
if(type == "node")
[code]......
But when i try to ptint id of second item std::cout<<"Item Id ->>>>>>>>>>>>>" << collection[2].GetId() << std::endl; it gets a blank value. but size of the collection is 82, get the correct value for the collection size.
View 1 Replies
View Related
Mar 9, 2014
I wrote this code in my program
JSONNode::const_iterator iter = root.begin();
for (; iter!=root.end(); ++iter) {
const JSONNode& arrayNode = *iter;
std::string type = arrayNode["type"].as_string();
if(type == "node")
[Code] .....
But when I try to ptint id of second item std::cout<<"Item Id ->>>>>>>>>>>>>" << collection[2].GetId() << std::endl;
it gets a blank value. but size of the collection is 82, get the correct value for the collection size.
View 1 Replies
View Related
Mar 5, 2014
I'm working on creating a windows form with a listbox, textbox, and 2 buttons (add,remove). I need a way of removing every string matching the contents of the textbox from the listbox. Here's what I have:
for (int i=0;i<listBox1.Items.Count;i++)
{
//...
listBox1.RemoveAt(i--)
}
Seems to work, but I need a way to show a error message once the user clicks 'remove' and no items in the listbox match.
View 6 Replies
View Related
Jan 18, 2014
I am creating a student management system (using classes) for my assignment and am stuck with designing UI. I made the classes but am not sure what the best control is to display items from a Dictionary<> object. Right now I am using the ListView because of the columns in details view...just want to know if there is a better, simpler control I could use if i want to display data (without using sql)...or is the good old "next" and "previous" option the simplest?
View 9 Replies
View Related
Oct 21, 2014
im new to programming and new to C, just started with arrays and im somewhat stucked, where i have a .txt file which contains items and prices. I want the items and the prices split into 2 different arrays
The .txt looks like that:
orange 0.89
banana 0.79
apple 0.59
I now want to split the items in a char items[100][100] and float prices[100]. how to split this, preferably with fscanf ?
View 7 Replies
View Related
Nov 6, 2014
I'm creating a program that is combining functions to show a menu to a user then the user picks numbered items which results in the totalling of a bill for them.
Where I'm stuck is after they're entered their selections, how to take them and sum them up. I've been trying with a switch statement, but I'm not sure if this is the right method. Is it even possible to sum separate cases of a switch statement together? Below is the code I've gotten so far:
#include <iostream>
#include <iomanip>
using namespace std;
void showMenu ();
void showBill (double, double, float, double);
void changeDue (double, int);
[Code] ....
View 3 Replies
View Related
Oct 31, 2013
I am writing a program in Visual C++ 10 with 2 forms.
In the first form I have a textbox and a button. The button opens the second form.
In the second form, I have a button that changes the text in the textbox in form1 to an item from a listbox in form2.
Here is my problem. When I do the code for the button in form2 to change the textbox in form1 I get the errors:
error C2065: 'textBox1' : undeclared identifier
error C2227: left of '->Text' must point to class/struct/union/generic type
I thought maybe I should just include the "Form1.h" file but I can't do that because I already included "Form2.h" in form1 in order to be able to open the second form. If I try to include form1 in form2, it says that the code to open form2 is an error now.
My question is, how can I access identifiers such as "textbox1" from other forms and other files when I already used the first form to open the second form? I also want to know how to do this for all identifiers between all files.
how to print the selecteditem from a listbox into a textbox because that doesn't work by just setting them equal either.
Here is my code:
#pragma once
#include "Form2.h"
namespace Test1 {
using namespace System;
[Code].....
View 11 Replies
View Related
Sep 14, 2014
I'm using winforms and I want to set a checkbox on a dropdown menu item, but I don't know how to access the dropdown menu items.
I know ToolStripMenuItem items are attached to ContextMenuStrip items but I'm not sure how to navigate into the ToolStripMenuItem section to read/set those menu items.
ToolStripMenuItem listbox_font_size;
cmsListBox = new ContextMenuStrip();
cmsListBox.Items.Clear();
[Code].....
View 14 Replies
View Related
Aug 31, 2014
I have the following code in which I wish to dynamically delete items out of a vector based on the condition of the item in the vector.
The below code works but throws the error: "vector iterator not incrementable" at certain times.
It seems like this happens when the last item in the vector get's deleted. How do I solve this problem?
for (std::vector<PhysicsObject*>::iterator it = CurrentBoxes.begin(); it != CurrentBoxes.end();/*it++*/) {
(*it)->CalculatePhysicsOrientation();
(*it)->DrawMe();
glm::vec3* CurrentBoxPosition = (*it)->GetCurrentPosition();
if (CurrentBoxPosition->y < -750.0f) {
it = CurrentBoxes.erase(it);
}
++it;
}
View 9 Replies
View Related
Jul 24, 2014
Is there a way to set the height of a listBox to show all of the items without having to kick in the vert scrollbars? I've searched on this question but can't find how to do this.
I want to kind of auto-size my listBox height to accommodate my items (within reason and perhaps set a max height which would kick in the vert scroll bars.
View 9 Replies
View Related
Sep 2, 2013
I'm having problems fully comprehending how to do this task (I'm only going to include my function code since that's the basis of my problem). How should I go about getting my vector to print off 12 items per line. Here's my current function.
void printVec(const vector<int>& v) {
for(unsigned i=0; i < 12;i++)
cout<<v[i]<<" "<<endl;
}
View 2 Replies
View Related
Mar 31, 2013
What codes in c# will output items in a list box?
View 2 Replies
View Related
May 17, 2012
I have a data-bound ComboBox and I populate a DataSet with the values returned from a SQL query.
public DataSet CompanyArray(DataSet dataSet) {
SqlConnection connection = InstancesTest.IDataInterface.DefineConnection();
SqlCommand command = new SqlCommand();
command.CommandText = "usp_CompanyArray";
command.CommandTimeout = 20000;
[code]....
All this works fine. The reason I populated it in an array was so that I could sort the items alphabetically. I know I could just do an "order by" in SQL but I chose this route.
What I'm after is putting a "Please Select" at index 0 in the ComboBox. How can I move this value to the top of the list, without reordering the sorted list?And I don't really want to insert a "Please Select" as a first row in a database table.
View 2 Replies
View Related
Sep 11, 2013
I was wondering how can we know how many items exist in a dialogbox? If there any way that i can get the items ID in a dialogbox by having just the dialogbox's object or handler? Or any way that we can get a dialogbox content by coding.
View 6 Replies
View Related
Aug 25, 2014
I have this structures:
Code:
typedef struct {{
GList *presets;
} Settings;
typedef struct Preset preset;
struct Preset
{gchar *name;
[Code]...
I want to remove duplicates items in list if them have same freq value.
Example output with duplicate freq:
PHP Code:
name freq unammed 87.80 Radio ZU 92.20 Napoca FM 104.50 unammed 92.20 Rock FM 102.20
Want output:
PHP Code: Europa FM 92.20 unammed 87.80 Radio ZU 92.20 Napoca FM 104.50 Rock FM 102.20
write code to remove duplicates.
View 10 Replies
View Related
Dec 30, 2013
i want to create a program that allows a user to list all create new items, list those items, delete an item, modify an item, search for an item how can i do that This is my work so far
Code:
#include <stdio.h>
#include <string.h>
struct listofitems
char itemName [50];
float itemPrice = 0;
}
[code]...
View 1 Replies
View Related
Apr 1, 2013
Trying to do a homework assignment for a class and how to read a file into an array. I've looked in our book and on several other forums and cant seem to find any examples of this. Below is the assignment I'm working on. I have a shell of the program that I can get to run, but getting a .txt file to read into an array is something I cant seem to figure out how to do.
Write a program to read N data items into two arrays, X and Y, of size 20. Store the product of the corresponding pairs of elements of X and Y in a third array Z, also of size 20. Print a three column table that displays the arrays X, Y, and Z. Then compute and print the square root of the sum of the items in array Z. Compute and print the average of the values in array Z and print all values above the average of array Z. Determine the smallest value in each array using only one function.
Use the two data files named DATAX.TXT and DATAY.TXT.
You must use functions for the reading of the data, computing the average, printing the three column table and printing the values above average.
View 3 Replies
View Related
Jan 17, 2013
The process cannot access the file because it is being used by another process.
How can i edit CStdioFile to let me open the file while the program is running.
View 2 Replies
View Related
Oct 10, 2013
how to add a list of information from a file to a vector of a class. Here is my code:
Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>
[Code].....
View 6 Replies
View Related
Dec 27, 2013
Arrays are by far the most fun to work with and I really need see if its possible to enable an array to count apples, pears, peaches, from a group of three each.
If any of the fruit groups were chosen how might an algorithm be put together to count how many were chosen from each group. But lets take into consideration that these fruit groups are not supposed to be randomly generated, instead they belong as an array with certain amount of chosen occurrences. To show how many fruits were chosen from each group example, 1 from group 1, 2 from group 2, 3 from group 3 the out put is the important part because it shows the group and the occurrence of that group. the algorithm should be able to display the group with an occurrence as well
View 1 Replies
View Related
Oct 21, 2014
#include<iostream>
#include<fstream>
#include<iomanip>
#include <sstream>
using namespace std;
string padLeft(string,char,int);
string padRight(string,char,int);
string fromMoneyToStr(double);
[Code] ....
And don't know how to use padding functions so I can space my receipt.
View 9 Replies
View Related