this is in my .cpp
void Sequence::push_back(const value_type& value)
{
}
this is in my .h under public
typedef int value_type;
void push_back(const value_type& v);
this is the code i have to produce in my .cpp
try {
cout << "Testing push_back()"
<< endl;
cout << "-------------------"
<< endl;
Sequence data(3);
data[0] = 100;
data[1] = 200;
data[2] = 300;
data.push_back(400);
data.push_back(500);
cout << "Sequence: " <<
data << endl;
cout << "Should be: <100,
200, 300, 400, 500>" << endl << endl;
}
catch (exception& e)
{
cout << "Exception: "
<< e.what() << endl << endl;
}
im trying to figure out what do i write in the void Sequence::push_back to produce this output.
class Sequence { private: int count; int capacity; int *data; public: typedef int value_type; Sequence(int); void push_back(const value_type& v); }; Sequence::Sequence(int c) { capacity = c; data = new value_type[c]; count = 0; } void Sequence::push_back(const value_type& v) { if(count < capacity) { data[count++] = v; } }
It shoudl be like above.
this is in my .cpp void Sequence::push_back(const value_type& value) { } this is in my .h...
C++ programming language: In this program you will create a simplified bag that acts like a stack meaning that the Last item inserted is the First Item that comes out. Your backend implementation must use a linked list. The code should pass the test (there's only 1) and there should be no memory leaks. Note that passing the test does not ensure full credit! The functions are listed in the suggested order of implementation but you may implement them in...
c++ Sequence class is a class that supports sequence of integers. Run the project ad verify that project works for integers. Next convert your sequence class into a template class. Demonstrate in your main function by using a sequence of int, float, string. sequence.cxx #include // Provides assert using namespace std; namespace main_savitch_3 { sequence::sequence() { used = 0; current_index = 0; } void sequence::start() { current_index = 0; } void sequence::advance() // Library facilities used: assert.h { assert(is_item()); current_index++;...
PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...
Please zoom in so the pictures become high resolution. I need
three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The
programming language is C++. I will provide the Sample Test Driver
Code as well as the codes given so far in text below.
Sample Testing Driver Code:
cs52::FlashDrive empty;
cs52::FlashDrive drive1(10, 0, false);
cs52::FlashDrive drive2(20, 0, false);
drive1.plugIn();
drive1.formatDrive();
drive1.writeData(5);
drive1.pullOut();
drive2.plugIn();
drive2.formatDrive();
drive2.writeData(2);
drive2.pullOut();
cs52::FlashDrive combined = drive1 + drive2;
// std::cout << "this drive's filled to " << combined.getUsed( )...
Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list). /* definition of the list node class */ class Node { friend class LinkedList; private: int value; Node *pNext; public: /* Constructors with No Arguments...
Hello, im looking for help on adding overload operators to my code. It needs to consist of + (addition) for the Fraction class * (multiplication), no need not reduce == (equality operator) = (assignment operator) << and >> so in main you can use << and >> as follows: cin>>frac1; cout<< frac1; where frac1 is a an object of the Fraction class the original code is: #include <iostream> using namespace std; class Fractions { private: int numerator; int denominator;...
A library maintains a collection of books. Books can be added to
and deleted from and checked out and checked in to this
collection.
Title and author name identify a book. Each book object
maintains a count of the number of copies available and the number
of copies checked out. The number of copies must always be greater
than or equal to zero. If the number of copies for a book goes to
zero, it must be deleted from the...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...
there show an error in sample.cpp file that more than one instance of overloaded function find matches the argument list. can you please fix it. and rewrite the program and debug. thanks. I also wrote error below on which line in sample.cpp. it shows on find. #include #include #include "node1.cpp" using namespace main_savitch_5; // node1.h #ifndef MAIN_SAVITCH_NODE1_H #define MAIN_SAVITCH_NODE1_H #include <string> namespace main_savitch_5 { template<class item> class node { public: typedef item value_type; ...
This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private: char *name; int salary; public: PermanentWorker(const char* nam, int money) : salary(money) { name = new char[strlen(nam) + 1]; strcpy(name, nam); } int getPay() const { return salary; ...