Question

In: Computer Science

DEVELOP IN VISUAL STUDIOS C++ PLEASE 1. Develop a main program that does the following a)...

DEVELOP IN VISUAL STUDIOS C++ PLEASE

1. Develop a main program that does the following

a) Create six nodes of integers such as n0, n1, n2, n3, n4, n5 (n0 is the head)

b) Assign data to each nodes such as n1->data = 2; n2->data = 5, n3->data = 3, n4->data = 10, n5->data = 1.

c) Make n0 ->next to point to n1, and n0->prev to point to NULL 2.) Print out the content of list you have created 3.) Create another Node called n6 with n6->data = 9. Add this new node after n3 (between node 3 and 4). 4.) Print the content of the list that you created.

d) link nodes to each other (see figure 1) (n5->next must point to NULL)

2. Print out the content of list you have created

3. Create another Node called n6 with n6->data = 9. Add this new node after n3 (between node 3 and

4). After you added n6 your list should look like figure 2

NODE.H

#pragma once
#ifndef _NODE_H
#define _NODE_H
#include<iostream>
using namespace std;
template<class T>
class Node
{
private:
        T data;
        Node<T>* next;
        Node<T>* prev;
public:
        Node();
        Node(T anItem);
        void setItem(T anItem);
        void setNext(Node<T>* nextNode);
        void setPrev(Node<T>* prevNode);
        T getItem();
        Node<T>* getNext();
        Node<T>* getPrev();
};

#endif // !_NODE_H

NODE.CPP

#include "Node.h"
template<class T>
Node<T>::Node() {
        next = NULL;
        prev = NULL;
}

template<class T>
Node<T>::Node(T anItem) {
        data = anItem;
        next = NULL;
        prev = NULL;
}
template<class T>
void Node<T>::setItem(T anItem) {
        data = anItem;
}

template<class T>
void Node<T>::setNext(Node<T>* nextNode) {
        next = nextNode;
}

template<class T>
void Node<T>::setPrev(Node<T>* prevNode) {
        prev = prevNode;
}

template<class T>
T Node<T>::getItem() {
        return data;
}

template<class T>
Node<T>* Node<T>::getNext() {
        return next;
}

template<class T>
Node<T>* Node<T>::getPrev() {
        return prev;
}

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

//main.cpp

#include<iostream>
#include "Node.h"

using namespace std;

int main(){
        //creating 6 nodes
        Node<int> *n0=new Node<int>();
        Node<int> *n1=new Node<int>();
        Node<int> *n2=new Node<int>();
        Node<int> *n3=new Node<int>();
        Node<int> *n4=new Node<int>();
        Node<int> *n5=new Node<int>();
        
        //adding data to each node except n0 (n0 is the dummy head node)
        n1->setItem(2);
        n2->setItem(5);
        n3->setItem(3);
        n4->setItem(10);
        n5->setItem(1);
        
        //linking nodes in the order: n0 -> n1 -> n2 -> n3 -> n4 -> n5 -> NULL
        n0->setPrev(NULL);
        n0->setNext(n1);
        n1->setPrev(n0);
        n1->setNext(n2);
        n2->setPrev(n1);
        n2->setNext(n3);
        n3->setPrev(n2);
        n3->setNext(n4);
        n4->setPrev(n3);
        n4->setNext(n5);
        n5->setPrev(n4);
        n5->setNext(NULL);
        
        //looping and printing the current list
        cout<<"list: ";
        for(Node<int> *n=n0->getNext();n!=NULL;n=n->getNext()){
                cout<<n->getItem()<<" ";
        }
        cout<<endl;
        
        //creating a new node with data=9
        Node<int> *n6=new Node<int>(9);
        
        //adding the new node between n3 and n4
        n6->setNext(n4);
        n4->setPrev(n6);
        n3->setNext(n6);
        n6->setPrev(n3);
        
        //printing updated list
        cout<<"updated list: ";
        for(Node<int> *n=n0->getNext();n!=NULL;n=n->getNext()){
                cout<<n->getItem()<<" ";
        }
        cout<<endl;
        
        //deleting nodes from memory to prevent memory leaks.
        delete n0, n1, n2, n3, n4, n5, n6;
        return 0;
}

/*OUTPUT*/

list: 2 5 3 10 1
updated list: 2 5 3 9 10 1

Related Solutions

Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
Use C++ please Implement the following exercise on Visual Studios and submit the necessary (.h and...
Use C++ please Implement the following exercise on Visual Studios and submit the necessary (.h and .cpp) files in a .zip folder 1.   Create a class NumberType such that it has the following functionality: The draw function in NumberType only prints 'this is an empty function' message. Create a class NumberOne (derived from NumberType) which in the draw function prints the number using a 5(rows)x3(columns) matrix. See example at https://www.istockphoto.com/vector/led-numbers-gm805084182-130563203 * * * * * Similarly create a class NumberTwo...
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and...
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and printout the first 6 Fibonacci numbers.   Fibonacci sequence is described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). (sequence 0 1 1 2 3 5 8 13 21 34 ...) Have your program print out "The first six numbers in the Fibonacci Sequence are". Then the numbers should be neatly printed out, with...
Must be written in C++ in Visual studios community In this lab, you will modify the...
Must be written in C++ in Visual studios community In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program...
Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program accepts inputs from the user from the console. The user can provide the following two types of input: add num1 num2 mult num1 num2 Here, num1 and num2 are two integer numbers. E.g., the user may input add 1 2. The threads receive the command along with the number, and performs the appropriate arithmetic operation and returns the results to main program. The main...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that serves as a healthcare billing management system. This application is a multiform project (Chapter 9) with three buttons. The "All Accounts" button allows the user to see all the account information for each patient which is stored in an array of class type objects (Chapter 9, section 9.4).The "Charge Service" button calls the Debit method which charges the selected service to the patient's account...
Code should be written in C++ using Visual Studios Community This requires several classes to interact...
Code should be written in C++ using Visual Studios Community This requires several classes to interact with each other. Two class aggregations are formed. The program will simulate a police officer giving out tickets for parked cars whose meters have expired. You must include both a header file and an implementation file for each class. Car class (include Car.h and Car.cpp) Contains the information about a car. Contains data members for the following String make String model String color String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT