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

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...
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...
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...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name and phone (vendor_name and vendor_phone) in the state "CA" and the city "Los Angeles". here is the database tables CREATE TABLE general_ledger_accounts ( account_number INT PRIMARY KEY, account_description VARCHAR(50) UNIQUE ); CREATE TABLE terms ( terms_id INT PRIMARY KEY AUTO_INCREMENT, terms_description VARCHAR(50) NOT NULL, terms_due_days INT NOT NULL ); CREATE TABLE vendors ( vendor_id INT PRIMARY KEY AUTO_INCREMENT, vendor_name VARCHAR(50) NOT NULL UNIQUE, vendor_address1...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT