Questions
Change the ones with Bold text on the code accordingly. The code within the if statement...

Change the ones with Bold text on the code accordingly.

The code within the if statement is not doing the correct process. When your code goes to the c2 function it should be passing argv[1] to it.

(side note: your program design of calling the function c1(), c2() c3() is a bit odd, but it can work)

if (argv[2] == _c2)   
                {
                        ret = c1(argv[2]);
                        ret = ret >> 2;//divide by 2 to make it 8 bit
 
                }
                else if (argv[2] == _c1)
                {
                        ret = c2(argv[1]);
                        ret = ret >> 2;//divide by 2 to make it 8 bit // this should be done in the c2() funciton
                }
                else if (argv[1] == _c3)
                {
                        ret = c3(argv[2]);
                        ret = ret >> 2;//divide by 2 to make it 8 bit // this should be done in the c2() funciton
                }
                else if (argv[1] == _c4)
                {
                        ret = c4(argv[2]);
                        ret = ret >> 2;//divide by 2 to make it 8 bit  // this should be done in the c2() funciton
                }
                else {
                        cout << "'V' - Invalid operation selection" << endl;
                        exit(0);
                }

In: Computer Science

•   What is “umask” in Unix? •   What are the “setuid”, “setgid” and “sticky” bit flags?...

•   What is “umask” in Unix?
•   What are the “setuid”, “setgid” and “sticky” bit flags?
•   What are access tokens and security descriptors in the context of Windows access control?
•   What are principles of the Bell-LaPadula confidentiality model?
•   What are principles of the Biba integrity model?
•   What are principles of the Clark-Wilson integrity model?

In: Computer Science

Python While traveling home for the holiday, you wondered how much time you'd save if you...

Python

While traveling home for the holiday, you wondered how much time you'd save if you drove faster. The distance home is 120 miles, and you decided to compare driving 55 mph versus 70 mph. You also wondered if driving faster around town really saves you that much time. The around-town distance you chose was 5 miles, using speeds of 25 and 35 mph. Of course, you decided that no amount of times savings is worth the risk to yourself or others, but you still wanted to find the answer.

Create two functions to help calculate the travel time in hours, minutes and seconds and to display the results.

# Calculate travel time in minutes given the distance in miles and the speed in mph
calc_travel_time ( distance, speed )

# Output the travel time hours, minutes and seconds given distance and speed
print_travel_time ( distance, speed )

Your Python solution must include the following:

  • The calc_travel_time() function will return the travel time in minutes
  • The print_travel_time() function will use (call) the calc_travel_time() function, and will determine the actual time in hours, minutes and seconds, using the int() and round() Python functions
  • Include the single line comment above each function
  • Comment the test section of your program
  • Include the standard class ''' comment section at the top of your file
  • Include a section called References that lists the web site reference link

Tip:

Expected output:

To travel 120 miles at 55 MPH will take 2 hr, 10 min and 55 sec
To travel 120 miles at 70 MPH will take 1 hr, 42 min and 51 sec
To travel 5 miles at 25 MPH will take 0 hr, 12 min and 0 sec
To travel 5 miles at 35 MPH will take 0 hr, 8 min and 34 sec

In: Computer Science

John has recently discovered that online auctions can provide him with more opportunities to expand his...

John has recently discovered that online auctions can provide him with more opportunities to expand his business on the web. However, John has to conduct research about the various categories of auction Websites before choosing one that suits his business needs. Briefly explain three broad categories of auction Websites that should form part of John's research.

In: Computer Science

All years that are evenly divisible by 400 or are evenly divisible by four and not...

All years that are evenly divisible by 400 or are evenly divisible by four and not evenly divisible 100 are leap years. For example, since 1600 is evenly divisible by 400, the year 1600 was a leap year. Similarly, since 1988 is evenly divisible by four but not 100, the year 1988 was also a leap year. Using this information, write a C++ program that accepts the year as user input, determines if the year is a leap year, and displays an appropriate message that tells the user whether the entered year is or is not a leap year.

In: Computer Science

Routine Persuasive Message Guidelines Summary Because everyone at your company is suddenly working from home due...

Routine Persuasive Message Guidelines

Summary Because everyone at your company is suddenly working from home due to the pandemic, upper management wants to make it mandatory for all employees to install insecure corporate spyware on any device they use for work. As the lead developer on your team, you must speak up for yourself and your colleagues and persuade your direct manager that this is a bad idea. Using the strategies discussed in your readings and resources, write a well formatted email to your manager, Deion Guillory (he/him). Include a subject line and email signature. Do not copy text or phrases from these guidelines, the readings, templates, or any other source.

Details For this assignment, imagine that you are a senior software developer at the imaginary company, Swift Coding Enterprises. The company has been fortunate during the pandemic: the software you make is still in high demand, and your jobs are such that all employees can do their work from home. Some of you are using company laptops, but most of you have your own desktop computers, laptops, tablets, etc. that you also use for work while you’re at home. However, your upper management (CEO, CFO, etc.) are concerned that employees are “slacking off” because they’re working from home. They want to monitor employees’ work to make sure no one is taking advantage of the situation to be less productive. In order to do this, they’ve instructed all managers to make it mandatory for employees to download and install Beramind corporate monitoring software on any device the employee uses for work. Beramind takes screenshots of the user’s display every 30 seconds and sends it to cloud storage. Anyone who has the company’s admin login can view these screenshots and which employee’s computer they come from. They can also choose, without notifying the user, to mirror a user’s display on their own system and watch what that user is doing in real time. Your manager, Deion Guillory (he/him), has received these instructions from his own manager. He has sent a memo to you and your team telling you to download and install Beramind on your computers. You and your team have discussed the situation privately, and you don’t want to install Beramind for many reasons, such as:

- Your team’s output (e.g. code, documentation) has been the same as when you worked in the office. - Some of you haven’t been able to work as many hours as usual, but it’s not because you’re slacking off—it’s because there’s a pandemic, and you have other emergency responsibilities, such as taking care of children. - You don’t want your bosses to be able to monitor your activity on your personal and/or family computers, even if you do use it for work sometimes. - Beramind uses a lot of bandwidth, system memory, and processor power, which not everyone is able to spare. - According to some articles you read online, Beramind doesn’t use end-to-end encryption when it sends data to its server.

Because you’re the team lead, it’s up to you to email Deion and explain your team’s situation. You want to make it clear that none of you will install this program, and you want to persuade Deion that it’s a bad enough idea that he should push back against it to his own bosses. TIP: You may make up any reasonable information you need (for example, a colleague’s name or exactly how much system memory Beramind needs) as long as it doesn’t contradict the assignment guidelines. By “reasonable,” your instructor means that the information you include might happen in reality and doesn’t substantially change the assignment. For example, it would not be “reasonable” to tell Deion that your team can’t install Beramind because you have all forgotten the passwords to your system admin profiles and can’t install anything.

Your email should follow the best practices for business emails that you’ve learned about in your readings/resources. You must include an email signature block and a subject line. There is no required word count, but you must include enough information to achieve your purpose effectively without overloading a single email with too much content. Most submissions will be between 200 and 500 words, although it is possible to write an excellent but slightly longer or shorter submission.

In: Computer Science

Two sorted lists have been created, one implemented using a linked list (LinkedListLibrary linkedListLibrary) and the...

Two sorted lists have been created, one implemented using a linked list (LinkedListLibrary linkedListLibrary) and the other implemented using the built-in Vector class (VectorLibrary vectorLibrary). Each list contains 100 books (title, ISBN number, author), sorted in ascending order by ISBN number.

Complete main() by inserting a new book into each list using the respective LinkedListLibrary and VectorLibrary InsertSorted() methods and outputting the number of operations the computer must perform to insert the new book. Each InsertSorted() returns the number of operations the computer performs.

Ex: If the input is:

The Catcher in the Rye
9787543321724
J.D. Salinger

the output is:

Number of linked list operations: 1
Number of vector operations: 1

________________________________________

The given code that i must use is:

____________________________________________________________________

Main.cpp

#include "LinkedListLibrary.h"
#include "VectorLibrary.h"
#include "BookNode.h"
#include "Book.h"
#include <fstream>
#include <iostream>
using namespace std;

void FillLibraries(LinkedListLibrary &linkedListLibrary, VectorLibrary &vectorLibrary) {
ifstream inputFS; // File input stream
int linkedListOperations = 0;
int vectorOperations = 0;

BookNode* currNode;
Book tempBook;

string bookTitle;
string bookAuthor;
long bookISBN;

// Try to open file
inputFS.open("books.txt");

while(getline(inputFS, bookTitle)) {
inputFS >> bookISBN;
inputFS.ignore(1, '\n');
getline(inputFS, bookAuthor);

// Insert into linked list
currNode = new BookNode(bookTitle, bookAuthor, bookISBN);
linkedListOperations = linkedListLibrary.InsertSorted(currNode, linkedListOperations);
linkedListLibrary.lastNode = currNode;

// Insert into vector
tempBook = Book(bookTitle, bookAuthor, bookISBN);
vectorOperations = vectorLibrary.InsertSorted(tempBook, vectorOperations);
}

inputFS.close(); // close() may throw ios_base::failure if fails
}

int main (int argc, const char* argv[]) {
int linkedListOperations = 0;
int vectorOperations = 0;

// Create libraries
LinkedListLibrary linkedListLibrary = LinkedListLibrary();
VectorLibrary vectorLibrary;

// Fill libraries with 100 books
FillLibraries(linkedListLibrary, vectorLibrary);

// Create new book to insert into libraries
BookNode* currNode;
Book tempBook;

string bookTitle;
string bookAuthor;
long bookISBN;

getline(cin, bookTitle);
cin >> bookISBN;
cin.ignore();
getline(cin, bookAuthor);

// Insert into linked list
// No need to delete currNode, deleted by LinkedListLibrary destructor
currNode = new BookNode(bookTitle, bookAuthor, bookISBN);
// TODO: Call LL_Library's InsertSorted() method to insert currNode and return
// the number of operations performed

linkedListLibrary.lastNode = currNode;

// Insert into VectorList
tempBook = Book(bookTitle, bookAuthor, bookISBN);
// TODO: Call VectorLibrary's InsertSorted() method to insert currNode and return
// the number of operations performed

// TODO: Print number of operations for linked list

// TODO: Print number of operations for vector

}

__________________________________________________

LinkedListLibrary.h

#ifndef LINKEDLISTLIBRARYH
#define LINKEDLISTLIBRARYH

#include "BookNode.h"
using namespace std;

class LinkedListLibrary {
public:
//Linked list nodes
BookNode* headNode;
BookNode* lastNode;

LinkedListLibrary();

~LinkedListLibrary();

int InsertSorted(BookNode* newNode, int counter);

void PrintLibrary() const;
};

#endif

________________________________________________________

LinkedListLibrary.cpp

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

LinkedListLibrary::LinkedListLibrary() {
// Front of nodes list
headNode = nullptr;
lastNode = nullptr;
}

LinkedListLibrary::~LinkedListLibrary() {
while(headNode != nullptr) {
BookNode* tempNode = headNode->GetNext();
delete headNode;
headNode = tempNode;
}
}

int LinkedListLibrary::InsertSorted(BookNode* newNode, int counter) {
BookNode* currNode, nextNode;

// Special case for head node
if (headNode == nullptr || headNode->GetBookISBN() >= newNode->GetBookISBN()) {
newNode->SetNext(headNode);
headNode = newNode;
}
else {
// Locate the node before insertion point
currNode = headNode;

while (currNode->GetNext() && currNode->GetNext()->GetBookISBN() < newNode->GetBookISBN()) {
currNode = currNode->GetNext();
}
currNode->insertAfter(newNode);
}

++counter;
return counter;
}

void LinkedListLibrary::PrintLibrary() const {
BookNode* currNode;

currNode = headNode->GetNext();
while (currNode != nullptr) {
currNode->PrintBookInfo();
cout << endl;
currNode = currNode->GetNext();
}
}

____________________________________________________

VectorLibrary.h

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

LinkedListLibrary::LinkedListLibrary() {
// Front of nodes list
headNode = nullptr;
lastNode = nullptr;
}

LinkedListLibrary::~LinkedListLibrary() {
while(headNode != nullptr) {
BookNode* tempNode = headNode->GetNext();
delete headNode;
headNode = tempNode;
}
}

int LinkedListLibrary::InsertSorted(BookNode* newNode, int counter) {
BookNode* currNode, nextNode;

// Special case for head node
if (headNode == nullptr || headNode->GetBookISBN() >= newNode->GetBookISBN()) {
newNode->SetNext(headNode);
headNode = newNode;
}
else {
// Locate the node before insertion point
currNode = headNode;

while (currNode->GetNext() && currNode->GetNext()->GetBookISBN() < newNode->GetBookISBN()) {
currNode = currNode->GetNext();
}
currNode->insertAfter(newNode);
}

++counter;
return counter;
}

void LinkedListLibrary::PrintLibrary() const {
BookNode* currNode;

currNode = headNode->GetNext();
while (currNode != nullptr) {
currNode->PrintBookInfo();
cout << endl;
currNode = currNode->GetNext();
}
}

________________________________________________________________________

VectorLibrary.cpp

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

VectorLibrary::VectorLibrary() {
vector<Book> library;
}

int VectorLibrary::InsertSorted(const Book &newBook, int counter) {
Book currBook;

// Add an empty element at end of list
Book emptyBook;
library.push_back(emptyBook);

// Loop through elements starting at the end
for (int i = library.size() - 2; i >=0; --i) {
currBook = library.at(i);

// If the current book's ISBN is larger than newBook's ISBN, shift
// the current book down 1, count shift operation
if(currBook.GetBookISBN() > newBook.GetBookISBN()){
library.at(i + 1) = currBook;
++counter;
}

// Otherwise, place newBook at the next location (empty slot),
// count insert operation
else {
library.at(i + 1) = newBook;
++counter;
return counter;
}
}

// If we get to the top of the list, place newBook on top
library.at(0) = newBook;
++counter;
return counter;
}

void VectorLibrary::PrintLibrary() const {
for (size_t i = 0; i < library.size(); ++i) {
library.at(i).PrintInfo();
cout << endl;
}
}

_____________________________________________

BookNode.h

#ifndef BOOKNODEH
#define BOOKNODEH

#include <string>
using namespace std;

class BookNode {
public:
BookNode();

// Constructor
BookNode(string bookTitleInit, string bookAuthorInit, long bookISBNInit);

// Constructor
BookNode(string bookTitleInit, string bookAuthorInit, long bookISBNInit, BookNode* nextLoc);

// inserAfter
void insertAfter(BookNode* nodeLoc);
  
//setNext
void SetNext(BookNode* nodeLoc);

// Get location pointed by nextNodePtr
BookNode* GetNext() const;

long GetBookISBN() const;

// Print book information
void PrintBookInfo() const;

private:
string bookTitle;
string bookAuthor;
long bookISBN;
BookNode* nextNodePtr; // Reference to the next node
};
#endif

_________________________________________-

BookNode.cpp

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

BookNode::BookNode() {
bookTitle = "";
bookAuthor = "";
bookISBN = 0;
nextNodePtr = nullptr;
}

// Constructor
BookNode::BookNode(string bookTitleInit, string bookAuthorInit, long bookISBNInit) {
bookTitle = bookTitleInit;
bookAuthor = bookAuthorInit;
bookISBN = bookISBNInit;
nextNodePtr = nullptr;
}

// Constructor
BookNode::BookNode(string bookTitleInit, string bookAuthorInit, long bookISBNInit, BookNode* nextLoc) {
bookTitle = bookTitleInit;
bookAuthor = bookAuthorInit;
bookISBN = bookISBNInit;
nextNodePtr = nextLoc;
}
// insertAfter
void BookNode::insertAfter(BookNode* nodeLoc){
BookNode* tmpNext;

tmpNext = nextNodePtr;
nextNodePtr = nodeLoc;
nodeLoc->nextNodePtr = tmpNext;
}

// setNext
void BookNode::SetNext(BookNode* nodeLoc) {
nextNodePtr = nodeLoc;
}

// Get location pointed by nextNodePtr
BookNode* BookNode::GetNext() const{
return nextNodePtr;
}

long BookNode::GetBookISBN() const{
return bookISBN;
}

// Print book information
void BookNode::PrintBookInfo() const{
cout << "Title: " << bookTitle << endl;
cout << "Author: " << bookAuthor << endl;
cout << "ISBN: " << bookISBN << endl;
}

_______________________________________________

Book.h

#ifndef BOOKH
#define BOOKH

#include <string>
using namespace std;

class Book{
public:
Book();

Book(string userBookTitle, string userBookAuthor, long userBookISBN);

long GetBookISBN() const;

void PrintInfo() const;

private:
string bookTitle;
string bookAuthor;
long bookISBN;
};

#endif

_______________________________________________

Book.cpp

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

Book::Book() {
bookTitle = "";
bookAuthor = "";
bookISBN = 0;
}

Book::Book(string userBookTitle, string userBookAuthor, long userBookISBN) {
bookTitle = userBookTitle;
bookAuthor = userBookAuthor;
bookISBN = userBookISBN;
}

long Book::GetBookISBN() const{
return bookISBN;
}

void Book::PrintInfo() const{
cout << "Title: " << bookTitle << endl;
cout << "Author: " << bookAuthor << endl;
cout << "ISBN: " << bookISBN << endl;
}

In: Computer Science

Question 110 pts What are the contents of the queue bankLine after the following statements execute?...

Question 110 pts

What are the contents of the queue bankLine after the following statements execute? The front of the queue in the answers is the left-most value

QueueInterface<String> bankLine = newLinkedQueue<>();
bankLine .enqueue(“John”);
bankLine .enqueue(“Matthew”);
String next = bankLine .dequeue();
bankLine .enqueue(“Drew”);
bankLine .enqueue(“Heather”);
bankLine .enqueue(“David”);
next = bankLine .dequeue();

John, Drew, Heather
Heather, John, Drew
Drew, Heather, David
David, Heather, Drew

Flag this Question

Question 210 pts

What are the contents of the deque waitingLine after the following statements execute? The front of the queue in the answers is the left-most value

DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
String name = waitingLine.removeFront();

Larry, Sam, Jack
Rudy, Jack, Larry
Larry, Jack, Rudy
Jack, Larry, Sam

Flag this Question

Question 310 pts

How does a queue organize its items?

according to the order in which they were added
by priority
alphabetically
randomly

Flag this Question

Question 410 pts

The ADT priority queue organizes objects

according to the order in which they were added
by priority
alphabetically
none of the above

Flag this Question

Question 510 pts

What item is at the front of the list after these statements are executed?

DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
String name = waitingLine.getFront();

Jack
Rudy
Larry
Sam

Flag this Question

Question 610 pts

If we use a chain of linked nodes with only a head reference to implement a queue, which statement is true?

You must traverse the entire chain to access the last node.
Accessing the last node is very inefficient.
Both a and b
None of the above

Flag this Question

Question 710 pts

In the linked chain implementation of a queue, the chain’s first node contains

the queue’s front entry
the queue’s back entry
both a and b
none of the above

Flag this Question

Question 810 pts

In a linked chain implementation of a queue, the performance of the enqueue operation is

O(1)
O(log n)
O(n)
O(n^2)

Flag this Question

Question 910 pts

In a linked chain implementation of a queue, the performance of the getFront operation is

O(1)
O(log n)
O(n)
O(n^2)

Flag this Question

Question 1010 pts

In a circular array-based implementation of a queue, what is the performance when the enqueue operation must resize the array?

O(n^2)
O(n)
O(log n)
O(1)

In: Computer Science

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2

In: Computer Science

Considering Remote Data Acquisition The CEO of MegaCorp comes to see you on the advice of...

Considering Remote Data Acquisition

The CEO of MegaCorp comes to see you on the advice of the CIO who was impressed with your previous assistance to the organization. He and the other senior managers have been considering consolidation of all IT management activities either by moving them in-house at their corporate location or by outsourcing them to Berbee. He would like you to explain to him how these centralized staff would be capable of conducting investigations at the other sites that would not have local support and what the potential issues might be for those who have to conduct these remote investigations. Discuss what advice you would offer the CEO in terms of the pros and cons of centralizing staffing and the risks and benefits associated with remote data acquisition.

In: Computer Science

Write a program in python that reads the elements of a set from the keyboard, stores...

Write a program in python that reads the elements of a set from the keyboard, stores them in a set, and then determines its powerset. Specifically, the program should repeatedly ask the user:

Enter one more element ? [Y/N]

If the user answers Y then an new element is read from the keyboard:

Enter the new element in the set:

This cycle continues until the user answers N to the first question. At that point the program shall compute the powerset of the set of elements provided by the user, and print it to the screen. The powerset should not only be printed to the screen, but also stored in an instance of set.

Important: for what stated above, the elements of the powerset cannot be sets themselves. It is ok to store them in tuples. Note that while you can use a list to create a set (like in the example where we used list of chars), you cannot store lists in a set because of the same reason you cannot store sets inside a set. For example, the following code will give you an error

>>> A = [1,2] >>> B = [3,4] >>> C = [A,B] >>> D = set(C) 3 ---------------------------------------------------------------------------

TypeError Traceback (most recent call last) in ----> 1 D = set(C)

TypeError: unhashable type: ’list’

The reason is that D = set(C) tries to build a set of elements from the list C, and the elements of C are the lists A and B. On the contrary, E = set(A) would be ok, because it builds a set from the elements of A, and the elements of A are integers.

In: Computer Science

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2 Codes in C please.s

In: Computer Science

i need the graph also please . Consider the following jobs having I/0 wait of 70%...

i need the graph also please

. Consider the following jobs having I/0 wait of 70% with Arrival time and CPU minutes needed.

  

    

Jobs

Arrival Time

CPU minutes needed

1

13:10

8

2

13:30

6

3

13:40

4

4

13:50

4

5

13:55

3

1. Calculate CPU idle, CPU busy and CPU busy/ process

2. Draw a graph showing no. of jobs and when it completes

In: Computer Science

C language Modify the getAvg() function to support passing an array by reference. The parameters of...

C language

  1. Modify the getAvg() function to support passing an array by reference.
    • The parameters of this function should be pointer to a float array, and the size of the array.
    • Returns the average of the array.
  2. Build a function called getScoreFromUser() with the following properties:
    • Asks the user to enter the score
    • scans into a local float variable
    • returns the float value that the user entered.
  3. Build and present a menu to a user like the following and enclose it into a loop that ends when the Quit option is chosen. Insert a line with your favorite character before and after printing the menu.

    ***************************
    1. Enter user name.
    2. Enter scores.
    3. Display average score.
    4. Display summary.
    5. Quit
      ***************************
  4. For Option #1, scanf a string, and store it to a username char array.
  5. For Option #2, do the following :
    • Ask the user how many exams they have and store that value into an int variable.
    • Use a for loop in combination with getScoreFromUser() to get the user's scores.

      Hint: Declare a float array of size 20 to store the user's scores. If the user wants to enter more than the array size we declared, display an error, and have the user re-enter the test count. Some array members will be left un-used which is okay.

      Hint: You can use this inside your for loop: scores_array[i] = getScoreFromUser()
    • Use the getAvg() function to calculate the average of all the tests the user entered.
  6. For Option #3, do the following :
    • If the user has already entered test scores, display the average of all the test scores.
    • If the user has not yet entered test scores, display an error message similar to: "Please use the menu to enter test scores first."
  7. For Option #4, if the user has not yet entered their name and test scores, display an error message. Otherwise display the average, the letter grade of the average, and the user's name.

    Example: "Hello Charley, your test scores were 70, 75, 80, 85, 90, 95. Your average is 82.5 with letter grade: B."

    Hint: You can print "Hello Charley, your test scores were " first, and then use for loop to print thetest scores, followed by "Your average is 90.0 with letter grade: A."

In: Computer Science

hi i need to do a C++ program. You are going to practice the use of...

hi i need to do a C++ program.

You are going to practice the use of array by implementing the interface of Shuttle Puzzle.
Here is an example of how you play the Shuttle Puzzle.
Say that you start with a board with 7 holes and there are 3 black and 3 white marbles on the board in this configuration:
W W W . B B B
The dot (.) represents the empty hole withouth any marble.
The objective of the game is to switch the positions of the black and white marbles, i.e. the puzzle with former configuration should end when the board becomes:
B B B . W W W
You have only two types of moves. You can either

  • slide a marble 1 space (into the empty position), or
    For example, to slide the white (W) marble at index 2: W W W . B B BW W . W B B B
  • jump a marble over 1 and only 1 marble of the opposite color (again, into the empty position).
    For example, to jump the black (B) marble at index 4: W W . W B B BW W B W . B B

You CANNOT jump marbles over more than 1 position, and you CANNOT backtrack your moves (B can only be moved to left, and W can only be moved to right).
In this lab, we are implementing the basic version of the game with 1 empty hole only in between the black and white marbles.

Tasks

You need to use array to implement the interface of shuttle puzzle.

  • Your program should get 2 integers from the player which represent the number of white marbles (num_W) and black marbles (num_B) respectively.
  • The input of every move is an int (position) and a char (operation). You should move the marble at the position with the operation. The direction of this move depends on the color of the marble.
  • If the input position is -1, your program should print "Exit." and then the program ends and exits.
  • While the puzzle solver (player) playing with your program, your program should identify forbidden move, and print "Error!" to warn the puzzle solver.
  • When the puzzle is solved, your program should print "Congratulations!" and exit.

In our test cases, we assume that

  • num_W + num_B < 100, num_W > 0 and num_B > 0
  • the position (index) will be always in the range of [0, num_W + num_B]
  • the operation can only be 'J' (jump) or 'S' (slide)

You can start from skeleton. The skeleton has already divde the tasks into several functions. Feel free to start from scratch and write your own code as long as it implements the game.

For a puzzle with 2 white marbles and 2 black marbles:

Num of white and black marbles: 2 2
[01234]
WW.BB
Index (-1 to exit): 0
'J' or 'S': J
Error!
Index (-1 to exit): 1
'J' or 'S': S
[01234]
W.WBB
Index (-1 to exit): 3
'J' or 'S': J
[01234]
WBW.B
Index (-1 to exit): 4
'J' or 'S': S
[01234]
WBWB.
Index (-1 to exit): 2
'J' or 'S': J
[01234]
WB.BW
Index (-1 to exit): 0
'J' or 'S': J
[01234]
.BWBW
Index (-1 to exit): 1
'J' or 'S': S
[01234]
B.WBW
Index (-1 to exit): 3
'J' or 'S': J
[01234]
BBW.W
Index (-1 to exit): 2
'J' or 'S': S
[01234]
BB.WW
Congratulations!

For a puzzle with 2 white marbles and 3 black marbles:
>>>2 3
>>>3 S
>>>1 J
>>>0 S
>>>2 J
>>>4 J
>>>5 S
>>>3 J
>>>1 J
>>>2 S
>>>4 J
>>>3 S
<<<Congratulations!

'>>>' represents input and '<<<' represents output. We skip the ragular output in above case.

Your output should be exactly the same as the requirement.
You should NOT modify the output code in the skeleton, and you MUST clear all redundant ouput before submit.
You should submit merely 1 source code file.

Skeleton

#include <iostream>
using namespace std;

const int MAX_SIZE = 1000;

/*
 * (Given)
 * Print the current game board
 */
void print(const char board[], int valid_length)
{
    cout << " [";
    for (int i = 0; i < valid_length; ++i)
       cout << i;
    cout << "]" << endl;
    cout << "  ";
    for (int i = 0; i < valid_length; ++i)
       cout << board[i];
    cout << endl;
}

/*
 * Initialize the game board with white (W) marbles on the left and 
 * black (B) marbles on the right, and a gap in between
 * Returns the length of the puzzle, i.e. num_W + 1 + num_B
 */
int initialize(char board[], int num_W, int num_B)
{
    // TODO
}

/*
 * Jump a marble over 1 and only 1 marble of the opposite color into the empty position.
 * You CANNOT jump marbles over more than 1 position, and 
 * you CANNOT backtrack your moves (B can only be moved to left, and W can only be moved to right).
 *
 * Returns true if the jump is valid
 * otherwise, returns false
 */
bool jump(char board[], int length, int index)
{
    // TODO
}

/*
 * Slide a marble 1 space (into the empty position)
 * you CANNOT backtrack your moves (B can only be moved to left, and W can only be moved to right).
 *
 * Returns true if the slide is valid
 * otherwise, returns false
*/
bool slide(char board[], int length, int index)
{
    // TODO
}

/* 
 * Returns true if all black marbles are on the left and white marbles are on the right
 * otherwise, returns false 
 */
bool game_finished(const char board[], int num_W, int num_B)
{
    // TODO
}

int main()
{
    char board[MAX_SIZE] = {};
    int num_W, num_B;

    // Get the number of white (W) & black (B) marbles
    cout << "Num of white and black marbles: ";
    cin >> num_W >> num_B;

    // Initialize the board 
    int length = initialize(board, num_W, num_B);
    print(board, length);

    // Continue while not all marbles are switched
    while(!game_finished(board, num_W, num_B))
    {
        // Get the index (position) for the move (operation), -1 means give up the game
        int index;
        cout << "Index (-1 to exit): ";
        cin >> index;
        if(index == -1)
        {
            cout << "Exit." << endl;
            break;
        }

        // Get the operation, 'J' for jump or 'S' for slide
        char op;
        cout << "'J' or 'S': ";
        cin >> op;
        bool res = false;
        switch (op)
        {
        case 'J':
            res = jump(board, length, index);
            break;
        case 'S':
            res = slide(board, length, index);
            break;
        }
        if(!res)
            cout << "Error!" << endl;
        else 
            print(board, length);
    }

    if(game_finished(board, num_W, num_B))
    {
        cout << "Congratulations!" << endl;
    }

    return 0;
}

Test cases for students

We skip the regular output in the following cases.

Input:
2 2 3 S 1 J 0 S 2 J 4 J 3 S 1 J 2 S
Expected ouput:
Congratulations!

Input:
2 2 0 J 1 S 3 J 4 S 3 S 2 J 0 J 1 S 3 J 2 S
Expected ouput:
Error!
Error!
Congratulations!

Input:
2 2 0 J 1 S 3 J 4 S 3 S -1
Expected ouput:
Error!
Error!
Exit.

Input:
3 3 4 S 2 J 1 S 3 J 5 J 6 S 4 J 2 J 0 J 1 S 3 J 5 J 4 S 2 J 3 S
Expected ouput:
Congratulations!

Input:
4 4 5 S 3 J 2 S 4 J 6 J 7 S 5 J 3 J 1 J 0 S 2 J 4 J 6 J 8 J 7 S 5 J 3 J 1 J 2 S 4 J 6 J 5 S 3 J 4 S
Expected ouput:
Congratulations!

Input:
10 11 11 S 9 J 8 S 10 J 12 J 13 S 11 J 9 J 7 J 6 S 8 J 10 J 12 J 14 J 15 S 13 J 11 J 9 J 7 J 5 J 4 S 6 J 8 J 10 J 12 J 14 J 16 J 17 S 15 J 13 J 11 J 9 J 7 J 5 J 3 J 2 S 4 J 6 J 8 J 10 J 12 J 14 J 16 J 18 J 19 S 17 J 15 J 13 J 11 J 9 J 7 J 5 J 3 J 1 J 0 S 2 J 4 J 6 J 8 J 10 J 12 J 14 J 16 J 18 J 20 J 21 S 19 J 17 J 15 J 13 J 11 J 9 J 7 J 5 J 3 J 1 J 2 S 4 J 6 J 8 J 10 J 12 J 14 J 16 J 18 J 20 J 19 S 17 J 15 J 13 J 11 J 9 J 7 J 5 J 3 J 4 S 6 J 8 J 10 J 12 J 14 J 16 J 18 J 17 S 15 J 13 J 11 J 9 J 7 J 5 J 6 S 8 J 10 J 12 J 14 J 16 J 15 S 13 J 11 J 9 J 7 J 8 S 10 J 12 J 14 J 13 S 11 J 9 J 10 S 12 J 11 S
Expected ouput:
Congratulations!

In: Computer Science