I am trying to create a program that will read data from a text file into a string. Afterwards I need to sort the data in ascending order and print it. So far my program reads the data but I'm not sure how to go about indexing the array.
For the past couple of weeks I have been working on a template to hold two-dimensional arrays. Right now I am puzzling over an indexing question.
There are many places in the template where I would like to use initializer_lists to refer to user-specified row and column ranges, particularly in member function arguments. A typical example would be a member function whose declaration would be along the lines of:
Code: Array<Type>::some_function(std::initializer_list<int> columns, std::initializer_list<int> rows); which could get called via
Code: arrayInstance.some_function({3:4}, {5:8});
It would be really nice to be able to use Matlab-style indexing to specify the last column, or the last row, in the Array object -- along the lines of
Code: arrayInstance.some_function({3:4}, {5:END}); where END takes the value -1, and can be defined in Array, or somewhere else.
The way I have tackled this so far was to write myself an Indices PODS class with two elements to hold start and finish values, and a constructor-from-initializer_list that looks something like this:
Code: Indices::Indices(std::initializer_list<int> range, int replace_value) { int const *it = range.begin();
So the elements of "range" give the values of Indices::start and Indices::finish -- but if either of them are entered as END by the user, they will be replaced by replace_value. (The default value of replace_value is END, so Indices::start and Indices::finish will never change if it is omitted.)
I also defined an Indices::endset(int) function to do the same thing for existing Indices objects:
Code: Indices::endset(int replace_value) { if (start == END) start = replace_value; if (finish == END) finish = replace_value; } Using Indices::endset, you can code up Array::some_function by modifying the above signature to something like
Code: Array<Type>::some_function(Indices columns, Indices rows) { columns.endset(this->M); rows.endset(this->N); ... }
This does work, and I've been able to use it in practice. However, it is klutzy. What I would really like to be able to do is have the Indices constructor handle value-replacements in "columns" and "rows", instead of needing to put calls to Indices::endset in every single Array<Type> member function that uses this approach.
The basic problem is that, when Array<Type>::some_function is called, there is no easy way of inserting Array<Type>::M and Array<Type>::N into the optional argument of the Indices constructor when "columns" and "rows" are being built.
The Indices class needs somehow to get access to these, and know which one is being used, M or N. So it needs to have some sort of deeper connection to Array<Type>, but I don't know what that connection should be.
I am trying sort my Calorie array and day array corresponding to each other but how to start i cant grasp the concept for some reason. I want it to sort by calories in descending order.
So instead of this...
Day: Calories:
1 200 2 500 3 400 4 600 5 100
I want this.....
5 100 1 200 3 400 2 500 4 600
#include <cstdlib> #include <iostream> using namespace std; //Prototypes int getDays(int); void getCal(int*,int); float calcSum(float,int*,int);
I have been tasked with sorting a text file with some numbers in it. For example, there can be 5 numbers in it: 1,2,3, 4, and 5. However, they are out of order (3,2,4,1 and 5). I need the numbers in numerical order. How can you sort the numbers into a new file?
Bubblesorting? I can not use arrays in this program. I have already determined the minimum number in the file.
I'm trying to write a program that should output, in a tabular form, the name of the algorithm, size of the array, number of comparisons and number of swaps. I am really, really, really bad at arrays and comprehending how to output variables from several. Especially in tabular form />
My questions: 1 - How do I make the array size change from 10 to 100 to 1000? 2 - How do I populate the array's with random non-repeating numbers? 3 - How do I make each algorithm count the # of comparisons and swaps? 4 - How do I return the counted comparisons AND swaps (in one return function??) and then print them?
Having trouble with homework involving (title). Here is the assignment:Write a program that allows the user to enter 10 numbers from the keyboard. Sort the numbers using any sort routine you wish. The output from your program should be 2 columns of numbers. The left column should be the numbers in the order they were originally entered and the right column should be the sorted list. The columns should be labeled. You will need 2 arrays to accomplish this.
Use separate functions for input, sorting, and printing.So, I have to use separate functions for each of these. I would think it would be easiest to do the input in Main() and then the sorting and printing in another function, but of course since you can't return arrays I am kind of stuck on how I return the new array after sorting. I thought about doing the sorting in Main(), but then I would need to still do the original arrays input in a function and would still run into the same problem.
Here is what I have so far:
Code:
//Cameron Taylor #include <stdio.h> #define MAXARRAY 10 int highLow(int[], int); int print(int[], int[], int); int main (){ int unsorted[MAXARRAY], i, j, temp;
[Code]...
I know it seems simplistic right now, but I am just trying to get it to work first and then go back and beautify it up a bit.
Write a program using user-defined function to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.
Write a function to read and display the contents of names and marks. You then ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student.
Next, sort the arrays, write them out and then ask the user for a name to search for. This time use the binarySearch to return -1 or an index. Display the student's name and mark if found.
void getNames(ifstream& inStream, string names[], int marks[], int numElts); int linearSearch(const string names[], int numElts,string who); int binarySearch(const string names[], int numElts,string who); void selectionSort(string names[], int marks[],int numElts); void displayData(const string names[], const int marks[], int numElts); [Code] ....
Now I have worked up some stuff in parts but I am so lost and confused with these specific requirements: Previous questions asked me to sort out a linear search, a binary search and
LINEAR SEARCH:
int searchList(int list[], int numElems, int value) { int index = 0; // Used as a subscript to search array int position = -1; // To record position of search value bool found = false; // Flag to indicate if value was found
Class programming project where we declare two arrays, a sting array containing the names of the boroughs and an int array which which holds accident number for each borough. The main function calls getNumAccidents() function to fill the array. it then calls findLowest() to learn which borough had the fewest accidents. It should print out the accident numbers for each borough and then out the borough and accident number with the fewest accidents.
I'm able to get the program to kind of work. When I run it everything works fine but I am not able to get the arrays to sort and match up correctly..
#include<iostream> #include<iomanip> #include<string> #include<cstring> using namespace std; class combineSort { public: combineSort() {
I am having some problem with my quick sort problem. My program is supposed to create 5 arrays with 5,10,15,and 20 random integers, respectively. Then it should sort those arrays, where the numbers are bigger or smaller than the middle element in the original array! The program I wrote should do that but, its not! The program just keeps running infinitely!
#include <iostream> #include <cstdlib> using namespace std; void p(int k[],int left, int right) { int i = left, j = right;
I have having trouble looping through the list in the update section to update each object in the rectangleList. I am not sure how to format it because it is only drawing one and it does not move across the screen. I thought this section of code would work and loop through each object and make each one move but it does not.
for (int i = 0; i < rectangleList.Count; i++) { enemyPosition = new Rectangle(rectangleList[i].X + 2, rectangleList[i].Y ,enemyPosition.Width,enemyPosition.Height); } List<Rectangle> rectangleList; protected override void Initialize() { rectangleList = new List<Rectangle>();
I've spent some time trying to performance test various methods of loading / accessing a file, either into memory or through a memory mapped file, but I am having some trouble.
FILE * pFile; std::ifstream ifs; MapViewOfFile
I'm have trouble because Windows appears to cache the file, so I am getting very mixed results. Sometimes a huge file (100's MB's) will load quickly, other times almost instantly.
How to stop Windows from doing whatever it's doing, so I can see the real time taken to load/access a file from disk?
My below code is createing databases(database here is a kd tree) and indexing one image per database. I have two classes LastDatabaseTndexingPolicy and another forwardingDatabaseaccessor.cpp .
I am calling the GetDatabaseToAccess() function from forwardingDatabaseAccessor.cpp class .GetDatabaseToAccess() function is present in LastDatabaseTndexingPolicy class and it returns the database created as a pointer and using that database pointer we call another function which actually indexes the image to the database .
Now my issue is i am not able to have multiple threads act on the following functions as DatabaseAccessor_ptr db which is in the following file is coupled with two functions and however i put locks in the LastDatabaseTndexingPolicy file as below i end up getting synchronization issue ..........
Hence now i am using a single lock in forwardingDatabaseAccessor.cpp and serializing the code,. How can i change my design to parallelize this code .........
In ForwardingDatabaseAccessor.cpp we are calling function from LastDatabaseTndexingPolicy as shown below:-
DatabaseAccessor_ptr db is something which needs to be synchroinized. I tried createing 256 databases with one image each and when i run this code i ended up creating 175 databses and though i was restricting in code with locks that every database has only one image i ended up having two images in single database ..... ideally i had to get only one image per database but i got two images in few of them hence instead of 256 database this code created 175 or so databases.
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) { int comm = 10; int targ = 5; int death; struct AI_WORDS
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it into 4 x 2 bytes 12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) { int first = (mem_address&4278190080)>>24; int second = (mem_address&16711680)>>16; int third = (mem_address&65280)>>8; int fourth= (mem_address&255);
I'm working on a program for payroll that will calculate and display a list of payroll variables (including net pay) then run again sorting the net pay. So the program should run once display all the variables with the net pay not sorted then run a second time with the net pay sorted.
I've written a program. It is working. But it only runs once and it and it only displays the results with the net pay after it's sorted. What I need to do in order to get it to run a first time without sorting the net pays before it runs the second time sorting the net pays.
I'm trying to take a users input and break it up into four separate numbers, then take those numbers and arrange them from smallest to largest.So far I can't seem to get them working right.
Code:
# include <stdio.h>main () { int inputVariables[4]; //where userinput goes after being broken up int arrangedValues [4];// the user values arranged lowest to highest int i; int j; }
So my ongoing work sorting my net pay program continues.I've got it working to the point where it sorts the net pay and only the net pay. I've been told I can comment out the other variables (hours worked, hourly rate, etc...) with the exception of First Name, and Last Name which I need to sort along with Net Pay.I need to sort First Name and Last Name along with Net Pay so that while Net Pay is being sorted it still corresponds to the same individual.
Right now as I'm only sorting Net Pay and individuals end up with different Net Pays as the sorting occurs. This is the programs current output (Pre Sorting)
John Doe 900.00 Jane Smith 720.00 Chris Davis 450.00 Sara White 832.00 Alice Baker 756.00 Laura Jackson 486.00 Jack Benson 405.00 Kate Russle 1400.00 Matt Jones 880.00 Fred Shultz 1150.00