C/C++ :: Random Array Filling Of Airline Seating Assignment?

Dec 25, 2014

int firstarray[12][7] = { };
double firstClass(int airplane, int seats, double price)
{cout<<setw(60)<<"---------------------...
cout<<setw(60)<<"You are in **first class** booking screen

[Code] .....

The thing is, The first 2 rows having 7 columns like this:

0000000
0000000

User gives an input of seats reserved, for example user inputs 3 seats, then the program should give output like:

1110000
0000000

I will not ask any specific seat but put assign seats randomly where available.. How to do it?

View 5 Replies


ADVERTISEMENT

C :: Filling 2D Array

Mar 24, 2013

So here is the C code:

Code:

#include <stdio.h>
int main(void)
{
//2D Array
int array[2][2];
int number = 1;
}

[code]....

The array is not filled incorrectly for some reason, more specifically the first row.The first two cycles of the for loop seem to work correctly. One if the bugs seems to occur on the third. when array[0][2] is filled with number 7, for some reason array[1][0] changes it value to 7 as well.

View 2 Replies View Related

C/C++ :: Theater Seating Project - Getting Running Total

Dec 21, 2014

I am having trouble getting the running total to in this code, it runs but in case 4 the part with the call for the running total is just giving me the same number 589505315. Hope it is just a simple overlook on my end like usual. Here is my code.

#include <iostream>
#include <iomanip>
using namespace std;

int Show_Menu (); //To show Menu
int Purchase_Ticket (); //To purchase ticket
void Show_Chart (); //To show the seating chart
const char FULL = '*'; //Seats taken
const char EMPTY = '#'; //Seats open

[Code] .....

View 1 Replies View Related

C :: Filling Array With Even And Odd Number

Jun 25, 2013

I have this snippet :

Code:
#include<stdio.h>
#define LEN 3
int main(void)
{
int a[LEN] = {0} , b[LEN] = {0} , i = 0;

[Code] ....

/* OUTPUT :
a[0] = 2 , b[0] = 1
a[1] = 0 , b[1] = 3
a[2] = 0 , b[2] = 0 */

The problem is some elements of the array would be remained zero and unused. Is there any solution about this wasting of memory?

View 7 Replies View Related

C :: Filling 2D Array Complexity?

Mar 24, 2013

Assuming that we have :

Code:
int arr2d[rows][columns] ; // Not valid syntax of course ... let be arr2d rows * columns size
for(int i=0; i<rows; i++)
for(int j=0; j<columns; j++)
arr2d[rows][columns] = some_value;

What is the complexity? I believe O(n) and not O(n^2) on this case because if you have 3*3 size you would put 9 elements (from 9 elements input of course)... for each input you have one insertion and that is the meaning. Same as 4*4 size 16 input times 16 insertions .. or 5*5 and so forth...

View 8 Replies View Related

C :: Filling Float Array

Oct 6, 2013

What am I doing wrong here.

Code:

#include <stdio.h>
#define N 25
int main () {
int s,min,sec,total,mins;
float speed,splits[N];

[Code] ....

View 2 Replies View Related

C++ :: Filling Int Array Using Binary File

Mar 2, 2013

I am trying to do binary filling. This is the Constructor code, you will see a couple of integer arrays:

Doc::Doc ( int useridValue , string firstnameValue , string lastnameValue , string deptValue
, int dayinhourValue[] , int dayinminValue[] ,int dayouthourValue[] , int dayoutminValue[]
, int timeperpatValue , int appValue[] , int applimValue[] ) {
setuserid(useridValue);

[Code] ....

it gives an error:

void Doc::setdayinhour ( intdayinHOUR[] ){
for(int i=0;i<7;i++) {
dayinhour[i]=dayinHOUR[i];//highlighted area
} }

I am using this code for filling:

void main () {
Doc r;
ofstream outDoc("docdata.dat" , ios::out | ios::binary);
if (!outDoc) {
cerr << "File Could Not Be Opened" << endl;

[Code] ....

View 5 Replies View Related

C :: Word Search Program - Filling 2D Array

Oct 5, 2014

I am currently working on writing a word search program. However, I am stuck on reading the used input into the 2-D array. The code I've posted below is only dealing with the user input (I'll work on the word search part once I know i am correctly reading in the user input). I know the coding is bad practice with the use of hexadecimal, and getchar() ect. But I am currently using a microblaze microprocessor and this is just the way microblaze can interpret the information. As for the infinite while loops...that can be changed just trying to figure out how.

My question is how could I change my code to correctly read in the user input into the 2-D array?

Code:
#include "platform.h"#include "xparameters.h"
#include <stdlib.h>
#include <stdio.h>
#define MAX 20
int main() {
char grid[MAX][MAX], word[30];
int i, j, arr[2],num;

[Code] ....

View 10 Replies View Related

C++ :: Filling Dynamically Allocated Array With Values

Jan 12, 2013

Just trying to fill a dynamically allocated array with values then I want to print out the values using pointer method:

#include <iostream>
using namespace std;
long * extend_arr(long int arr[], long int length, long int val) {
long * array2 = new long [length + 1];
for (int J = 0; J < length; ++J)
array2[J] = arr[J];

[Code] ....

When this runs, I get an array with random numbers in it. For example, just trying to print the first value in *Block gives me random numbers each time. What is wrong with this as to why it is not holding the right values?

The extend_arr works perfectly fine, because when I try to access the values in the array using indexes (arr[0], arr[1], etc) it shows the right output, but using pointers does not. How can I make it work?

Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 134561 23 29 640 112

As you can see, the primes end at 97 but it just keeps printing more

It now prints the correct values in the function if I set the last value in the array to 0. arr[length] = 0;

Now if I wanted to print the values in the array within main, why is that not working?

Nvm, I just changed the void function to return a pointer to an array.

View 2 Replies View Related

C :: Filling Structure Client / Storing Different Instances In Array

Mar 31, 2013

Here is what I have going on.

Code:

struct client {
char firstName[stnd];
char lastName[stnd];
long ID;
char email[stnd];
float funds;
float wager;
}

typedef client...I would like to have these fields filled with this function below and stored in an array... Basically Multiple users and this is my function for it, if I can get it to work proper -.- .... I don't get syntax errors but I do get warnings

Code:

void getct(client *cl, int *pclientCounter) {
char input[buff];
char *pinput = NULL;
int typef = 0;
int lengthf = 0;
}

[code]....

View 3 Replies View Related

C/C++ :: Filling Array With Non Letter Char And It Outputs A Number?

Sep 2, 2014

I am trying to fill an array with blank spaces and instead i get the number 32 over and over, i think this is the ANSI code for that character. how do i get the character itself?

char values[max];
for(o=0;o<=max;o++)
{
values[o]=' ';
printf("%2d ", values[o]);
}
printf("
");

View 1 Replies View Related

C++ :: Creating / Filling And Deleting Dynamically Allocated Array Of Objects

Jul 26, 2012

Project compile successfully but console turn off with "Windows " with error doesn't print or get anything

Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>

[Code] .....

View 2 Replies View Related

C++ :: Airline Reservation - Assign Seats On Each Flight

Jun 24, 2013

A small airline has just purchased a computer for its new automated reservation system. you have been asked to program a new system. Develop a program to assign seats on each flight of the airline's only plane (capacity = 10 seats) your program should display the following alternatives

Please type 1 for "SMOKING"
Please type 2 for "Non-Smoking"

if the person types 1, your program should assign a seat in the smoking section (seats 1-5). If a person types 2, your program should assign a seats in the non-smoking section (seats 6-10). your program should then print a boarding pass indicating the person's seat number and whether it is in the smoking or non-smoking section of the plane.

Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seats is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.

Your program should never assign a seat that has already been assigned. When the smoking section is full, your program should ask a person if it is acceptable to be placed in the non-smoking area section ( and vice versa ), If yes, make the appropriate a seat assignment. If no, print the message " Next flight leaves in 3 hours! ".

View 5 Replies View Related

C++ :: Save Top 10 Scores In Simon Game - Filling Array Not Working Correctly

May 17, 2013

I wrote a Simon game, and wanted to save the top 10 scores. I was working right, until I decided I wanted to still be able to read the file if someone enters a name containing spaces. Now, the results aren't right.

void FillScoreList(string Simon_Names[], int Simon_Scores[]) {
ifstream Simon_HiScores("Simon_Data.txt");

if (Simon_HiScores.is_open()) {
for( int x=0;x<10;x++){

[Code] ....

Even without trying to read names with spaces, I'm getting

dad 1
0
340176
0
... either a long number or a zero. No names

View 4 Replies View Related

C++ :: Airline Reservation Simulator - Binary File Errors

Aug 11, 2014

For a big project for school I have to make an airline reservation simulator but I have run into a problem. I want to save the the flight code and its location in a binary file so that I can obtain a code according to the location but this happens:

[URL] ... (link to current output and expected output)

Here is the source class

class file {
private:
char code[8];
char from[20];
public:
void input();

[Code] ....

View 4 Replies View Related

C :: Assignment Of Element Of 2D Character Array To 1D Character Array

Jul 4, 2014

Can we do this :

Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];

View 3 Replies View Related

C++ :: Filling A Vector With Elements?

Mar 21, 2013

I'm writing a program with a class containing a private std::vector<bool>. I chose bool because the vector represents a 2D array (think grid) and I only need 2 states per cell. I kept it one-dimensional as this hardly complicates things.

My problem is that I don't know how to initialize the vector, i.e. fill it with 0's.

The grid's resolution is not known at compile time, so I imagine I have to set the size (and content) of the vector in the class constructor.

Here's what I have tried among several things:

Code: World::World(const u_short worldsize)
{
grid.reserve(worldsize * worldsize); // grid is the private vector; square dimensions.
std::fill(grid.begin(), grid.end(), 0);
std::cout << grid.size();
} The output is 0. Only std::vector::push_back seems to have an effect on size(), but judging by its description, it doesn't look like the right candidate to populate a vector with zeros. Correct me if I'm wrong.

Frankly I expected line 3 to set the vector's size.

View 5 Replies View Related

C++ :: Filling A Vector With Structs

Feb 1, 2013

How to fill a vector with structs that are read in from a separate file. Each line in the file would read for example "Doe John M 26" for the name of the person, gender and age. I just need to get pointed in the right direction so I can get this started.

View 2 Replies View Related

C++ :: Filling Arrays From A Text File

Jun 20, 2013

I am having a trivial trouble on how to create three different arrays from a text file. I am a beginner in C++. I have a .txt file containing a string of 'float' values as below:

0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
1.3

//----------------------

Now, I want to make three arrays, p1[], p2[], and p3[] from them, so that
p1[] has elements from line: 1, 4, 7, ...,
p2[] has elements from line: 2, 5, 8, .., and
p3[] has elements from line: 3, 6, 9,... of the .txt file.

My original file has a huge amount of data, so I would have to use a loop, but I cannot think of a way to fill my arrays as described.

View 3 Replies View Related

C++ :: Initializing / Filling Container With Sample Of Another

May 22, 2014

I have a vector that I want to use to source another vector, something like copy_if, but without the need to allocate space first:

bool is_odd( const int x ){ return x % 2 == 1; }
std::vector< int > numbers = { 1, 2, 3, 4, 5, 6 };
std::vector< int > odd_numbers;
std::sweet_function( numbers.begin(), numbers.end(), odd_numbers, is_odd );
// odd_numbers is { 1, 3, 5 }

Even better might be a std::transform_if

View 5 Replies View Related

C# :: Filling And Sending A POST Form

Mar 21, 2015

I'm building a project in my free time and in the last part of it I need to fill a form of a website and then 'hit submit', but how it can be done. Btw the form is a 'POST' form so it's harder than a 'GET' one.

View 2 Replies View Related

C Sharp :: Filling In DataTable Using OleDb

Jul 2, 2013

For some reason I am having problems doing this simple task. I just want to run a query in Access to select a field from the table that is "like" the string being inputted.

However, the dataset comes back empty...well not empty, I get a column name but no data. So when I type in

ds.Tables[0].Columns[0].ColumnName

I get the column name coming from the database ("ParcelNumber"). When I run the query inside Access I receive the desired information. But when I try to check for the info in code

ds.Rows[0]

I get "There is no row at position 0".

public DataTable FindFullPNusingPartialPN(string _parcelNumber)  {
                 OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + ConfigurationManager.AppSettings["TaxCert_Database"]);
DataTable dt = new DataTable();

[Code] ....

View 1 Replies View Related

C++ :: Filling Memory Causes Application Crash

Jul 5, 2012

I have a question about allocating 2MB memory then filling it...

@ Platform:
=> DOS, and application is compiled/linked via Watcom C + DOS32/A (...memory model is "flat" mode)

@ phenomenon:
1. I allocate 2M memory by calloc() function. Then I got "!NULL" and it means allocating 2MB memory is ok( right ? )
2. then I tried to "fill" this 2MB memory by for loop(one byte by one byte) like below:

for( DWORD i=0; i<0x200000; i++) {
*((BYTE *)(A[0].B[0]->C) + i ) = 0x5A; // C is 4-byte address value
}

here :
* DWORD means "unsigned long(4-byte)" and 0x200000 means "2MByte"
* in actual case the value of pointer(to allocated memory) is 3019AF3C(~768MB) <- running in flat mode...

3. after filling this range of memory(2MB) the application crashed...

@ my observations:
1. if allocating 2MB and no fill(no write data to memory) => OK
2. if allocating 2MB and just fill the former 32 bytes => OK
3. if allocating 4KB and fill all => OK

my question is: why can't I filling this 2M memory totally "even memory allocation succeeds" ?

View 5 Replies View Related

C++ :: Filling Vectors With Pointers To Account Objects

Jul 27, 2013

So I'm trying to fill a vector with pointers to account objects.

std::vector<account*> fill_vector() {
std::vector<account*> temp;
std::ifstream s;
std::string str;
s.open("H://account2.dat");

[Code] ....

The accounts have four different types and I am supposed to skip over ones that have an invalid account type and throw an exception:

account* factory(std::string account_code, std::string first_name,
std::string last_name, char type, double balance) {
try {
if(type == 'A') {
simple_account *a = new simple_account(account_code, first_name, last_name, balance);

[Code] .....

My problem is they program will not skip over my rejected accounts.. still adds them to the vector but I cant figure out why!

View 8 Replies View Related

C/C++ :: Array With Random Value?

Jan 7, 2015

i want to create an arry with random value. in 50% times the average of this array is upper of 0.5 and in 50% times the average of this array is lower of 0.5 . i want to write this code in C++. but i dont know what the algorithm is.

My code is this.

#include <algorithm>
#include <cstdlib>
#include <iostream>
int main() {
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7,8 ,9};
std::srand(unsigned(std::time(0)));
}

View 1 Replies View Related

C++ :: Filling Vector From A File - Adding Empty Element At The End

Apr 20, 2014

I'm having a problem filling a vector from a file. Basically, it is adding an empty element at the end. I'm new to Qt and haven't worked with file streams much so how to stop the stream before it adds the extra element.

void gui::get_data() {
mileage.clear();
QFile file(file_label->text() + ".txt");
QTextStream in(& file);
float m;
float g;
QString d;

[Code] ....

But, if I add another element to the vector and write that the file look like this.

//file after adding element
132654 0 02132014
132654 0 02132014
0 0
132998 22 02202014

I have it set to append at the moment so that is why the first line is repeated. I figure the problem is with if(in.atEnd()). I could fix it by deleting the last element right after adding it, but that seems like more of a hack than anything else.

View 3 Replies View Related







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