How to initialize a dynamic two-dimensional array with values? (C++)
Here's my problem...
# include
using namespace std;
int main()
{
// Q#5 - dynamic 2d arrays, indexing via subscript
operator, pointer arithmetic
// tic tac toe board is an array of int
pointers
// each int pointer in the board points to a row
// declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int)
const int SIZE = 3;
int** p_p_tictactoe = new int* [SIZE];
// ... // [5.1] row1: dynamically allocate int[SIZE],
use initializer list to initialize to {1,0,0}
// ... // [5.2] row2: dynamically allocate int[SIZE],
use initializer list to initialize to {0,1,0}
// ... // [5.3] row3: dynamically allocate int[SIZE],
use initializer list to initialize to {0,0,1}
cout << endl << endl;
system("pause");
return 0;
}
# include<iostream>
using namespace std;
int main()
{
// Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic
// tic tac toe board is an array of int pointers
// each int pointer in the board points to a row
// declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int)
const int SIZE = 3;
int** p_p_tictactoe = new int* [SIZE];//here rows are initialized
// ... // [5.1] row1: dynamically allocate int[SIZE], use initializer list to initialize to {1,0,0}
p_p_tictactoe[0]=new int[SIZE]{1,0,0};//here first row created and initialized with values
// ... // [5.2] row2: dynamically allocate int[SIZE], use initializer list to initialize to {0,1,0}
p_p_tictactoe[1]=new int[SIZE]{0,1,0};//here second row created and initialized with values
// ... // [5.3] row3: dynamically allocate int[SIZE], use initializer list to initialize to {0,0,1}
p_p_tictactoe[2]=new int[SIZE]{0,0,1};//here third row created and initialized with values
cout << endl << endl;
system("pause");
return 0;
}
what i lines bolded was entered by me
i completed the remaining rows and initialized the rows.
if you have any doubt please do comment
How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using...
using the code above my instructor just want me to
delete name from a list of students name. the function needs to be
called delete_name. It's in c++. please no changing the code above
just adding. this is pointer and dynamic array.
// This is chapter 9 Pointers and Dynamic array #include< iostream> #include<string> using namespace std; //Gv //function declaration string* add_name(string*,int&); void display_names (string*,int); //main int main() //local var int size-3; string *students_names-new string[size]; //code cout<<"Enter "<<size< students names:"<<endl;...
C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...
C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement the Inner and Outer classes (Circular Buffer of circular buffers using Queues). No need of any classes from the Standard Template Library (STL), not even vector. Add the member functions of those classes by following the codes of InnerCB.h and CBofCB.h below: // file: InnerCB.h // Header file for Inner Circular Buffer. // See project description for details. // #ifndef _INNERCB_H_ #define _INNERCB_H_ class...
The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() { char board[SIZE]; int player, choice, win, count; char mark; count = 0; // number of boxes marked till now initBoard(board); // start the game player = 1; // default player mark = 'X'; // default mark do { displayBoard(board); cout << "Player " << player << "(" << mark...
Write a C++ console program that defines a class named Course that utilizes a dynamically allocated array. Do not use the vector class for this assignment. The Course class should define private data members for the name of the course, the number of students in the course, an array of student names (string*), and the capacity of the course (the array may not be full of students). Use pointer notation when dealing with the array. A 2-arg constructor should initialize...
Purpose This assignment is an exercise in implementing the Stack ADT using a dynamically-allocated array, as well as techniques for managing dynamically-allocated storage in C++. Assignment In this assignment, you will write a class called Stack that will encapsulate a dynamically-allocated array of elements of a generic data type. A driver program is provided for this assignment to test your implementation. You don't have to write the tests. Program You will need to write a single template class for this...
How to solve this Problem in C++
. The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...
Make a program that will calculate and compute for the quotient of miles and gallons (mpg: miles per gallons). Your program should must ask the user to specify the size of the array (using dynamic array) for the following variable: miles ,gallons and mpg. Prompt the user to Initialize the value of miles (value for miles should be 100-250) and gallons (values should be from 5-25). Use pointer galPtr for gallons, milPtr for miles and mpgPtr for mpg. Use function...
Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...