Question

In: Computer Science

C++ Code! This code was written/implemented using the "class format." How would I go about in...

C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?"

#include <iostream>

#include <iomanip>

using namespace std;

class ListNode{

public:

string course_name;

string course_number;

string course_room;

ListNode* next;

ListNode(){

this->next = NULL;

}

ListNode(string name, string number, string room){

this->course_name = name;

this->course_number = number;

this->course_room = room;

this->next = NULL;

}

};

class List{

public:

ListNode* head;

List(){

this->head = NULL;

}

void insert(ListNode* Node){

if(head==NULL){

head = Node;

  

}

  

else{

ListNode* temp = head;

while(temp->next!=NULL){

temp = temp->next;

}

temp->next = Node;

}

}

void print(){

ListNode* temp = head;

while(temp!=NULL){

cout << left << setw(20) << temp->course_name

<< setw(10) << temp->course_number

<< setw(10) << temp->course_room << "\n";

temp = temp->next;

}

}

};

int main() {

List l;

ListNode* n1 = new ListNode("Calculus 1","Math 1","SCMA 221");

ListNode* n2 = new ListNode("C++ Programming","CSP 31B","SCMA 150");

ListNode* n3 = new ListNode("Discrete Math","CS 55","SCMA 127");

ListNode* n4 = new ListNode("Java Programming","CS 26A","SCMA 352");

l.insert(n1);

l.insert(n2);

l.insert(n3);

l.insert(n4);

cout << "Courses for Tim Apple:\n";

l.print();

  

return 0;

  

}

Solutions

Expert Solution

structures:

structure is a collection of heterogeneous type of data means different data types under a single name.

and stucture is similar to class , both holds a collection of different data types.

syntax: struct structure_name

{

type variable_name;

type variable_name;

................  

} structure_variable;

#include <iostream>

#include <iomanip>

using namespace std;

struct ListNode {

string course_name;

string course_number;

string course_room;

ListNode* next;

ListNode(){

this->next = NULL;

}

ListNode(string name, string number, string room) {

this->course_name = name;

this->course_number = number;

this->course_room = room;

this->next = NULL;

} };

struct List {

ListNode* head;

List() {

this->head = NULL;

}

void insert(ListNode* Node) {

if(head==NULL) {

head = Node;

  }

  else {

ListNode* temp = head;

while(temp->next!=NULL) {

temp = temp->next;

}

temp->next = Node;

}

}

void print() {

ListNode* temp = head;

while(temp!=NULL){

cout << left << setw(20) << temp->course_name

<< setw(10) << temp->course_number

<< setw(10) << temp->course_room << "\n";

temp = temp->next;

}

}

};

int main() {

List l;

ListNode* n1 = new ListNode("Calculus 1","Math 1","SCMA 221");

ListNode* n2 = new ListNode("C++ Programming","CSP 31B","SCMA 150");

ListNode* n3 = new ListNode("Discrete Math","CS 55","SCMA 127");

ListNode* n4 = new ListNode("Java Programming","CS 26A","SCMA 352");

l.insert(n1);

l.insert(n2);

l.insert(n3);

l.insert(n4);

cout << "Courses for Tim Apple:\n";

l.print();

  return 0;

  }


Related Solutions

How would I go about making a simple code for an analog clock using matlab?
How would I go about making a simple code for an analog clock using matlab?
How would I structure the following PHP (PDO) code into a table format using only PHP?...
How would I structure the following PHP (PDO) code into a table format using only PHP? //Our SQL statement, which will select a list of tables from the current MySQL database. $sql = "SELECT * FROM jobs"; //Prepare our SQL statement, $statement = $pdo->prepare($sql); //Execute the statement. $statement->execute(); //Fetch the rows from our statement. $tables = $statement->fetchAll(PDO::FETCH_NUM); //Loop through our table names. foreach($tables as $table){ //Print the table name out onto the page. echo $table[0], ' '; echo $table[1], '...
How would I go about debugging this to make it work properly? import java.util.Scanner; public class...
How would I go about debugging this to make it work properly? import java.util.Scanner; public class TemperatureConverter{ public static void main(String[] args) { // Declare named constants. final double MIN_FAHRENHEIT = -459.67; // Declare the variables. double fahrenheit; double convertedDegrees; int tempScale; String tempScaleStr=""; // Creating the Scanner object Scanner keyboard = new Scanner(System.in); System.out.print("Enter the temperature in Fahrenheit: "); fahrenheit = keyboard.nextDouble(); // Set a breakpoint here // Verify the user's input if (fahrenheit > MIN_FAHRENHEIT) { // first...
How would I get this java code to work and with a main class that would...
How would I get this java code to work and with a main class that would demo the rat class? class rat { private String name; private String specialAbility; private int TotalHealth; private int shieldedHealth; private int cooldown; public rat() { } public rat(String n,String SA,int TH,int SH,int cd) { name=n; specialAbility=SA; TotalHealth=TH; shieldedHealth=SH; cooldown=cd; } public void setname(String n) { name=n; } public String getname() { return name; } public void setability(String SA) { specialAbility=SA; } public String getability()...
How would I go about this question using R studio? In a multiple regression, investigate whether...
How would I go about this question using R studio? In a multiple regression, investigate whether the categorical variable "Type" has a statistically significant interaction effect with any of the other covariates, A, B, C and D. Of those interactions that are statistically significant (if any), determine which one has the most impact on the model and add it to your model. Please include general 'formulas' for the commands needed!
I want this code to be written in c++. Take a string of length n as...
I want this code to be written in c++. Take a string of length n as an input from the user such that n>=8 and only lower-case letters (a-z) are allowed as valid string characters. Deleting a letter from the string removes all the occurrences of that letter. The objective is to find the longest possible string such that it is left with only two unique letters and no two consecutive characters in a string are the same. If there...
using visual basic how would i go about coding: if checkbox 1 is checked add 10...
using visual basic how would i go about coding: if checkbox 1 is checked add 10 to subtotal if checkbox 2 is checked add 50 to subtotal if checkbox 3 is checked add 100 to subtotal subtotal label is 'lblSubtotal' all 3 boxes are independent. example if checkboxes 1 and 3 are checked 110 would be added to subtotal.
How would i go about answering this? Select the range the PH will fall into for...
How would i go about answering this? Select the range the PH will fall into for each .1M solution. a. MnCl3 <1 1 between 1&7 7 between 7&13 13 >13 b. CH3CO2H <1 1 between 1&7 7 between 7&13 13 >13 c. KOH <1 1 between 1&7 7 between 7&13 13 >13 d. NaF <1 1 between 1&7 7 between 7&13 13 >13
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent...
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of...
How do you translate this pseudocode go regular code in C++ int iMin = 0,i =...
How do you translate this pseudocode go regular code in C++ int iMin = 0,i = 0; for(j = 0; j < n - 1; j++) int iMin = j; for(i = j + 1; i < n; i++) if(a[i] < a[iMin]) iMin = i; if(iMin != j) swap(a[i], a[iMin]);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT