C :: Ferry Loading Using Two Queues - Can't Enter In Data After First Set Is Scanned
Feb 25, 2014
I'm trying to solve the ferry loading problem using two queues. My problem is I can't enter in data after the first set is scanned in, I'm assuming there is a problem with my loop, such that the scan function doesn't get called after one iteration. In the example I marked the data I can't enter. An example correct input would be:
correct input:
1 - can enter data20 4 - can enter data
380 left - can enter data
720 left - can't enter data
1340 right - can't enter data
1040 left - can't enter data
What is the most efficient (fastest) way to load data from a file on HDD to RAM? (which would allow to only load a limited section of that file - eg. load only half of the file etc.)
What is the best / most efficient way to load polymorphic data from a file? I thought you could have an enumeration and for each item to load from a file you could have an integer at the start specifying the type of data, but I think there must be a better way I'm just not sure what.
Example of what I mean:
//The syntax isn't really that important for explanation class base; class a: base, b: base; enum polymorphicType { A, B };
and in the loading code you would have (this is the bit I think could be improved):
polymorphicType t; File >> t; if(t == A) { newObject = new A; } else if(t == B) { newObject = new B; }
I think there is probably a more efficient/better way of doing this I am just unaware of it.
Heres what I am suppose to do, So it doesnt seem hard to understand my messy code!
1. Gotta load the file "FactoryData.txt" 2. Load all values in my 2D array (array[5][3]) 3. Print out the array to ensure that the copying went by well.
Heres my problem:
1. The for loops is REALLY off in my eyes. From my knowledge (correct me if im wrong), its suppose to be for(r=0;r<5;r++) not <=. BUT somehow im getting the results I want (in terms of formatting). HERE IS MY OUTPUT
I am currently working on a project that requires me to "load the data in the file into array at the beginning of the program."
I have a text file with data, and I need to populate an array with the information. From then on, I am supposed to be able to add, display, and search that array. However, I can't figure out how to add the data from the file into an array. I was trying to find out how to search the text file itself. So it threw me off balance and I've been staring so long at the screen I can't really focus.
I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:
I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.
I want to compare the part of the character array with the scanned input. I've initialized the character array (colourCompare).
What I want to do is, if the input colour matches up with one of the elements in the colourCompare array, it will then read the next value(I did not include "read the next value part"). If the input does not match up, then it goes back to the scanning part.
I want to do simple program to capture some 5 surnames of people(employees) - using array and pointers. Well I understand a bit of arrays and I know how to loop through.
How can achieve this? This holds the key to my understanding how pointers work and can be used with char or strings.
fprintf(stderr, "Data is %s when first entering ins_llist loop. ", data); q = malloc(sizeof(struct lnode)); if ( q == NULL ) return(NULL); }
[code]...
Trying to figure out a way to sort as i enter my data into the llist. What is in red and blue is what I've been messing around with to try and see if maybe i can get it to sort but it is not. When i flip sign, the order changes opposite, but i cant see how to sort each item as i go. Maybe i am too tired right now, lol, been working on this program for what feels like 30 of the past 24 hours haha.
I have a small program to calculate the value of salary. I want to user to be able to enter more than one user using array and finally calculates the average salary of all users.
Here is the code
Code: #include <iostream>#include <conio.h> using namespace std; int main() { const int months=3; double net_pay; string EmpName;
I've seen some threads that include the information about what data types one has to use usually to put a number of 12digit. But honestly speaking none of them works for me & it takes me a lot suffering about the data type. Even I've googled but I didn't get any specific result.
So, which data type I'd have to use to enter 12digit number.
I'm writing a code to find the largest prime factor of the number 600851475143
I have the following code which will find the minimum size queue among a vector of queues and the minimimum size queue will enqueue(push) the int
std::vector<std::queue<int> > q void enqueue(){ int min_index = 1; std::size_t size = q.size(); for( i=2; i<size; i++) //accessing loop of queues if(q[min_index].size() > q[i].size()) min_index = i; // Now q[min_index] is the shortest queue q[min_index].push(int) }
Now my another paradigm is to do the dequeue(pop) operation in another function(shown below), bt i need to access all vector of queues declared in enqueue() function. how can i access the loop of queues given in the enqueue() function?
void dequeue(){ //q.pop operation , access all the queues in the loop of queues } willq[i].pop(int);
Access all the queues in the enqueue function and does the pop operation?
i have a paradigm where a integer before gets enqueued to a queue, the loop of queues in a vector is searched and integer is enqueued to a queue which has minimum size among the queues. the following code shows the operation.
#include <vector> #include <queue> std::vector<std::queue<int> > q int min_index = 0; std::size_t size = q.size(); for( i=0; i<size; i++){ //accessing loop of queues if(q[min_index].size() > q[i].size()) min_index = i; // Now q[min_index] is the shortest queue} q[min_index].push(int)
next i am trying to extend my paradigm with that the condition the integers should be enqueued to the shortest queue until it becomes maximum size among the queues.
do{ q[min_index].push(int) } while(q[min_index].size > queue sizes in the vector loop except this queue )
how to search the loop of queues of vector in the while ()
Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;
I'm having troubles with this program I made. Put it simply, it's a basic program using Queues. Whenever I try to input a value, my compiler(Dev C) suddenly stops working. The .exe file crashes and I've no way on how I can execute my program.
Code : #include<iostream> using namespace std; int *queue; int rear, front, queueSize; void enqueue(); void dequeue(); void display();
I have a paradigm in a loop of queues of a vector,if a condition is true,increase sizes of the queue of that particular queue in the loop of queues, if condition is false, the queuesize is left as such in loop of queues. After this operation i need to search the queue sizes of all queues and enqueue in the shortest queue.
I would like to make a program that automatically launches and loads a file when a file of that file type is double clicked within windows. As said I am unsure where to look for some information as to how to do that, and so turn to you all. Is there a simple way of doing such a thing without using any external libraries, if so, a simple tutorial or link to a reference for this; if there is no way of doing this without externals what would be a small and simple to use library for this?
Alright i have my program and it loads the vector fine and even puts the vector into a txt file but when it comes to lloading it again im not sure if it works or not
The program is supposed to read in a text file, load it into an array and assign a character to each number in the array (so for this I'm thinking I'll be creating 2 arrays, an int array with the numbers read in from the file, and a char array with the characters assigned to the numbers). It will then print these two arrays. It's then supposed to go through the initial int array and search for any numbers whose values differ from their neighboring values by more than one, if such a value is found, it's supposed to give the number the value of the average of it's neighboring values. It's supposed to make all these corrections and then assign characters to these corrected numbers and print out both arrays.
How to load the array from the file. My textbook seems to do a good job of covering arrays and files, but it doesn't really bring them together and talk about building arrays from files. Here is what the file looks like, the first number is the size of the array.
#include <iostream> #include <fstream> using namespace std;
[Code]....
When I attempt to compile this (I'm working on a Linux system), I'm getting several errors:
prog1.cpp: In function ?int main()?: prog1.cpp:37: error: expected unqualified-id before ?[? token prog1.cpp:39: error: ?numArray? was not declared in this scope prog1.cpp:39: error: expected primary-expression before ?]? token
I have this game that I have to make modifications to, it compiles without errors but when I run the game it breaks. Im not very experienced with c++ but im assuming theres an error because it cant find or load the mesh, when it runs, visual studio breaks at the mesh.cpp line 638
I am trying to copy the stats from the save file "lol.txt" to main. I posted what the contents of the file below, but for some reason the I get for output jiberish and I cannot seem to figure out why.
I have a function that essentially takes a screen shot and saves a pointer to it as a structure. I would like to use the same structure for bitmaps that I load from files.
Code: typedef struct _BITMAPCAPTURE { HBITMAP hbm; LPDWORD pixels; INT width; INT height; } BITMAPCAPTURE; BOOL CaptureScreen(BITMAPCAPTURE* bmpCapture) {
[code].....
The handle to the bitmap, as well as the width and height are all easy enough to get but I'm unsure of how to get the pixels.