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

correct output: 3

my incorrect output: 1

Code:

#include <stdio.h>
#include <stdlib.h>
#include "my_linked_list.h"
#include "my_linked_list.c"
#include "status.h"

[Code] ....

View 6 Replies


ADVERTISEMENT

C++ :: Loading Data From File To RAM?

Mar 29, 2013

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.)

View 3 Replies View Related

C++ :: Loading Polymorphic Data From A File

Jun 11, 2014

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.

View 4 Replies View Related

C/C++ :: Loading Int Data From File To 2D Array

Apr 28, 2014

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

Quote
300 450 500 510
510 600 750 627
627 100 420 530
530 621 730 200
200 50 58 100
100 83 4 5
Press Enter to return to Quincy...

View 8 Replies View Related

C/C++ :: Loading Data From Text File Into Array

Jan 25, 2015

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.

View 7 Replies View Related

C++ :: Pointer-based Data Loading From A (text) File

Dec 4, 2013

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:

class buyerListType
{
public:
setCustomerInfo( ....., productListType* p);
.
.
.
private:
productListType* productBoughtRecord;
.
.
};

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.

View 11 Replies View Related

C :: Comparing Part Of Character Array With Scanned Input

Feb 25, 2013

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.

Code:

char colourCompare [12][6] = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Gray","White","Gold","Silver"};
float resistanceCal() {

[Code]....

View 14 Replies View Related

C/C++ :: Using Pointers To Enter Data?

Nov 6, 2013

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.

View 2 Replies View Related

C :: Way To Sort As Enter Data Into Llist

Oct 19, 2013

Code:

struct lnode *ins_llist(char *data, struct llist *ll){
struct lnode *p, *q;

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.

View 2 Replies View Related

C++ :: Using Array To Enter Number Of Users And Their Data?

Dec 10, 2014

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;

[Code].....

View 2 Replies View Related

C :: Exe File Stops Working And Not Able To Enter Data

Sep 13, 2013

I am trying to enter data to a structure some 8 times, but not able to do so. Here is my code.

Code: #include<stdio.h>
struct _Timer {
unsigned int HH;
unsigned int MM;
}Time[8];
[code]...

But when I enter any data and press enter , the .exe file stops working and not able to enter data.

View 4 Replies View Related

C :: Which Data Type Have To Enter To Get 12 Digit Numbers

Jul 8, 2013

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

View 4 Replies View Related

C++ :: Hash Tables And Queues

Jun 3, 2013

For my homework I need to create a hash table with a size of 7. I also need to create a queue that holds 3 names maximum for each table position

View 1 Replies View Related

C++ :: How To Access Vector Of Queues In Two Functions

Jan 20, 2013

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?

View 1 Replies View Related

C++ :: How To Search The Loop Of Queues Of Vector

Feb 14, 2013

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 ()

View 13 Replies View Related

C :: Generate A Program That Will Allow User To Enter Data For A Stock And Calculate Amount Of Stocks

Oct 5, 2013

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;

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

Code:

void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
}

[code]....

View 6 Replies View Related

C++ :: Multidimensional Arrays - Enter Data Into Table And Display On Screen In Tabular Form

Sep 8, 2014

Write a program to enter data into a table and display on the screen in tabular form. I want to know where are the errors.

#include<iostream>
using namespace std;
int main() {
int table[3][4];
int r,c,i;
r=c=0;
while(r<=2)

[Code] .....

View 3 Replies View Related

C++ :: Queues Program Suddenly Stops Working When Input Value

Feb 22, 2013

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();

[Code] ....

View 1 Replies View Related

C++ :: Increase Sizes Of Queue In A Vector Of Queues And Find Shortest Queue

Feb 20, 2013

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 want to do something like the code given below

#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();

[Code] ....

How to implement this logic?

will q[i].size=q[i].size+5 increase the queuesize by 5 for the ith queue?

View 12 Replies View Related

C++ :: Loading Menu For Files

Jun 11, 2014

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?

View 2 Replies View Related

C :: Library For Loading Images In PNG?

Jan 29, 2015

What's the best performance library for loading images in PNG?

View 5 Replies View Related

C++ :: Loading A Vector From A File?

May 21, 2014

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

#include <iostream>
#include <string>
#include <fstream>

[Code]....

View 2 Replies View Related

C/C++ :: Loading 2D Array From A File?

Sep 10, 2014

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.

10
7 6 9 4 5 4 3 2 1 0
6 5 5 5 6 5 4 3 2 1
6 5 6 6 7 6 8 4 3 2
1 5 6 7 7 7 6 5 4 3
5 5 6 7 6 7 7 6 5 9
5 6 7 6 5 6 6 5 4 3
5 6 7 9 5 5 6 5 4 3
5 5 6 7 6 6 7 6 5 4
5 9 5 6 7 6 5 0 3 2
5 5 5 5 6 5 4 3 2 7

And here is the code I have so far:

#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

View 14 Replies View Related

C/C++ :: Game Mesh Not Loading

Sep 5, 2014

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

View 14 Replies View Related

C/C++ :: Loading File With Fscanf?

Apr 21, 2015

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.

#define _CRT_SECURE_NO_WARNINGS
#define MAX_NAME 31
#include <stdio.h>
int main(void){
char sName[MAX_NAME];

[Code] .....

View 5 Replies View Related

Visual C++ :: Loading Bitmap In Particular Way?

May 25, 2013

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.

View 2 Replies View Related







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