Brianca plans to save $5,000, $1,000, and $42,000 a year over the next three years, respectively. How much would you need to deposit in one lump sum today to have the same amount as Brianca three years from now if you both earn 10.9 percent, compounded annually? $36,115 $35,192 $43,282 $41,635 $35,372
.
Historical philosophical, theoretical, and legal foundations of special and i...
Β
C++ Please write the whole code that is needed for this assignment- wr.docx
1. C++ Please write the whole code that is needed for this assignment, write the completed code
together with the provided one, don't copy anyone else's code, label in what file each code
belongs, and please don't forget to share your code output after finishing writing the code, if
these requirements aren't met, I will nor upvote the answer, everything must be clear and
complete, everything is given below. Thank you.
ListNode.h
#include<memory>
#include <string>
template <class T>
//template <class T>
class ListNode{
public: T data;
public: ListNode * next;
// post: constructs a node with data 0 and null link
public: ListNode();
public: ListNode(T data);
public: ListNode(T idata, ListNode<T> * newNext);
public:std::string toString();
public: ListNode<T> * getNext();
public: void setNext(ListNode<T> * newNext);
public: T getData();
public: void setData(T newData);
};
ListNodecpp.h
#include "ListNode.h"
template <class T>
// post: constructs a node with data 0 and null link
//GIVEN
ListNode<T>:: ListNode() {
//std::cout<<" IN constructor"<<std::endl;
T t ;
next=nullptr;
}
//GIVEN
template <class T>
ListNode<T>:: ListNode(T idata) {
data=idata;
next=nullptr;
}
2. //TODO
template <class T>
ListNode<T>:: ListNode(T idata, ListNode<T>* inext) {
//TODO - assign data and next pointer
}
//GIVEN
template <class T>
std::string ListNode<T>::toString(){
return data.toString();
}
//GIVEN
template <class T>
ListNode<T> * ListNode<T>::getNext(){
return next;
}
//TODO
template <class T>
void ListNode<T>::setNext(ListNode<T> * newNext){
//TODO set the next pointer to incoming value
}
//GIVEN
template <class T>
T ListNode<T>::getData(){
return data;
}
//TODO
template <class T>
void ListNode<T>::setData(T newData){
//TODO set the data to incoming value
}
main.cpp
#include <iostream>
#include "ListNodecpp.h"
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
3. //Also changes the next pointer of the previous node to point to the newly inserted list node. the
next pointer of the newly inserted pointer points to what was the next of the previous node. This
way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter - Why do you think this
is needed ?**********
void insert(ListNode<int> * &front,int value);
//Requires: integer value for adding, address of front
//Effects:creates a new ListNode with value and inserts at the beginning
//Modifies:front, if node is added at the beginning.
void addNode(ListNode<int> * &front,int value);
//Requires: integer value for removing, address of front
//Effects: removes a node, if list is empty or node not found, removes nothing.
//Modifies: If the first node is removed, front is adjusted.
// if removal is at the end or middle, makes sure all nececssary links are updated.
void remove(ListNode<int>* & front, int value);
//Requires: address of front
//Effects: prints data of each node, by traversing the chain starting from the front using next
pointers.
//Modifies: nothing
void printList(ListNode<int> * front);
//GIVEN
int main() {
// Add 3 Nodes to the chain of ListNodes
//note AddNode method appends to the end so this will be out of order
// the order of the nodes is 1,2 , 4
//Create a daisy chain aka Linked List
//
ListNode<int> * front = nullptr;
printList(front);
std::cout<<"**********************n";
addNode(front,1);
printList(front);
std::cout<<"**********************n";
addNode(front,2);
printList(front);
std::cout<<"**********************n";
addNode(front,4);
printList(front);
std::cout<<"**********************n";
4. // the insert method inserts node with value 3 in place
insert(front,3);
printList(front);
std::cout<<"**********************n";
// remove the first, so front needs to point to second
remove(front, 1);
printList(front);
std::cout<<"**********************n";
// insert it back
insert(front,1);
printList(front);
std::cout<<"**********************n";
//remove from the middle
remove(front, 3);
printList(front);
std::cout<<"**********************n";
// remove at the end
remove(front, 4);
printList(front);
std::cout<<"**********************n";
//remove a non existent node
remove(front, 5);
printList(front);
std::cout<<"**********************n";
// remove all nodes one by one leaving only front pointing to null pointer
remove(front, 2);
printList(front);
std::cout<<"**********************n";
remove(front, 1);
printList(front);
std::cout<<"**********************n";
// insert at the beginning of the empty list a larger value
insert(front, 4);
printList(front);
std::cout<<"**********************n";
// insert the smaller value at correct position in the front of the chain and change front
insert(front, 1);
printList(front);
std::cout<<"**********************n";
}
//GIVEN
void printList(ListNode<int> * front){
ListNode<int> * current = front;
5. while (current!=nullptr){
std::cout<<current->getData()<<"n";
current=current->getNext();
}
if (front ==nullptr)
std::cout<<"EMPTY LIST n";
}
//GIVEN
int search(ListNode<int> * front,int value){
ListNode<int> * current = front;
while (current!=nullptr&& current->getData()!=value){
// std::cout<<current->getData()<<"n";
current=current->getNext();
}
if (current!= nullptr) return current->getData();
return value+1 ; // to indicate not found. The calling program checks if return value is the same
as search value to know if its found; I was using *-1 but if search value is 0, then that does not
work;
}
//GIVEN
void addNode(ListNode<int> * & front ,int value){
ListNode<int> * current = front;
ListNode<int> * temp = new ListNode<int>(value);
if (front ==nullptr)
front=temp;
else {
while (current->getNext()!=nullptr){
// std::cout<<current->getData()<<"n";
current=current->getNext();
}
//ListNode<int> * temp = new ListNode<int>(value);
current->setNext(temp);
}
}
//TODO
void remove(ListNode<int> * &front,int value){
//TODO
}
//TODO
void insert(ListNode<int> * &front,int value){
7. **********************
1
4
**********************
This assignment and the next (#5) involve design and development of a sequential non
contiguous and dynamic datastructure called LinkedList. A linked list object is a container
consisting of connected ListNode objects. As before, we are not going to use pre-fabricated
classes from the c++ library, but construct the LinkedList ADT from scratch. The first step is
construction and testing of the ListNode class. A ListNode object contains a data field and a
pointer to the next ListNode object (note the recursive definition). #This assignment requires
you to 1. Read the Assignment 4 Notes 2. Watch the Assignment 4 Support video 3. Implement
the following methods of the ListNode class -custom constructor -setters for next pointer and
data 4. Implement the insert and remove method in the main program 5. Scan the given template
to find the above //TODO and implement the code needed //TODO in ListNodecpp. h file public:
ListNode(T idata, ListNode < T > newNext); public: void setNext(ListNode < T > newNext);
public: void setData(T newData); # The driver is given ListNodeMain.cpp is given to you that
does the following tests 1. Declares a pointer called front to point to a ListNode of datatype
integer 2. Constructs four ListNodes with data 1,2,4 and adds them to form a linkeo list. 3.
Inserts ListNode with data 3 to the list 4. Removes node 1 and adds it back to test removing and
adding the first element 5. Removes node 3 to test removing a middle node 6. Removes node 4 to
test removing the last node 7. Attempt to remove a non existent node 8. Remove all existing
nodes to empty the list 9. Insert node 4 and then node 1 to test if insertions preserve order 10.
Print the list