Questions
*In C++ Please! This problem uses the concept of linked list What is a C++ structure?...

*In C++ Please! This problem uses the concept of linked list

  1. What is a C++ structure? Store product-id, product-name, and price per unit in a C++ structure. Use a C++ class with a member variable of that structure and provide read and write member functions for the product details.

  2. Suppose the product names are stored in alphabetical order, Write the C++ insert function to insert a new product ‘tooth brush’ in that linked list.

  3. Suppose the product names are stored in alphabetical order, Write the C++ delete function to remove product ‘tooth brush’ in that linked list.

  4. Suppose the product names are stored in alphabetical order, Write the C++ count function to display the number of products in that linked list

In: Computer Science

In racket Assume that the elements of a list are indexed starting with 1. Write a...

In racket

Assume that the elements of a list are indexed starting with 1. Write a function alts that takes a list of integers xs and returns a pair of lists, the first of which has all the odd-indexed elements (in the same relative order as in xs) and the second of which has all the even-indexed elements (in the same relative order as in xs).

Output should be

(alts (list 7 5 4 6 9 2 8 3)) '((7 4 9 8)5 6 2 3)

(alts (list 5 4 6 9 2 8 3)) '((5 6 2 3) 4 9 8)

Any help would be appreciated, we're not allowed to use cond

In: Computer Science

PLEASE COMPLETE BOTH PARTS (LANGUAGE: C++ if necessary) Part I For the following example, determine the...

PLEASE COMPLETE BOTH PARTS (LANGUAGE: C++ if necessary)

Part I

For the following example, determine the number of comparisons that will take place during a search using both searching algorithms (Linear search and binary search). Also, list each comparison for each algorithm(Linear and binary). The number being searched for is 13.

List = {1,3,5,9,10,11,15,17,19,23,24,25,29,31,33,37,38,39,43,45,47,51,52,53,57,59,61}

Part 2

For the following example, determine the number of swaps that will take place during a sort using both sorting algorithms (bubble and selection sort). Also, list each swap for each algorithm (bubble and selection)

List = {23, 10, 3, -5, 2, 7, 0, 20, 15, 17, 9, 11, 4, 1}

In: Computer Science

C# Create a console application named that creates a list of shapes, uses serialization to save...

C#

Create a console application named that creates a list of shapes, uses serialization to save it to the filesystem using XML, and then deserializes it back:

// create a list of Shapes to serialize
var listOfShapes = new List<Shape>
{
new Circle { Colour = "Red", Radius = 2.5 },
new Rectangle { Colour = "Blue", Height = 20.0, Width = 10.0 },
new Circle { Colour = "Green", Radius = 8 },
new Circle { Colour = "Purple", Radius = 12.3 },
new Rectangle { Colour = "Blue", Height = 45.0, Width = 18.0 }
};

Shapes should have a read-only property named Area so that when you deserialize, you can output a list of shapes, including their areas, as shown here:

List<Shape> loadedShapesXml = serializerXml.Deserialize(fileXml)
as List<Shape>;
foreach (Shape item in loadedShapesXml) {
WriteLine($"{item.GetType().Name} is {item.Colour} and has an
area of {item.Area}");
}

This is what your output should look like when you run the application:

Loading shapes from XML:
Circle is Red and has an area of 19.6349540849362
Rectangle is Blue and has an area of 200
Circle is Green and has an area of 201.061929829747
Circle is Purple and has an area of 475.2915525616
Rectangle is Blue and has an area of 810

In: Computer Science

C++: Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except...

C++:

Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except to add documentation. PLEASE DO NOT CHANGE THE CODE JUST ADD DOCUMENTATION. Thank you. The last few have changed the code. Appreciate you all.
Please use the file names listed below since your file will have the following components:

Ch16_Ex5_MainProgram.cpp - given file


//22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999

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

using namespace std;

int main()
{
unorderedLinkedList<int> list, subList;

int num;                                                                                                                     

            cout << "Enter numbers ending with -999" << endl;                                                                                                                   
cin >> num;                                                                                                   

            while (num != -999)                                                                                        
{
list.insertLast(num);                                                                
cin >> num;                                                                                                   
}

            cout << endl;                                                                                                 

            cout << "List: ";                                              
list.print();                                                                                                      
cout << endl;                                                                                                             
cout << "Length of the list: " << list.length() << endl;                                                                                                    

            list.divideMid(subList);

            cout << "Lists after splitting list" << endl;

            cout << "list: ";
list.print();                                                                                                      
cout << endl;                                                                                                             
cout << "Length of the list: " << list.length() << endl;                

            cout << "sublist: ";
subList.print();                                                                                                
cout << endl;                                                                                                             
cout << "Length of subList: " << subList.length() << endl;
system("pause");
return 0;                                                        
}

linkedList.h
unorderedLinkedList.h

In: Computer Science

Nodes Problems In C++, Your objective is to write the definition of the function Maximum() whose...

Nodes Problems

In C++,

Your objective is to write the definition of the function Maximum() whose header is double Maximum(Node* root) It returns the maximum value from the singly linked list referenced by root. If root is referencing an empty list, the function returns 0.

Part B: Take home Your objective is to write the definition of the following functions the function

EndAppend() whose header is void EndAppend(Node*& data,Node* addon) template It appends the linked list referenced by addon to the end of the linked list referenced by data. For instances, if data = [a, b, c, d, e] and addon = [f, g, h, i, j]; then after the call of the function, data = [a, b, c, d, e, f, g, h, i, j].

the function GreaterThan() whose header is bool GreaterThan(Node* op1,Node* op2). Given that op1 and op2 references doubly linked lists that represent binary numbers, the function returns true if the list referenced by op1 is greater than the list referenced by op2 . For instances, if op1 = [0, 0, 1, 1, 0] and op2 = [1, 0, 0, 1], the function will return false. Do not assume that the lists are the same size.

In: Computer Science

Create a class called College that has: At least 2 constructors (one should be the default...

Create a class called College that has:

  • At least 2 constructors (one should be the default constructor)
  • All members private
  • The relevant setters and getters
  • A print_me() function
  • A college_ID member (unique)

Write two unsorted lists that manage the data for colleges and their ranking:

  • An unsorted list using an array
  • An unsorted list using a linked list

Each college will have a unique ID number that will be used for search.

For the lab you don't need to read the commands from a file. Your commands will be hard-coded as function calls within your main() function.

The following actions will be performed twice: once with the array and once with the linked list. Make sure your code is clearly marked with comments, so the grader can easily see which actions were performed with each structure.

  • Add 5 colleges
  • Print your list of colleges
  • Remove 2 colleges
  • Search for a college by college ID (it will print all the information about the college)
  • Print your list of colleges
  • Add 4 more colleges
  • Change the info in 1 college
  • Change the info in 1 college
  • Print all colleges
  • Add one more college
  • Print all colleges

C++language

In: Computer Science

(Programming Language: Python) It's trivial that the value of a number remains the same no matter...

(Programming Language: Python)

It's trivial that the value of a number remains the same no matter how many zeros precede it. However, adding the zeros at the end of the number increases the value * 10. Jasmine is tired of seeing \001/100" on her tests (well yes, no one really writes 001, but Jasmine's teacher finds it funny to do so). So, she managed to login to her teacher's computer and now wants to design a function that can move the 0's in her grade to the end before her teacher uploads her grades. Although we don't agree with Jasmine's tactics, Krish (Jasmine's mentor) told us to help her out by finishing the `move zeros' function. This function should move all the 0's in the given list to the end while preserving the order of the other elements.

Remember that this function needs to modify the list, not return a new list!

---------------------------------------------

def move_zeros(lst: List[int]) -> None:

"""

Move all the 0's in lst to the END of the lst *in-place*, i.e. *modify* the list, DONT return a new list

>>> lst = [1, 0, 2, 3]

>>> move_zeros(lst)

>>> lst [1, 2, 3, 0]

"""

pass

In: Computer Science

Suppose a professor has 3 separate lists of questions totaling 120 questions including: List 1: includes...

Suppose a professor has 3 separate lists of questions totaling 120 questions including:

List 1: includes 35 “Hard” questions. You have 40% likelihood of answering each hard question correctly

List 2: includes 50 “Intermediate” questions. You have 60% likelihood of answering each intermediate question correctly

List 3: includes 35 “Easy” questions. You have 80% likelihood of answering each easy question correctly

Professor lets you choose either one of the following 5 exams (You take only one of these 5):

Exam1: includes 30 randomly selected questions, all from list 1. If you choose this exam you can pass if you score 40% (12 out of 30) or higher in this exam.

Exam2:  includes 30 randomly selected questions, all from list 2. If you choose this exam you can pass if you score 60% (18 out of 30) or higher in this exam.

Exam3: includes 30 randomly selected questions, all from list 3. If you choose this exam you can pass if you score 80% (24 out of 30) or higher in this exam.

Exam4: including 30 questions that consist of 7 questions from the list 1, 13 questions from the list 2, and 10 questions from list 3 (all randomly selected). If you choose this exam you can pass if you score 60% (18 out of 30) or higher in this exam.

Exam5: includes 30 randomly selected questions from the list of all 120 questions of all 3 lists combined. If you choose this exam you can pass if you score 60% (18 out of 30) or higher in this exam.

Find probability of passing each exam i.e. fill out the empty column in the following table based on binomial distribution answers and highlight in the table the exam which you will choose to take. (Do not use binomial to Normal approximation for question 1, just solve it as binomial)

***Needs to be solved as Binomial***

P(passing the exam1)

P(passing the exam2)

P(passing the exam3)

P(passing the exam4)

P(passing the exam5)

In: Statistics and Probability

In this problem, you will write a program that reverses a linked list. Your program should...

In this problem, you will write a program that reverses a linked

list. Your program should take as input a space-separated list of integers

representing the original list, and output a space-separated list of integers

representing the reversed list. Your algorithm must have a worst-case run-

time in O(n) and a worst-case space complexity of O(1) beyond the input.

For example, if our input is:

5 7 1 2 3

then we should print:

3 2 1 7 5

Please note that the starter code contains the following files:

• MyLinkedListNode: A class representing linked list nodes. Each

node contains an integer value, a variable next representing the next

node in the list (which is null if we’re at the last node), and a variable prev

representing the previous node in the list (which is null if we’re at the first node). You will probably need to modify this file.

• MyLinkedList: A class representing a stripped-down version of a

linked list. We keep track of the first and last nodes of the list, and

have methods for creating linked lists from arrays and converting

linked lists to space-separated strings.

Your task is to complete the reverse() method in this class.

• Main: A class with a main() method that collects input into a linked

list, calls the reverse() method, and outputs the resulting linked

list. You should not modify this file.

Restrictions:

(a) In this problem, you must use the custom MyLinkedList class. You may not use the normal LinkedList class. Any solutions that do not use MyLinkedList will receive a zero in all categories.

(b) Your algorithm must have a worst-case runtime in O(n) and a worst-

case space complexity of O (1) beyond the input. Any solutions that are less efficient will receive at most half credit for all categories. The class Main provides starter code for turning the input into a linked list, and turning a linked list into the output string. Your job is to implement the reverse() method in the MyLinkedList class. You will need to modify the MyLinkedListNode class as well.

Main.java

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  
// Read in the list of numbers
int[] numbers;
String input = sc.nextLine();
if (input.equals("")) {
numbers = new int[0];
} else {
String[] numberStrings = input.split(" ");
numbers = new int[numberStrings.length];
for (int i = 0; i < numberStrings.length; i++) {
numbers[i] = Integer.parseInt(numberStrings[i]);
}
}
  
// Create a MyLinkedList containing these numbers
MyLinkedList numbersList = new MyLinkedList(numbers);
  
// Reverse the list
numbersList.reverse();
  
// Print the reversed list
System.out.println(numbersList.toString());
}
}

MyLinkedList.java

public class MyLinkedList {
private MyLinkedListNode firstNode = null;
private MyLinkedListNode lastNode = null;
private int length = 0;
  
/**
* Constructs a MyLinkedList from an integer array.
*/
public MyLinkedList(int[] numbersArray) {
// set length
length = numbersArray.length;
  
// leave the first and last nodes as null if there
// are no elements in the array
if (numbersArray.length == 0) {
return;
}
  
// set the first node to the first number
firstNode = new MyLinkedListNode(numbersArray[0], null, null);
if (numbersArray.length == 1) {
lastNode = firstNode;
return;
}
  
// create all the middle nodes
MyLinkedListNode prevNode = firstNode;
for (int i = 1; i < numbersArray.length - 1; i++) {
MyLinkedListNode currentNode =
new MyLinkedListNode(numbersArray[i], prevNode, null);
prevNode.setNext(currentNode);
prevNode = currentNode;
}
  
// set the last node to the last number
lastNode = new MyLinkedListNode(
numbersArray[numbersArray.length-1],
prevNode,
null);
prevNode.setNext(lastNode);
}
  
@Override
public String toString() {
StringBuilder sb = new StringBuilder(length);
  
MyLinkedListNode currentNode = firstNode;
for (int i = 0; i < length; i++) {
sb.append(currentNode.toString());
if (i < length - 1) {
sb.append(" ");
currentNode = currentNode.getNext();
}
}
  
return sb.toString();
}
  
/**
* Reverses this linked list.
*/
public void reverse() {
// TODO implement this
}
}

MyLinkedListNode.java

public class MyLinkedListNode {
private int value = 0;
private MyLinkedListNode prev = null;
private MyLinkedListNode next = null;
  
public MyLinkedListNode(int value, MyLinkedListNode prev, MyLinkedListNode next) {
this.value = value;
this.prev = prev;
this.next = next;
}
  
public MyLinkedListNode getNext() {
return next;
}
  
public void setNext(MyLinkedListNode next) {
this.next = next;
}
  
@Override
public String toString() {
return (new Integer(this.value)).toString();
}
}

In: Computer Science