#pragma once
#include<iostream>
#include<vector>
using namespace std;
template <typename T>
class ArrayBag
{
private:
vector<T>Array;
int Size;
public:
ArrayBag() = default;
ArrayBag(int Size)
{
this->Size = Size;
Array.resize(Size);
}
void RemoveRandomEntry()
{
if (Size > 0)
{
T index =
(rand() % Size);
if (index >=
0 && index < Array.size() - 1)
Array.erase(Array.begin() + index);
}
}
~ArrayBag() = default;
};
//ArrayBag<int> Bag(4); // how to
instantiate in main
//Bag.RemoveRandomEntry(); // calling to check
// tested by calling RemoveRandomEntry(); 10 times in a single run!
COMMENT DOWN FOR ANY QUERIES,
AND LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.
This homework involves ADDING MEMBER FUNCTIONS to ArrayBag.h. This homework is important because ...
Add a member function template called RemoveRandom to the ArrayBag class (so add it to ArrayBag.h). The RemoveRandom member function should remove a random entry from the list (so use your srand and rand functions). Do not forget to TEST... that means you will need to add the prototype and test with a simple main. All you need to submit though is the member function implementation Add an overloaded constructor to the ArrayBag class (so add it to 2. ArrayBag.h)....
========================Data Structure C++============================ 1. Write a CLIENT program that creates a stacks fo type int (so one stack instance): aStack. Ask the user for 5 ints and push them onto aStack. Find a way to print the values in aStack in from the bottom to the top (so display the top LAST) - so if aStack was 1,2,3,4,5 with 5 at the top and 1 at the bottom you want it to display 1,2,3,4,5 (you don't want it to display 5,4,3,2,1...
you will write a templated array class. Called MyArray with member variables ptr and array_size. This array must use dynamic memory--see program shell, names should remain unchanged. The following is a list of required member functions of the array class along with a rubric: (1pts) program compiles (2pts) default constructor (2pts) parametered constructor which feeds MyArray a size. (10pts) copy constructor 8pts for performing a *deep* copy 2pts for correct syntax (10pts) overloaded = operator 7pts for functioning properly 3pts...
This program has an array of floating point numbers as a private data member of a class. The data file contains floating point temperatures which are read by a member function of the class and stored in the array. Exercise 1: Why does the member function printList have a const after its name but getList does not? Exercise 2: Fill in the code so that the program reads in the data values from the temperature file and prints them to...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
Complete this program, by adding a function called mag( ) to calculate the magnitude of a vector. You'll need to add a prototype before main( ), and the implementation (header & body) of the function after main( ); reminder: mag = sqrt (x 2 + y 2) Calling it with something like: vec_length = mag(x, y); Name your program functions1.cpp
Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE... MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...
I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...
(C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...
Your goal is to create an ‘Array’ class that is able to hold
multiple integer values. The ‘Array’ class will be given
functionality through the use of various overloaded operators
You will be given the main() function for your program and must add
code in order to achieve the desired result. Do not change any code
in main(). If something is not working, you must change your own
code, not the code in main().
Assignment 5: overloading member functions. Overview:...