C++ :: Building Database - Sort 2D Array Alphabetically
May 25, 2013
I'm using a database and im trying to sort a 2D array info[51][10] that contains 51 pieces of records and 10 different fields for each record. And, now I'm trying to sort a desired field in the 2D array alphabetically.
However, the other fields within the same record should be swapped together. (So that the information of the same records stays together).
Also, I am constantly experiencing a run-time error. Sometimes my program works sometimes the whole thing crashes... By opening the code in different folders sometimes works. But the problem is still here. Is there any way to fix this error?
bool swapped =true;
int j=0;
string tmp[10];
swapped =true;
j=0;
I have a homework assignment in C++ where I have to: "Write a program which asks user to input 10 students names. Store them in an array. Convert all the names to UPPERCASE without using any built-in functions. You must write the function to do that yourself. Lastly, sort the name in alphabetic order."
Here is my code so far, but my program won't compile, and the message it gives me is gibberish.
#include <iostream> using namespace std; void sortNames(string name[], int cap); void toUpper(string name[]); int minIndex(string name[], int i); void sort(string name[]); void swap(string name[], int i, int j);
is this correct? I used this sorting with numbers i don't know if it is the same with strings. When I run it, there are no errors detected, but when i try to view it, the inputs does not appear.
I'm attempting to build a column based database, and I'm new to C++ (just wanted to play around with building a column base database "for the fun of it"). I want to construct a very fast radix sort, that would allow me to quickly sort groups of columns based on integer values. My general preference is to take up more RAM to get more performance.
I'd like to build the radix sort by allowing 256 "buckets" to drop values in as I'm sorting. This allows me to sort through a group of 4 byte integers in only 4 passes. But assuming I'm trying to sort a large group of values (say 50+ million), I'm not sure what type of container to use for these. Also note I'm pretty unfamiliar with the "standard library", so below are my thoughts:
Vectors: -Pros: Easy to use, and very fast for sequential and random access inserts / reads -Cons: If they have to dynamically resize because a given vector wasn't large enough, this can apparently really slow performance. Unless I make another pass over the numbers before I start sorting, I wouldn't know how big to make individual the individual vectors. This means I either have to make them "too big" and waste space, or pay a performance price for either resizing, or scanning data first.
Lists: -Pros: Seems like I wouldn't have to specify size ahead of time, so I could just easily insert values to a given list. Also, since I don't need random access reads (I'll ready the "0" list sequentially, then the "1" list, etc. they should work fine. -Cons: I don't really know much about lists, but I'm not sure how easy it is to append a new value to the end of a list. I've read that standard library lists include both "forward" and "backward" pointers, which I don't need. Also, I find it hard to believe that there isn't some time taken up with memory allocation. If I build a list and append x million records in it, is it calling memory allocation routines x million times?
Or maybe there's another container type I should learn?
Again, my goal is to make this "fast", not "memory efficient". But having said that, the fastest way I could think of (use 256 vectors, each sized equal to the total number of members to be sorted) is just too much memory to burn - 256 times a vector big enough to hold millions of elements is too much.
Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.
Code: typedef unsigned long long UI64; typedef unsigned long long *PUI64; PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) { size_t mIndex[8][256] = {0}; /* index matrix */ PUI64 pDst, pSrc, pTmp; size_t i,j,m,n; UI64 u;
I've tried searching for answers around the web but everyone is using syntax that We haven't been taught before in class yet. I understand that the string library is probably the most efficient way of doing this but is there a way without using that library? Like using if, for, while etc. instead?
I've been told that using anything else other than the string syntax is far to complex but I think the more complex it is the more I will understand it.
I understand multimaps are key ordered. I have no problems with ints but when I put my char arrays in they are not alphabetically ordered. I must use char array and not <string>. Is it possible to alphabetically order them with char*
39 int c; 40 User *user; 41 char nameH[200]; 42 char line[200]; 43 int ageH; 44 double wH;
I'm trying to write a program that reads in from a .txt file the movie title, rating, director, actors etc. All I want to do is to just sort movie titles alphabetically and print all its attributes(director, actors). I tried using sort( movies.begin(), movies.end()) method, but it doesn't work.
I'm trying to finish this project which is supposed to read two files, and merge them alphabetically. I've written this code, and it compiles. But it isn't actually doing anything??The console opens and closes immediately upon running.
Code: #include <iostream> #include <fstream> #include <cstdlib> #include <string> using namespace std; #define hisFamily "The Adopted.txt" //His family #define herFamily "The Originals.txt" //Her family #define ourFamily "The Big Picture.txt" //Our family
I am trying to create a NFA from a regular expression. I have a grasp on reading in the regular expression and being able to make a stack from it. The part I am struggling on is mapping the characters in the regular expression to an integer indicating the variables order in the expression. I am just not sure how to go about this.
My code so far... Code: #include<stdio.h> #include<stdlib.h> #include "stack.h" int main(void) { char expression[80];//array to store regular expression
i built a programming language called jade that right now can only print. i want to add variables to it however. I am going to use a modified bajarne stroustrop calculator to handle expressions (ie will now include string manipulations and such), but I want to build a var class into the program to make it easier for the program. i want variables to act like python variabes, and arrays to act like python associative arrays. Ive scoured different containers, but they only work if the variable isnt an array in my language, because it will only have one type. the only thing i can come up with is a union and 4 overloaded = operators (for bool, int, double, and string) is there a better way to do this?
Basically I want to embed the QGIS canvas widget into a custom application. In order to do that, I need to build QGIS from it's source in order to obtain the devel *.lib, *.dll, *.h, etc. files required. To that result, I am trying to build either version 2.6.* or the current nightly build ~2.7 - 2.8 64 bit version. There is very little documentation on the x64 builds. Not to mention that CMake and I are not the best of friends.
My progress so far: - Successfully built the extremely out of date nightly build readme instructions of version 0.11 x86 - Partial success in creating CMake output to VS2010, but many required headers were not included such as gqsmapcanvas.h, (So even if I got it building I couldn't use the canvas widget in an application) *Note I updated the external packages to x64 versions, so it is not an architecture mismatch issue.
I have also had issues with QWT looking for QWT Polar header files, but I suspect this is another issue with the missing headers as most of the errors related to files contained in the original source from GIT.
I'm trying to arrange names alphabetically from a text file. Inside my textfile, it's like : "John", "Edward", "Peaches", "Anna"... etc.(It has thousand more names, all with quotations, separated by comma and I think it's not typed line by line... but using only one line). How can I read each name separately?
this code, it works if the text file contains names separated by lines and without commas and quotations. I do not know with the case I've stated above.
string numbers[1000]; string line; string number; string y; string x; int z = 1; ifstream myfile; myfile.open("names.txt");
[Code]...
This only shows the data inside text file. I'm new in c++.
A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be in front of the line and Yolanda will be at the end.
Write a program that will read in a file of names. Names should be read until there are no more names to be read. Use LineUp.txt as a test file for your program.
Once all the names have been read in display which student will be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.
These are the name in the LineUp.txt file if needed: Cooper Gavin Joseph Sierra Kacie Dylan Kaylee Will
Code: 1 121 12321 1234321 123454321 EDIT: the above pyramid looks like a doom.i.e 1-5 will be in center.1-4(L)1-3(L)1-2(L)1(L) similarly 1-4(R) 1-3(R) 1-2(R) 1(R)
I'm partly successful in building the requirement of the program.but cant able to think the logic for the other half. how can i proceed.below is the code written in c#.
Making/Building 3D Game Engines, Do I need to know anything related to ART or graphics in order to make them ? I mean, I do know that having a know how about vectors is VERY important, But I am no good at art, I suck. I have thought of getting a separate guy to do the art, as I'm more interested in writing code and then implementing it making use of the art that has been made, I'm just worried if I need to or not need to know anything about sketching or art in order to write a 3D Game engine ?
I am just getting back in to C++ after 10 years not doing any, contributing to an open source project. I'm adding in some functionality and am hitting a road block.
I need to send a multicast packet out on the network that is structured in a certain way. I have the definition, and know what data is going in each byte. I can successfully send a message using multicast, I now just need to send the right message.
I have used a char array to hold the message, as each char represents 1 byte, and I can transmit the array.
I am having trouble putting all of the data in the right place though. If my source data is a string, then I seem to be able to convert it, but if it is a short or int, then I keep getting errors when compiling. Similarly, two of the lines, (version and type) i initially tried using char arrays with a length of one.
Should I be using memcpy or a different function, or even be doing this in a totally different way altogether? This is the code that I am using, along with the packet structure:
//Construct a Zone Query packet // 4 bytes - Signature "Ohz " = 0x6f, 0x68, 0x7a, 0x20 // 1 bytes - Version = 1 // 1 bytes - Type (0 = Zone Query, 1 = Zone Uri) // 2 bytes - Entire message length = 12 + zone length // 4 bytes - Length in bytes of the zone ID // n bytes - Zone ID to query
[Code] ....
The errors that I get are:
error: invalid conversion from ‘short int’ to ‘const void*’ [-fpermissive] memcpy(buffer + 6, packetLength, sizeof(packetLength)); ^ [Code] ....