Questions
A company creates a database for its customers in which each customer is identified by their...

A company creates a database for its customers in which each customer is identified by their phone number. In this discussion, explore whether or not this is a function with your classmates. In your first post, address the following:

  1. Assign one variable as the input and the other variable as the output for this scenario. Is this relation a function? Justify your answer using the definition of a function, and explain your reasoning carefully.
  2. Do you think this is a good setup for the company’s database? Describe any pitfalls you see in this setup.
  3. Suggest an alternative identification system for the company’s database.

In: Computer Science

I'm a little confused as to what exactly I'm researching and writing about. If someone could...

I'm a little confused as to what exactly I'm researching and writing about. If someone could break it down and give me a few minor examples so I can structure the essay around it I would really appreciate it:

(Intel 80x86, ARM, MIPS R4000 )Write a two page report on the similarities and differences are of these architectures. Include in your report what you find interesting about the architectures you researched.

In: Computer Science

Given an array of Student type and size 10, create a linked list of students by...

Given an array of Student type and size 10, create a linked list of students by linking students with an odd index first and then linking students with an even index. Write a loop to print out the students in the linked list.

#include #include #include using namespace std; const int NUM = 10; struct Student{ string fName; string lName; Student * next; }; int main() { Student stuArr[NUM]; ifstream myfile; myfile.open("Test.txt"); for(int i = 0; i < NUM; i++) { myfile>>stuArr[i].fName; myfile>>stuArr[i].lName; stuArr[i].next = 0; }

In: Computer Science

INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? void readFile(Candidate candidates[]) –...

INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO?

void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0.


void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking list.


void displayCandidate(Candidate candidates[]) – prints the complete information about the candidate

.
Candidate First(Candidate candidates[]) – returns single struct element: candidate with highest score


Candidate Last(Candidate candidates[]) – returns single struct element: candidate with lowest score


void Votes(Candidate candidates[]) – function sorts the candidates[] array by number of votes, the order in candidates[] array is replaced


void Scores(Candidate candidates[]) – calculates the percentage score for each candidate. Use the following formula: ??????=(CandidateVotes)/(sum of votes)*100%

Correct line for the reference: F=John,L=Smith,V=3342

The line errors that your program needs to detect, are as follows:

incorrect token / separator, example in line 5: F=Steven,L=JohnV=4429 --- (comma missing) – lines with this error need to be ignored

space in token, example in line 3: F=Hillary,X=Clinton, V=1622 --- lines with this error need to be read, error fixed, data included in your dataset

empty line, example in line 6 – empty lines need to be ignored

Example Textfile

F=Michael,L=John,V=3342

F=Danny,L=Red,V=2003

F=Hillary,L=Clinton, V=1588

F=Albert,L=Lee,V=5332

F=Steven,L=JohnV=4429

*IMPORTANT* How would I do the readFile function? It says to check if the commas are present, and that the program will correct the line if there is white spaces. How do i use the find() function? Please be DETAILED in explanations of each part of code. Beginner Coder. *IMPORTANT*

Code Skeleton We HAVE to follow. How Would i go about using this skeleton? YOU CANNOT CHANGE FUNCTIONS OF VARIABLES, BUT YOU MAY ADD TO IT. THE CODE MUST HAVE WHAT IS LISTED IN THE SKELETON CODE:

#include <iostream>

#include <iomanip>

#include <stdlib.h>

#include <fstream>

#include <string>

using namespace std;

struct Candidate {
string Fname;
string Lname;
int votes;
double Score;
};

const int MAX_SIZE = 100;

void readFile(Candidate[]);

void List(Candidate[]);

void Votes(Candidate[]);

void displayCandidate(Candidate);

Candidate First(Candidate[]);

Candidate Last(Candidate[]);

void Scores(Candidate[]);

int main() {

}

void readFile(Candidate candidates[]) {

string line;

ifstream infile;

infile.open("elections.txt");

while (!infile.eof()) {

getline(infile,line);

// your code here

}

infile.close();

}

void List(Candidate candidates[]) {

}

void Votes(Candidate candidates[]) {

}

void displayCandidate(Candidate candidates) {

}

Candidate First(Candidate candidates[]) {

}

Candidate Last(Candidate candidates[]) {

}

void Scores(Candidate candidates[]) {

}

Also, how do i make verticle columbs for the display?

In: Computer Science

(C++) How do I go about obtaining the origin of a point via an instance variable?...

(C++) How do I go about obtaining the origin of a point via an instance variable?

I'm fairly new to C++ and one of my first assignments in my current class has a focus on us trying to understand headers, implementations, pointers, constructors, and the like. This particular assignment has us working with x and y coordinates. I've gotten most of this completed, but I'm not quite sure what I've done so far is going to work and there are a few parts I've completely stuck on; I haven't even been able to test this yet. Also, I apologize in advance if I'm not using the proper terminology for some of this.

There are two headers, and here is an abstract one (Point.h) that doesn't require me to edit it, but is important as a reference to the entire assignment:

    using length_unit = double;
    using coordinate_unit = double;
  
    /**
     * A Point Interface.
     */
    class Point {
    public:
        /**
         * Calculate the distance this Point is from the origin.
         * @return The distance this Point is from the origin is returned.
         */
        virtual length_unit DistanceFromOrigin() const = 0;
  
        /**
         * Calculate the distance this Point is from the given Point.
         * @param other another Point in the plane
         * @return The distance this Point is from the given Point is returned.
         */
        virtual length_unit DistanceFromPoint(const Point &other) const = 0;
  
        virtual ~Point() = default;
    };

Here's another header (TwoDimensionalPoint.h) that I was only required to add private data members with the stipulation that they have to pointers:

    #include "Point.h"
  
    /**
     * An implementation of the Point interface in a two-dimensional plane.
     */
    class TwoDimensionalPoint : public Point {
    private:
        // TODO: Add appropriate data members
        coordinate_unit *x_coordinate;
        coordinate_unit *y_coordinate;
      
    public:
        /**
         * Default/initializing constructor.
         * @param x_coordinate the x-coordinate of this Point
         * @param y_coordinate the y-coordinate of this Point
         */
        explicit TwoDimensionalPoint(coordinate_unit x_coordinate = 0, coordinate_unit y_coordinate = 0);
  
        /* The Big Five */
  
        /**
         * Destructor responsible for deleting memory occupied by the coordinates of this Point.
         */
        ~TwoDimensionalPoint() override;
  
        /**
         * Copy constructor used to create a new Point with the same coordinates of the other Point.
         * @param other a Point used as a template for creating this point using copy semantics
         */
        TwoDimensionalPoint(const TwoDimensionalPoint &other);
  
        /**
         * Move constructor used to create a new Point with the same coordinates of the other Point.
         * @param other a Point used as a template for creating this point using move semantics
         */
        TwoDimensionalPoint(TwoDimensionalPoint &&other) noexcept;
  
        /**
         * Copy assignment operator used to create a new Point with the same coordinates as the other Point.
         * @param rhs an l-value; the right-hand side of the assignment statement lhs = rhs
         * @return A new Point with the same coordinates as the given (l-value) TwoDimensionalPoint is returned.
         */
        TwoDimensionalPoint &operator=(const TwoDimensionalPoint &rhs);
  
        /**
         * Move assignment operator used to create a new Point with the same coordinates as the other Point.
         * @param rhs an r-value; the right-hand side of the assignment statement TwoDimensionalPoint lhs = TwoDimensionalPoint{x, y}
         * @return A new Point with the same coordinates as the given (r-value) TwoDimensional Point is returned.
         */
        TwoDimensionalPoint &operator=(TwoDimensionalPoint &&rhs);
  
        /* Inherited Point behavior */
  
        /**
         * @copydoc Point::DistanceFromOrigin() const
         */
        length_unit DistanceFromOrigin() const override;
  
        /**
         * @copydoc Point::DistanceFromPoint(const Point &other) const
         */
        length_unit DistanceFromPoint(const Point &other) const override;
  
        /* Specific TwoDimensionalPoint behavior */
  
        /**
         * X-coordinate accessor method.
         * @return The x-coordinate of this Point is returned.
         */
        virtual length_unit GetX() const;
  
        /**
         * Y-coordinate accessor method.
         * @return The y-coordinate of this Point is returned.
         */
        virtual length_unit GetY() const;
  
        /**
         * Assess whether this Point is the origin.
         * @return True if this Point is the origin, otherwise false.
         */
        virtual bool IsOrigin() const;
  
        /**
         * Translates this Point by the given dimensions.
         * @param x the amount to translate in the x-direction
         * @param y the amount to translate in the y-direction
         */
        void Translate(coordinate_unit x = 0, coordinate_unit y = 0);
    };

And then finally the implementation (TwoDimensionalPoint.cpp) is the meat and potatoes of what I need to do; I have to complete the areas with commented with "TODO":

    #include <algorithm>
    #include <cmath>
    #include "TwoDimensionalPoint.h"
  
    TwoDimensionalPoint::TwoDimensionalPoint(coordinate_unit x_coordinate, coordinate_unit y_coordinate) {
        // TODO: Add an appropriate initializer list
        x_coordinate = new coordinate_unit{ x_coordinate };
        y_coordinate = new coordinate_unit{ y_coordinate };
    }
  
    TwoDimensionalPoint::~TwoDimensionalPoint() {
        // TODO: Delete appropriate data members
        delete x_coordinate, y_coordinate;
    }
  
    TwoDimensionalPoint::TwoDimensionalPoint(const TwoDimensionalPoint &other) {
        // TODO: Add an appropriate initializer list
        x_coordinate = new coordinate_unit{ *other.x_coordinate };
        y_coordinate = new coordinate_unit{ *other.y_coordinate };
    }
  
    TwoDimensionalPoint::TwoDimensionalPoint(TwoDimensionalPoint &&other) noexcept {
        // TODO: Add an appropriate initializer list and appropriate body
        other.x_coordinate = nullptr;
        other.y_coordinate = nullptr;
    }
  
    TwoDimensionalPoint &TwoDimensionalPoint::operator=(const TwoDimensionalPoint &rhs) {
        // TODO: Add any appropriate code
        if (this != &rhs)
            *x_coordinate = *rhs.x_coordinate;
            *y_coordinate = *rhs.y_coordinate;
        return *this;
    }
  
    TwoDimensionalPoint &TwoDimensionalPoint::operator=(TwoDimensionalPoint &&rhs) {
        // TODO: Add any appropriate code
        std::swap(x_coordinate, rhs.x_coordinate);
        std::swap(y_coordinate, rhs.y_coordinate);
        return *this;
    }
  
    length_unit TwoDimensionalPoint::DistanceFromOrigin() const {
        // TODO: Calculate and return the correct value
        const coordinate_unit temp_x = 0 - //no idea
        const coordinate_unit temp_y = 0 - //no idea
        return sqrt( pow(temp_x, 2) + pow(temp_x, 2) );
    }
  
    length_unit TwoDimensionalPoint::DistanceFromPoint(const Point &other) const {
        // TODO: Calculate and return the correct value
        const coordinate_unit x_diff = other.GetX() - GetX();
        const coordinate_unit y_diff = other.GetY() - GetY();
        return sqrt( pow(x_diff, 2) + pow(y_diff, 2) );
    }
  
    length_unit TwoDimensionalPoint::GetX() const {
        // TODO: Return the appropriate value
        const coordinate_unit *x_coordinate = &x_coordinate;
        return *x_coordinate;
    }
  
    length_unit TwoDimensionalPoint::GetY() const {
        // TODO: Return the appropriate value
        const coordinate_unit *y_coordinate = &y_coordinate;
        return *y_coordinate;
    }
  
    bool TwoDimensionalPoint::IsOrigin() const {
        // TODO Return the correct value
        if //unfinished due to not knowing how to complete DistanceFromOrigin()
  
        else
        return false;
    }
  
    void TwoDimensionalPoint::Translate(coordinate_unit x, coordinate_unit y) {
        // TODO: Implement me
        std::cout << "X is translated by: " << x << std::endl;
        std::cout << "Y is translated by: " << y << std::endl;
    } //This part confuses me as well since there are different parameters. I.e., x and y instead of x_coordinate and y_coordinate like throughout the rest of the program.

I feel like I'm close to finishing this, but Visual Studio Code has been throwing some problems throughout this, so I'm not completely certain. I've added some of my own comments to point out areas I'm particularly stuck. Any help would be highly appreciated!

In: Computer Science

(1) Define the term identifier as a name for something, such as a variable, constant, or...

(1) Define the term identifier as a name for something, such as a variable, constant, or function.

(2) Define the term data type as a set of values together with a set of operations.

(3) Discuss the five arithmetic operators in C++ that are used to manipulate integral and floating-type data types.

In: Computer Science

C++ Write a program for sorting a list of integers in ascending order using the bubble...

C++

Write a program for sorting a list of integers in ascending order using the bubble sort algorithm

Requirements
Implement the following functions:

  1. Implement a function called readData
    int readData( int **arr)
    arr is a pointer for storing the integers. The function returns the number of integers.
    The function readData reads the list of integers from a file call data.txt into the array arr. The first integer number in the file is the number of intergers. After the first number, the file lists the integers line by line.
  2. void bsort(int *arr, int last)
    arr is a pointer to an array of integers to be sorted. last is the number of elements in the array. The function bsort sorts the list of integers in ascending order.
    Here is the Link to the Bubble Sort.
  3. writeToConsole(int * arr, int last)
    arr is a pointer to an array of integers. last is the number of elements in the array. The function writeToConsole displays the sorted list.
  4. Do not use the array notation in your solution.

Here is the content of the file data.txt.
9
8
4
7
2
9
5
6
1
3

In: Computer Science

Each player throws both dice once per turn. The player only scores when the player throws...

Each player throws both dice once per turn. The player only scores when the player throws doubles. Double-6 scores 25 points. A double-3 cancels out a player’s score and puts the score back to zero. Any double other than a 3 or 6 scores 5 points. Scores are recorded and the first player to obtain a total score of fifty points wins the game.

Write a MATLAB program to simulate the FIFTY dice game that can:

1. Play the FIFTY dice game automatically for one player using two dice.

2. Add your name, purpose, and copyright your program.

3. Clear command window and clear all variables.

4. Randomize the pseudorandom number generator with the MATLAB built-in rng function and provide ‘shuffle’ as the function input.

5. Create a variable that will keep the game score. Set the value of this variable to 0.

6. Create another variable that will count the round number. Set the value of this variable to 1.

7. Welcome the player and briefly explain how to play the game when the program starts.

8. Print the current round number in the command window.

9. Print the current game score in the command window.

10. Generate two random integers between 1 and 6 to represent the face values of two dice.

11. Print the two dice values in the command window.

12. If the value of the 1 st die and the 2nd die are not equivalent with each other: a. No action required. We can optionally display a message that no point will be added to the game score.

13. Else a. If the value of the first die is equivalent with 3: i. Display a message about rolling a double 3 causes the game score to set back to 0. ii. Set the game score to 0. b. Elseif the value of the first die is equivalent with 6: i. Display a message about rolling a double 6 adds 25 points to the game score. ii. Set the game score to game score plus 25. c. Else: i. Print a message about rolling the double dice adds 5 points to the game score. ii. Set the game score to game score plus 5. d. End.

14. End.

15. Increment the round number by 1.

16. The game should keep playing while the player’s game score is less than 50 points. Insert a while loop to wrap around the code generated from step 8 through step 15. Make the existing code generated from steps 8 through 15 the code block of this new while loop.

17. Congratulate the player and show the player’s final game score in the command window.

In: Computer Science

Java Generic 2D Linked List Problem How to convert a 1D linked List into multiple linked...

Java Generic 2D Linked List Problem

How to convert a 1D linked List into multiple linked lists with sequential values together?

//Example 1: [1,1,2,3,3] becomes [[1,1],[2],[3,3]]
//Example 1: [1,1,2,1,1,2,2,2,2] becomes [[1,1],[2],[1,1],[2,2,2,2]]
//Example 3: [1,2,3,4,5] becomes [[1],[2],[3],[4],[5]]

public <T> List<List<T>> convert2D(List<T> list) {

// Given a 1D, need to combine sequential values together.

}

In: Computer Science

6. Write a Java program to rotate an array (length 3) of integers in left direction...

6. Write a Java program to rotate an array (length 3) of integers in left direction
7. Write a Java program to store a collection of integers, sort them in ascending order and print the sorted integers.

In: Computer Science

Important: you are required to use only the functional features of Scheme; functions with an exclama-...

Important: you are required to use only the functional features of Scheme; functions with an exclama- tion point in their names (e.g., set!) and input/output mechanisms other than load and the regular read-eval-print loop are not allowed. (You may find imperative features useful for debugging. That’s ok, but get them out of your code before you hand anything in.)

1. (10 pts) Write a function atLeast that returns true if a list is at least as long as the argument value, and false otherwise. Use predicate functions and recursion, and assume that the length given is at least 0 (i.e., the first parameter cannot be negative).
> (atLeast 5 ’(1 2 3 4))
#f
> (atLeast 5 ’(2 4 6 8 10))
#t


using the programming language scheme

In: Computer Science

Add a copy constructor for the linked list implementation below: ---------------------------------------------------------------------------------------------------------------------------------------------------- // list.cpp file #include <string>

Add a copy constructor for the linked list implementation below:

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

// list.cpp file

#include <string>
#include "list.h"

using namespace std;

Node::Node(string element)
{
data = element;
previous = nullptr;
next = nullptr;
}

List::List()
{
first = nullptr;
last = nullptr;
}

List::List(const List& rhs) // Copy constructor - homework
{
// Your code here
  
}

void List::push_back(string element)
{
Node* new_node = new Node(element);
if (last == nullptr) // List is empty
{
first = new_node;
last = new_node;
}
else
{
new_node->previous = last;
last->next = new_node;
last = new_node;
}
}

void List::insert(Iterator iter, string element)
{
if (iter.position == nullptr)
{
push_back(element);
return;
}

Node* after = iter.position;
Node* before = after->previous;
Node* new_node = new Node(element);
new_node->previous = before;
new_node->next = after;
after->previous = new_node;
if (before == nullptr) // Insert at beginning
{
first = new_node;
}
else
{
before->next = new_node;
}
}

Iterator List::erase(Iterator iter)
{
Node* remove = iter.position;
Node* before = remove->previous;
Node* after = remove->next;
if (remove == first)
{
first = after;
}
else
{
before->next = after;
}
if (remove == last)
{
last = before;
}
else
{
after->previous = before;
}
delete remove;
Iterator r;
r.position = after;
r.container = this;
return r;
}

Iterator List::begin()
{
Iterator iter;
iter.position = first;
iter.container = this;
return iter;
}

Iterator List::end()
{
Iterator iter;
iter.position = nullptr;
iter.container = this;
return iter;
}

Iterator::Iterator()
{
position = nullptr;
container = nullptr;
}

string Iterator::get() const
{
return position->data;
}

void Iterator::next()
{
position = position->next;
}

void Iterator::previous()
{
if (position == nullptr)
{
position = container->last;
}
else
{
position = position->previous;
}
}

bool Iterator::equals(Iterator other) const
{
return position == other.position;
}

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

Use the following header file, and test program (not to be modified) to verify that the copy constructor works correctly:

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

// list.h file

#ifndef LIST_H
#define LIST_H

#include <string>

using namespace std;

class List;
class Iterator;
//template <typename T>
class Node
{
public:
/**
Constructs a node with a given data value.
@param element the data to store in this node
*/
Node(string element); // Node(T element)
// Node(T data, Node<T>* n, Node<T>* n);
private:
string data; // T data;
Node* previous;
Node* next;
friend class List;
friend class Iterator;
};

class List
{
public:
/**
Constructs an empty list.
*/
List();
List(const List& rhs); // Homework
/*
Appends an element to the list.
@param element the value to append
*/
void push_back(string element);
/**
Inserts an element into the list.
@param iter the position before which to insert
@param element the value to insert
*/
void insert(Iterator iter, string element);
/**
Removes an element from the list.
@param iter the position to remove
@return an iterator pointing to the element after the
erased element
*/
Iterator erase(Iterator iter);
/**
Gets the beginning position of the list.
@return an iterator pointing to the beginning of the list
*/
Iterator begin();
/**
Gets the past-the-end position of the list.
@return an iterator pointing past the end of the list
*/
Iterator end();
private:
Node* first;
Node* last;
friend class Iterator;
};

class Iterator
{
public:
/**
Constructs an iterator that does not point into any list.
*/
Iterator();
/**
Looks up the value at a position.
@return the value of the node to which the iterator points
*/
string get() const;
/**
Advances the iterator to the next node.
*/
void next();
/**
Moves the iterator to the previous node.
*/
void previous();
/**
Compares two iterators.
@param other the iterator to compare with this iterator
@return true if this iterator and other are equal
*/
bool equals(Iterator other) const;
private:
Node* position;
List* container;
friend class List;
};

#endif

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

// list_test .cpp file

#include <string>
#include <iostream>
#include "list.h"

using namespace std;

int main()
{
List names;

names.push_back("Tom");
names.push_back("Diana");
names.push_back("Harry");
names.push_back("Juliet");

// Add a value in fourth place

Iterator pos = names.begin();
pos.next();
pos.next();
pos.next();

names.insert(pos, "Romeo");

// Remove the value in second place

pos = names.begin();
pos.next();

names.erase(pos);

List names_copy(names); //Copy constructor - homework
names_copy.push_back("Shakespeare");
// Verify that Shakespeare was inserted.
cout << "Printing new list" << endl;
for (pos = names_copy.begin(); !pos.equals(names.end()); pos.next())
{
cout << pos.get() << endl; //
}
cout << "Printing original list " << endl;
for (pos = names.begin(); !pos.equals(names.end()); pos.next())
{
cout << pos.get() << endl;
}

return 0;
}


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

Thank you for your time and help!

In: Computer Science

The following equation can be used to compute values of y as a function of x:...

The following equation can be used to compute values of y as a function of x: ? = ?? −??sin(??)(0.012? 4 − 0.15? 3 + 0.075? 2 + 2.5?) where a and b are parameters. Write a Matlab script file (m file) with the following steps: Step 1: Define scalars a = 2, b = 5. Step 2: Define vector x holding values from 0 to π/2 in increments of Δx = π/40. Step 3: generate the vector y using element-wise product (dot product). Step 4. Compute the vector z = y 2 where each element holds the square of each element of y. Step 5: Combine x, y, and z into a matrix w, where each column holds one of the variables, and display w using the short g format. Step 6: Generate plots of y and z versus x using dashed lines. Step 7: Include legends for each plot (for y vs. x plot, use “y” as legend; for z vs. x plot, use “z” as legend).

In: Computer Science

Given the following numbers in the given order, show the red black tree              100, 200,...

Given the following numbers in the given order, show the red black tree

             100, 200, 150, 170, 165, 180, 220, 163, 164

Show the pre-order traversal of this red black tree while showing the color of each node in the pre-order traversal.

Write (C++) the red black tree code and insert the above numbers. Show the screen shot of the pre-order traversal of the resulting tree. Distinguish the colors by writing a * next to the black color values. Compare the result with the previous question.

In: Computer Science

Write a C-based language program in visual studio that uses an array of structs that stores...

Write a C-based language program in visual studio that uses an array of structs that stores student information including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,”).

Write the same program in the same language without using structs.

In: Computer Science