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?
#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.
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: 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...
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;
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?
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; }
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?
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! ".
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
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)
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.
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.
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.
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.
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();
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" ?
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.
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.
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.