C++ :: Creating Dynamic Arrays / Structures

Feb 7, 2012

We are supposed to create a menu with an option to add a car (make, model etc) to inventory. I have the structure format set up as far as adding the car, but I am stuck on how to make it a dynamic array of structures or whatnot (I'm not really sure on what I'm trying to do in the first place!) Basically, the user can choose to add a car and its info in. How do you set up the array to add whatever number of cars is needed? Will it be able to add more cars should the user come back to the program later?

This is the instruction of this portion of the project :

Menu Application
Add a car to inventory
Prompted to add
Make, Model and Year, Color, Miles, Price
Finish (adds the car to the file)
Cancel takes you to the main menu

View 1 Replies


ADVERTISEMENT

C++ :: Fill Value Of Dynamic Array Of Dynamic Arrays?

Jan 4, 2013

I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.

unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{

[Code].....

View 2 Replies View Related

C++ :: Dynamic Data Structures (Linked List)

Oct 26, 2013

I need an explanation of what linked lists are. How the nodes are been defined and used, especially in an object oriented programming. With a code example.

View 1 Replies View Related

Visual C++ :: Implementing Dynamic Database Structures?

Mar 21, 2013

We're designing a new software and we want it to be customizable without code. That, for us, mean we can change the software behaviour without re-writing code. All will be developed using C and .NET.

One of our goals is to have what we are calling "dynamic tables". This means that these database tables may have different fields depending on the customization. We got to know it using high-level ERPs like SAP or CRM's system like VTIGER or even SalesForce. Let me give an example:

CUSTOMER TABLE:

FIELDS: ID, NAME, ADDRESS, PHONE.

This would be the standard Customer Table.

Now, a new customer needs to add FINANCE SCORE and RANKING to the database. We them would like to go to our application (not the database itself) and adding these new fields. After that, all of my input forms and reports would start to show and process these new fields.

View 4 Replies View Related

C++ :: Dynamic Data Structures And Information Input

Feb 17, 2013

I want to have input data stored in a database. All information entered is to be stored under a single block. That way whenever I want to recover that information all I have to do is point to that block. Think of it like this. I want a large square block that can hold certain information. Inside of that large block are a finite amount of smaller blocks in which the user entered information about a single subject. Lets say block 1 has a name, address, and phone number. The second block will have the same TYPE of information, but different values as entered by the user. I.E:

BLOCK 1: Name 1, Address 1, Phone 1
BLOCK 2: Name 2, Address 2, Phone 2
etc.

The large block contains all of the smaller blocks, we will name the large block "Address Book" ... How would I implement that? Of course it would be just a simple console program that would erase all information when the program shut down, but I've been trying to figure out how to do it, but just can't seem to grasp a good notion of how to do it. What would be the best way to do that? Structures? How would I make it dynamic so that I wouldn't have to define every block, so that it would be added on the fly when someone inputs new information.

View 2 Replies View Related

C++ :: Dynamic Structures - Find Average Value Of All Elements In Deque

Dec 17, 2013

I have a question. How to find the average value of all the elements in a deque?

View 2 Replies View Related

C++ :: Sorting Two Arrays Of Structures?

Mar 26, 2013

I wanted to sort two structure-arrays according to their element values and get their indices changed accordingly.For example if my array is

A[]= { 2 4 1 8 6}
indices[]={ 1 2 3 4 5}

then after sorting it should become

A[]= { 1 2 4 6 8}
indices[]={ 3 1 2 5 4}

I tried implementing it using the following code but I failed to get correct output.

Code:

#include<iostream>
#include<cstdio>
using namespace std;
#define inf 100000
struct array
{
int x;
int y;
};

[code]....

View 4 Replies View Related

C/C++ :: Printing Arrays In Structures?

Mar 1, 2014

# include <conio.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>

[Code]....

I tired changing the conditions in the for loops, but then I end up entering information multiple times and I want that to be the user's option. Do I have to change the for loops or something else? I've tried everything to get what I want but nothing works. When I print the receipt, only the last food Item that I entered prints.

View 14 Replies View Related

C++ :: Project Combining Arrays / Pointers And Structures

May 6, 2014

Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:

Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F

A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.

My code runs but it isnt returning anything (readable/correct) and i have no clue why. This is what i have so far:

#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];

[Code] .....

it compiles completely but at the end instead of showing the student name ID average score and class grade it shows.... [URL] .....

View 2 Replies View Related

C/C++ :: Project Combining Arrays / Pointers And Structures

May 5, 2014

Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:

Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F

A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.

My code runs but it isnt returning anything(readable/correct) and i have no clue why. This is what i have so far:

#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];
int scores[6][4];
double avg[6];
char grade[6];
}; //semi-colon required

[Code] ...

View 8 Replies View Related

C :: Creating Dynamic String?

Mar 6, 2015

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char * form(char *format, ...);
}

[code]...

So, this is the code i have problem with, as far as i can see, function form actually does the same thing that printf does.It probably puts all of the arguments sent to the function together into one string.

View 4 Replies View Related

C++ :: Creating A Pointer To Dynamic Integer Array?

Sep 15, 2013

Create in the private section of the ServerGroup class a pointer to a dynamic integer array called servers.

#ifndef ServerGroup_h
#define ServerGroup_h
class ServerGroup {
public:
private:
int *ptr = new int; // needs pointer to a dynamic integer array called servers
};
#endif

View 2 Replies View Related

C :: Dynamic Arrays And Pointers

Feb 11, 2013

I am having troubles with dynamic arrays and pointers. All the errors are of that kind. I think when I am assigning malloc to an array we assign to its address.

Code:
/*Create an array of genes of the large matrix*/
gene_t gene,gene1,gene2;
gene=malloc(INITIAL*sizeof(gene2)); Code:
while(...) {
if (gene_num==current_size){

[Code] .....

View 9 Replies View Related

C++ :: Dynamic Allocation For Arrays

Oct 1, 2014

Code to allocate the memory for my arrays in the create array function.

#include <iostream>
#include <cstdlib>
using namespace std;
typedef int* IntPtr;
const int NUMLABS = 4;

[Code] ....

View 1 Replies View Related

C++ :: Multiply Two Dynamic Arrays

Mar 28, 2014

By using operator overloads i need to be able to * two dynamic arrays;

this is what i have so far

MyInt operator* (const MyInt& x, const MyInt& y) {
MyInt Temp;
int carry = 0;
if(x.currentSize > y.currentSize){
for( int i =0; i < y.currentSize; i++)
for(int j = 0; j < x.currentSize; j++)

[Code] ....

View 7 Replies View Related

C++ :: Dynamic Arrays Error?

Mar 4, 2014

i was trying to make a dynamic array in this form :

int x;
cin>>x;
int ar[x];

my g++ (gcc) compiler on linux refused to create an array without a fixed size , however using the same code on windows on dev-cpp it was complied and executed , also it allowd me to create and use the dynamic array , i thought it was a compiler bug , however when i restarted and returned to g++ it compiled and executed the code although it never did before i tried the code on windows , how can that be and is it dangerous ?

View 5 Replies View Related

C++ :: Dynamic Containers With Arrays?

Feb 14, 2015

Im trying to create a function that searches my array for a specific string, and then displays that string and the other content associated with it. I'm basically searching for a keyword within an array that has multiple strings with in each element.

View 4 Replies View Related

C++ :: Dynamic Memory Allocation (arrays)

Feb 24, 2014

I have recently bought a copy of "Jumping into C++" and have come to chapter 14 ( dynamic memory location) and have a question.

On page 153-154 an example of dynamic allocation is given for array's of int. How would the code look like for strings or structs ?

The allocation was given by:

Code:
int *growArray (int* p_values, int *size)
{
*size *= 2;
int *p_new_values = new int[ *size ];
for ( int i = 0; i < *size; ++i )
{
p_new_values[ i ] = p_values[ i ];
}
delete [] p_values;
return p_new_values;
}

Sample Code I tried to use this for an array of structs but failed completely....

I used the following struct Code:

struct user{
int days;
string name;
};

and the allocation function (which does not work):

Code:
struct user *growarray (struct user *p_values, int *size) {
*size *= 2;
struct user *p_new_values = new struct user[ *size ];
for ( int i = 0; i < *size; ++i )

[Code].....

View 8 Replies View Related

C++ :: How To Initialise Dynamic Arrays Of Objects

Oct 22, 2014

Say I have a class called Play now I have a constructor called Play(int, char, int); I create Play play=new Play[2]()//default const Now i want to initialise different values of play objects using play(int char int) Whats the syntax? play[i](vale, value value); ? Its not working..

View 5 Replies View Related

C++ :: Freeing Dynamic Arrays From Memory

Sep 27, 2013

So I'm trying to wrap my head around dynamic arrays, and I've finally figured out how to build one, using

int arraysize = randomnumber;
int* arrayname = new int[arraysize];

Now, how to delete the array. Can I free the whole array from any scope in my program using a simple line like delete arrayname;?

Also, since I'm working in heap, I can't rely on the debugger to show me when I'm doing something wrong, If I create a struct such as :

struct twoints {int one, int two};

and then try to create a dynamic array of said struct using

int arraysize = 5;
twoints* arrayname = new twoints[arraysize];

Am I basically creating an array of 5 two ints?

//is it the same as doing this?

twoints arrayname[5];

View 8 Replies View Related

C++ :: Class With Pointers And Dynamic Arrays

Apr 25, 2014

Class with Pointers and Dynamic Arrays

View 2 Replies View Related

C++ :: Big Integer Class Using Dynamic Arrays

Mar 27, 2014

I have become overwhelmed an frustrated at these current operator overloads!

Currently I still can not get my +,* or istream operators working at all!

#include <iostream>
#include <cstring>
#include "myint.h"

[Code]....

View 1 Replies View Related

C++ :: Proper Declaration Of Dynamic Arrays

Dec 10, 2013

I started to practice some C++. I use to program in C and a little C++. Anyway, I am writing code that creates a dynamic array. I would like to be able to do something like

galaxyobject[object] -> uniqueid = in the class but I do not think I have it setup right.

Question.
1. Is the code correct?
2. Why can't I use the above line without a compile error or segment fault?

int main() {
cout << "ProteusCore Server" << endl;

// create a galaxy system with a certain amount of objects
galaxy galaxysystem;
galaxysystem.IntializeGalaxy(100);

[Code] ....

I made the code available to see on sourceforge as Proteus 3d Game Engine. It is something I would like to work on.

View 3 Replies View Related

C++ :: Pointer To Point Dynamic Arrays?

Jan 31, 2013

Do I really need to create a separate pointer to point to dynamic arrays?

T* temp = new T[capacity_ * 2];
T* tIter = &temp; //Do these need to be here?
T* dIter = &data; //Or can I use *(temp + i) and *(data + i)?
(for unsigned int i = 0; i < size_; i++) {
*(tIter + i) = *(dIter + i);
}

View 7 Replies View Related

C++ :: Passing Dynamic Multi-Dimensional Arrays

Jan 29, 2015

I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.

#include <iostream>
#include <stdio.h>
using namespace std;

[Code].....

View 1 Replies View Related

C/C++ :: 2D Dynamic Arrays - How To Create And Give Values

Apr 23, 2014

I cant get with part of it is wrong, i want to sum every row, too.

// Color Number.cpp : Defines the entry point for the console application.
//  
#include "stdafx.h"
#include<conio.h>
#include<iostream>

[Code].....

View 1 Replies View Related







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