C/C++ :: Create User Defined Dynamic Array For Player Scores - Missing Pointer Types Error

Jan 18, 2015

I'm completely new to pointers and have a homework assignment due where I'm supposed to create a user defined dynamic array for player scores. The only errors I'm experiencing is a C2109: subscript requires pointer type and only on the lines that use the int *score; variable (57, 62, 64, 69, 71, and 82). I've already tried adding = nullptr to the variable and that didn't work.

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void players(string[], int[], int);
void average(int[], int);

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ :: Create Dynamic Pointer Based Array Of Class

Nov 29, 2014

I have a class called Book and I am trying to create a dynamic pointer based array of the class. When I try to run the program I keep getting the error: pointer being freed was not allocated at the line of code that says "delete [] A;". I am using Xcode to run the program.

Book *changeArraySize(Book *A, int &size, double factor) {
int i;
int newsize = size*factor;
Book *A2 = new Book[newsize];

[Code] ....

View 7 Replies View Related

Visual C++ :: Unit-testing Functions With User-defined Types?

May 4, 2013

How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?

For example

CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);

View 9 Replies View Related

C++ :: Dynamic Array Allocation For Test Scores

Nov 30, 2014

I was doing a side programming challenge in my workbook that asked me to dynamically allocate and array for test scores. So far I have an array that will accept an integer to allocate the amount of test scores and then will accept integers to populate the array, however when I try to cout the contents of the array the numbers are absurdly different than what was put in. Here's my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
void main() {
cout << "How many test scores?" << endl;
int scores(0);

[Code] ....

And this is the output screen:
How many test scores?
4
Enter test score 1:
22
Enter test score 2:
33
Enter test score 3:
44
Enter test score 4:
55
-33686019
18472
55656634
201345063
Press any key to continue . . .

Why am I getting these crazy numbers? I've looked back and forth from examples in my book and it doesn't look like I'm doing anything wrong.

View 5 Replies View Related

C :: 2D Array Error - Missing Subscript

Nov 22, 2013

My program has two errors, they are intellisense:An array may not have elements of this type. and missing subscript

Code:
#define ROWS 20
#define COLLUMS 40
void MirrorArrays(char readarray[ROWS][COLLUMS], char *writearray[ROWS][COLLUMS]) {
int i,i2;
for( i = 0; i <= ROWS; i++)

[Code] .....It has both of these errors for both of my arrays.

View 3 Replies View Related

C++ :: Create User Defined Class And Have Access In Separate Header File From Main

Mar 15, 2013

I am a beginner with C++, taking a class right now. The lab this week is to create a user defined class and have it accesses in a separate .h header file from the main.

I think I'm finding my way through it, but I'm getting a complie error that makes no sense to me:

1> Resistor.cpp
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2
esistor.h(11): error C2146: syntax error : missing ';' before identifier 'resistor'
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2

[Code] .....

Here is the first portion of the .h file:

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>

class CResistor{
double res1, res2, res3, percentage, Nominal, Tolerance;

[Code] ....

View 16 Replies View Related

C :: Create Function To Create A Dynamic Array That Fill With Randomly Generated Integers From 0 To 50

Oct 26, 2013

I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.

Code:

* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}

[code]....

View 7 Replies View Related

C :: User Defined Array Size

Jul 23, 2014

The instructions call for the user to define the size of the array and all I have ever done is use a predefined size for the array and then let the user fill it. Here is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Display (void);
void random (int *, int);
void Ascending (int *, int);
void Descending (int *, int);

[code]....

View 7 Replies View Related

C++ :: Array 2D - Class Template Has Already Been Defined Error

Apr 6, 2014

I got an array class, but I'm getting this error:

Error1error C2953: 'Array2D' : class template has already been defined

Here's the code:

#include "Tools.h"
template <typename T>
class Array2D {
T** arr;
int xSize;
int ySize;

[Code] .....

View 3 Replies View Related

C++ :: How To Assign Char Array As User Defined String Object

Apr 17, 2014

STRING s1 = “FOOBAR”

Here STRING is a user defined class. how to assign a constant char array "FOOBAR" to string object? Copy constructor need to be same class type as parameter. and overloading assignment operator also need to be same class type. I think 'friend' can let pass another type of object rather than STRING to do operation on overloaded '=' operator. How could it be done if it is possible at all?

View 2 Replies View Related

C++ :: How To Add A Loop / User-defined Function And Array / Structure To Code

Apr 24, 2012

We had to write a "selling program for computers, laptops and tablets", which I did but for the extra credit, we have to have those three points in the application and I have tried but how to do the "extra credit" part, which I really need.

1.) A loop to prompt the user if they would like to place another order

2.) At least one user-defined function

3.) An enumerated data type, array or struct (structure)

I did one of these three, it's a "DO WHILE" loop asking users if they want to make another order, it's right at the beginning of the code.

Code:

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
double desktop();//function prototype
double laptop();
double tablet();

[Code] ....

View 2 Replies View Related

C :: Linear Search Script - Calling Array Inside Of User Defined Function?

Jul 24, 2013

im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.

I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.

I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.

My first user defined function is simple enough

Code:
ReadArray(int A[], int size){
int i;
printf("Please enter %d integer numbers separated by spaces:
", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}

Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.

I am confused as to my next function:

Code:
void SearchArray(int A[], int target, int size);

I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?

If i call *A do i then use something like this for my search:

Code:
for (*A = 0; *A < size; *A++)
if (*A < target) or use A[] insteadA?

Code:
for (i = 0; i < size; i++)
if (A[i] = target)

View 6 Replies View Related

C :: Convert Characters From Array Into ASCII Integers - Incompatible Types Error

Nov 22, 2013

The code is supposed to convert characters from an array into their respective ascii integers, and append a 0 if the number is less than 3 digits long. It then supposed to put it all together into one string.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){

char file[] = "This is a test";
char *ptr = file;
int length = strlen(file);
int i, numbers[length];

[Code] .....

View 4 Replies View Related

C :: How To Use Malloc Or Calloc To Create Array In Dynamic Memory

Mar 10, 2014

What is wrong with my function why does it spit out huge numbers? And how do i use malloc or calloc to create an array in dynamic memory, and return a pointer to this array

Code:

#include <stdio.h>#include <stdlib.h>
int fibonacci(int n)
{
int i;
long int fib[40];
fib[0]=0;
fib[1]=1;
for(i=2;i<n;i++){
fib[i] = fib[i-1] + fib[i-2];

[Code]....

View 12 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++ :: Calling Defined Function Pointer From Another Pointer To Class Object?

Aug 19, 2014

I am attempting to implement function pointers and I am having a bit of a problem.

See the code example below; what I want to be able to do is call a function pointer from another pointer.

I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.

class MainObject;
class SecondaryObject;
class SecondaryObject {
public:

[Code]....

View 10 Replies View Related

C :: Create Labyrinth And Player Who Needs To Go Through The Map Collecting Objects

Jan 1, 2015

I actually need to create a labyrinth and a player who needs to go thru the map collecting objects (like bags, water etc...). I planned to do the map with a bidimentional array (5x5) but I dont know how to put different objects on an index.. Ex: array[3][2] will have a Botte of water and an energy bar..

Someone told me to use structs but I dont really understand how this would work... I've tried so many times bit I cant do it...

View 2 Replies View Related

C :: Create Structure That Stores Player Name And Score

Aug 8, 2013

We are told to modify this code following the instructions given within the code. It is a tictactoe program.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Create a structure that stores a player's name (up to 20 characters) and score (# of wins)
// Call the struct Player

void info(void) {
printf("

[Code] ....

I've ended up with the following code, but the part about the name of the datafile is giving errors upon running the program.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Create a structure that stores a player's name (up to 20 characters) and score (# of wins)
// Call the struct Player
typedef struct {

[Code] ....

View 4 Replies View Related

C/C++ :: Missing Terminating Character And Int Main Function Error

Oct 6, 2014

I am suppose to make a program that when the user is asked "Enter a Letter for the day:" if the user enters M or m then the screen will output "The day of the week is Monday" and so on until Sunday. I looked over my code and everything looks right but I still get errors saying Missing terminating character " and int function main error.
 
#include <iostream>  
using namespace std;  
int main() {      
    char day;  
    cout << "Enter a letter for a day of the week: ";

[code]....

View 1 Replies View Related

C++ :: Enforcing That A Function Does Not Modify Dynamic Array Pointed To By Pointer

Aug 21, 2014

In case the question was not very clear. Say I have the following code:

int sum(int * x, size_t N){
int sx;
/* returns sum of elements in x */
return sx;

[Code] ....

I'm curious to know whether there is a way that ensures a function does not modify the memory pointed to by a pointer.

View 9 Replies View Related

C++ :: Error Passing Dynamic Array As Arguments

Dec 9, 2013

I am trying to make quicksort and binary search and I get error when I am passing dynamic array to argument. It also says error during initialization of the dynamic array.

//.h file

#ifndef SortableArray_h
#define SortableArray_h

#include <iostream>
#include <string>

[Code] ....

View 2 Replies View Related

C++ :: Debug Error When Deleting Dynamic Array

Feb 18, 2013

I get this error when I'm attempting to delete an array. I'm new to dynamic arrays, and from what I have learned, arrays must be deleted after use. I plan on using this in a function later on, so deleting the array is a must.

Here's the error message: Debug Error!

HEAP CORRUPTION DETECTED: after Normal block (#154) at 0x007E55A0.
CRT detected that the application wrote to memory after the end of heap buffer.

Here's my code:
int main() {
//Declare variables
char persist = ' ';
int* primes = NULL;
int size2 = 0;

//Declare array
primes = new int[size2];

[Code] ....

View 3 Replies View Related

C++ :: Templates User Inputs Dynamic Array?

Nov 12, 2013

This code is from my text book it shows how to implement code that is embedded I have modified it somewhat but I was wondering how I could get the user to implement the size of the array and enter the integers with the size of array that was implemented.

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

[Code].....

View 1 Replies View Related

C++ :: User To Enter Size Of Dynamic Array

Apr 22, 2013

I'm doing an exercise which involves for the user to enter the size of the dynamic array and then enter the numbers, but then it needs to create another dynamic array with the same numbers expect if the number repeats it only has one of it. I've done the first part of the exercise but I'm having trouble with creating the new array.

View 10 Replies View Related

C++ :: Create Main Function With One Dimension Dynamic Array With Float Data Type

Dec 4, 2013

I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?

View 6 Replies View Related

C/C++ :: Struct Locals With Dynamic Types?

Apr 20, 2014

struct InnerNode {
int key_count;
vector<type> keys[M];
int child_count;
union {

[Code] ....

In c++, is there any way to specify a type for a struct local dynamically? My plan is to implement a B+ Tree, but I want this to work with different data types. Could I do this using a constructor?

View 3 Replies View Related







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