Questions
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...

#include <stdio.h>

#include <math.h>

int fun(int);

int main(void)   

{

    int i = 5, x = 3;

    i = fun(x);

    printf("%d\n", i);

    return 0;

}

int fun(int i)

{

     int res = 0;

     res = pow (i , 3.0);

     return ( res);

}

In: Computer Science

Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the...

Python

#For question 1 and 2 you may not use ''' '''

Question 1 Print the messages below without using variables.

Output must be 2 lines identical to below:

What is the snake's favorite language?

"I love Python", said the snake.

Question 2 Write a python statements to match the 5 lines of output below.

Use a single print statement to produce the list of 4 languages

The 3 most popular programming languages of 2020 are:

1.         Python

2.         Javascript

3.         Java

4.         C#

-Source: https://www.northeastern.edu/graduate/blog/most-popular-programming-languages/

Question 3 (Multiple Choice)

lstrip and rstrip are examples of Python

(a)complex data types

(b)methods

(c)structures

(d)string variables

Question 4 (Multiple Choice)

What is true about Python variables?

(a)They are labels that can be assigned to values

(b)They reference a certain value

(c)A variable name cannot start with a number

(d)All of the above

In: Computer Science

My Name is Ahmad and here my Q Subject: Operating Systems Q1)Using access methods, write the...

My Name is Ahmad and here my Q

Subject: Operating Systems

Q1)Using access methods, write the commands to read location 3 if the position is currently at location 4.

a) Write the commands using sequential access method

b) Write the commands using direct access method

Note: ""Please use the keyboard to write the answer and i need a unique answer PLZ""

I APPRECIATE YOU'R HELP THANK YOU?

In: Computer Science

What is an n-tier architecture? Why do we need to use n-tier architecture? What is a...

  • What is an n-tier architecture? Why do we need to use n-tier architecture?
  • What is a service-oriented architecture? Provide an example of a service-oriented architecture.
  • Discuss the different architectural models for Database as a Service

In: Computer Science

Python Question 5 (Multiple Choice) msg1 = "My favorite number is " + str(fav_num) + "."...

Python

Question 5 (Multiple Choice)

msg1 = "My favorite number is " + str(fav_num) + "." msg2 = "My favorite number is "+str(fav_num)+"." Why would msg1 be preferred over msg2
(a)The user output is easier to read

(b)The code is easier to read. (c)Both a and b

Question 6

Given this list: pets = ['teddy', 'jessie', 'skippy'] Be sure to refer to the list element by its index Write the python statement whose output is: Hello SKIPPY; you are a fine parrot!

Note: print("Hello SKIPPY; you are a fine parrot!") is incorrect

Question 7

Using the list in Question 6
Write the python statement to add 'spot' to the list between 'teddy' and 'jessie'.

Question 8

Using the list updated in Question 7
Write the python statement to remove 'jessie' from the list.

In: Computer Science

C++ PLEASE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this program, you will analyze an array

C++ PLEASE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

In this program, you will analyze an array of 10 characters storing a gene sequence. You will be given a subsequence of 3 characters to look for within this array. If the subsequence is found, print the message:

Subsequence <XXX> found at index <i>.

Where i is the starting index of the subsequence in the array. Otherwise, print

Subsequence <XXX> not found.

The array of characters and the subsequence will be given through standard input. Read them and store them in arrays of characters of the right size. Do not use strings or vectors in this exercise.

You can assume the subsequence occurs at most once in the array.

Sample input 1:

AGTCAATGCA
TCA

Output:

Subsequence TCA found at index 2.

Sample input 2:

AGTCAATGCA
TAA

Output:

Subsequence TAA not found.

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

THANKS

In: Computer Science

Split the main function given into multiple functions. You have been given a very simple program...

  1. Split the main function given into multiple functions.

You have been given a very simple program that performs basic operations (addition, subtraction, editing) on two randomly generated integer vectors. All functionality has been included in main, causing code segments to be repeated as well as diminishing the readability.

Rewrite the program by grouping calculations and related operations into functions. In particular, your program should include the following functions.

  • InitializeVectors: This is a void function that initializes the two vectors by random numbers. Inside this function, the user will be prompted to enter the maximum random number. After the vectors have been populated with random numbers, print the vectors side by side. The parameters are the two arrays and their size.
  • EditVector: This is a void function that allows the user to update a value belonging to either vector. The user specifies the vector he wants to edit, the index he wants edit, and finally the updated value. The entire vector must then be printed on the screen. You need to pass the two arrays and their sizes.
  • CalculateAverage: This is a function that returns the average value in a vector. It returns a double and receives as parameters an array and its size.
  • printVector: A void function that takes a vector as a parameter along with its size, and prints it on the screen.

As you introduce each function, replace the code in main() by the appropriate function call. Also, keep in mind that for some functions, any changes that occur within the function body must also be visible in main. Finally, some functions can be called within other functions.

Remember that this program was already working. You should not alter the code, you just need to restructure it.

By the end of this assignment, the program’s structure and functionality will be more transparent, making it both easier and faster to understand.

Here is the code I need altered:

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int v_size = 0; //variable for the size of the arrays, its the same for both so that we can do addition and subtraction
    int v_id = 0;   //use it to determine which vector to operate on, used for average computation
    int ceiling = 0;    //when generating random numbers to place in vector, this constraints the maximum number attainable by the random number generator
    int action = 0; //determine which course of action the program will take
    double avg = 0.0;

    GetSize:
    cout<<"Enter size for vectors: ";
    cin>>v_size;

    if(cin.fail() == true)
    {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter vector size: ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto GetSize;
    }

    GetCeiling:
    cout<<"Enter Maximum Random Number for Vector: ";
    cin>>ceiling;

    if(cin.fail() == true)
    {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter Maximum Random Number: ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto GetCeiling;
    }

    int v1[v_size];
    int v2[v_size];

    int result[v_size];
    int run_sum =0;
    //randomly initialize the vectors
    srand (time(NULL));  //seed
    for(int i=0; i<v_size; i++)
    {
        v1[i]=rand() % ceiling;
        v2[i]=rand() % ceiling;
        cout<<setw(5)<<v1[i]<<setw(5)<<v2[i]<<endl;
    }

    GetAction:
    cout<<"Enter Action: vector addition(0), vector subtraction(1), average(2), edit(3), print vectors(4), clear screen(5), exit(-1): ";
    cin>>action;
    //system("CLS");
    if(cin.fail() == true || action<-1 || action>5)
    {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter Desired Action: ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto GetAction;
    }

    if(action == -1)
        goto end;

    if(action == 0)
    {
         for(int i=0; i<v_size; i++)
         {
             result[i]=v1[i]+v2[i];
             cout<<result[i]<<endl;
         }
    }

    else if(action == 1)
         for(int i=0; i<v_size; i++)
         {
             result[i]=v1[i]-v2[i];
             cout<<result[i]<<endl;
         }

    else if(action == 2)
    {
        getVector:
        cout<<"Average of Vector 1, or Vector 2 (Enter 1 or 2)? "<<endl;
        cin>>v_id;
        if(cin.fail() == true || (v_id!=1 && v_id!=2))
        {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter Vector Selection(1 or 2): ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto getVector;
        }
        if(v_id == 1 )
            for(int i=0; i<v_size; i++)
                run_sum += v1[i];

        else if(v_id == 2)
            for(int i=0; i<v_size; i++)
                run_sum += v2[i];

    avg = (double)run_sum/(double)v_size;
    cout<<"Average: "<<avg<<endl;
    run_sum = 0; //reset
    }

    else if(action == 3)
    {
        int index;
        GetVector:
        cout<<"Which Vector would you like to edit? (Enter 1 or 2): ";
        cin>>v_id;
        if(cin.fail() == true || (v_id!=1 && v_id!=2))
        {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter Vector Selection(1 or 2): ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto GetVector;
        }
        GetIndex:
        cout<<"Select Index to be Updated: "<<endl;
        cin>>index;
        if(cin.fail() == true || index<0 || index>(v_size+1))
        {
        system("CLS");
        cout<<"Invalid Input. Please Re-enter index to be updated: ";
        cin.clear();
        cin.ignore(10000, '\n');
        goto GetIndex;
        }
        cout<<"Enter updated value: ";
        if(v_id == 1)
        {
            cin>>v1[index];
            for(int i=0; i< v_size; i++)
                cout<<v1[i]<<endl;

        }

        else if(v_id == 2)
        {
             cin>>v2[index];
             for(int i=0; i< v_size; i++)
                cout<<v2[i]<<endl;
        }
    }
    if(action == 4)
         for(int i=0; i<v_size; i++)
             cout<<setw(5)<<v1[i]<<setw(5)<<v2[i]<<endl;


    if(action == 5)
        system("CLS");

    goto GetAction;
    end:
    return 0;
}

In: Computer Science

Modify the program so that after it reads the line typed on the keyboard, it replaces...

Modify the program so that after it reads the line typed on the keyboard, it replaces the ‘\n’ character with a NUL character. Now you have stored the input as a C-style string, and you can echo it with: Explain what you did.

#include <unistd.h>
#include <string.h>

int main(void)
{
  char aString[200];
  char *stringPtr = aString;

  write(STDOUT_FILENO, "Enter a text string: ",
        strlen("Enter a text string: "));  // prompt user

  read(STDIN_FILENO, stringPtr, 1);    // get first character
  while (*stringPtr != '\n')           // look for end of line
  {
    stringPtr++;                       // move to next location
    read(STDIN_FILENO, stringPtr, 1);  // get next character
  }

  // now echo for user
  write(STDOUT_FILENO, "You entered:\n",
        strlen("You entered:\n"));
  stringPtr = aString;
  do
  {
    write(STDOUT_FILENO, stringPtr, 1);
    stringPtr++;
  } while (*stringPtr != '\n');
  write(STDOUT_FILENO, stringPtr, 1);

  return 0;
}

In: Computer Science

what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back('...

what is the expected output of the following segment of code?

dq = Deque()
dq.push_back('M')
dq.push_back(' ')
l = ['A', 'L', 'E', 'S', 'T', 'E']
for i in l:
 if ord(i) % 3 == 0:
→ → dq.push_back(i)
elif ord(i) % 5 == 0:
→ → dq.push_front(i)
→ → dq.push_back(i)
elif ord(i) % 4 == 0:
→ → dq.push_back(i)
else:
→ → dq.peek_front()
→ → dq.push_front('X')
→ → dq.push_back('R')
dq.push_front(dq.peek_back())
dq.pop_back()
print(dq)

In: Computer Science

Question 17 Demonstrate your knowledge of if, elif and else: Create a variable gpa. Set it...

Question 17

Demonstrate your knowledge of if, elif and else:

Create a variable gpa. Set it to a number between 0 and 4.0

Write python statements which produce one line of output -just one of the below

You are a great student!

You are a good student!

You really need to study more!

You choose the thresholds between 0 and 4.0 which determine the outputs.

Question 18 (Multiple Choice)

pizza_toppings = []

if pizza_toppings:

(a)This evaluates to true because there is a variable pizza_toppings

(b)This evaluates to false because there is not a variable pizza_toppings

(c)This evaluates to true because the list contains the null element.

(d)This evaluates to false because the list is empty.

  Question 20

Write a list comprehension which will do the same work as the below 3 statements:

squares = []

for i in range(10):

     squares.append(i * i)

In: Computer Science

b. Implement StackFromList, a templated stack class backed by the above singlylinked list. The stack should...

b. Implement StackFromList, a templated stack class backed by the above singlylinked list. The stack should have a private linked list member, and utilize the linked list methods to implement its functionality. The stack should include a constructor, a destructor, a push, a pop, and an isEmpty method (which returns a bool).

c. Implement, QueueFromList, a templated queue class backed by the above singlylinked list. The queue should have a private linked list member, and utilize the linked list methods to implement its functionality. The queue should include a constructor, a destructor, an enqueue (insert to head), a deque (remove from tail), and an isEmpty method (which returns a bool).

LinkList.h:

#ifndef LinkedList_h
#define LinkedList_h

#include <iostream>

using namespace std;

template <class T = int>
class Node {
public:
   Node(); // default constructor
   Node(const T& data, Node<T>* next = nullptr); // donstructor
   T data; // node data
   Node<T>* next; // node next pointer
};

template <class T = int>
class LinkedList {
public:
   LinkedList(); // constructor
   ~LinkedList(); // destructor
   T deleteFromHead(); // removes and returns content of head
   T deleteFromTail(); // removes and returns content of tail
   void deleteNode(T data); // removes node with specified data
   void InsertToHead(T data); // insert node with data at the head
   void InsertToTail(T data); // insert node with data at the tail
   int getSize(); // returns size of linked list
   void print(); // prints linked list
private:
   Node<T>* head; // head of linked list
};


/******* From here down is the content of the LinkedList.cpp file: ***********************/

/* Implementation of Node */

// default constructor
template<class T>
Node<T>::Node()
{
}

// constructor
template<class T>
Node<T>::Node(const T& data, Node<T>* next)
{
   this->data = data;
   this->next = next;
}

/* Implementation of linked list */

// constructor
template <class T>
LinkedList<T>::LinkedList()
{
   head = nullptr;
}

// destructor
template <class T>
LinkedList<T>::~LinkedList()
{
   Node<T>* current = head;
   while (current != 0) {
       Node<T>* next = current->next;
       delete current;
       current = next;
   }
   head = nullptr;
}

template <class T>
T LinkedList<T>::deleteFromHead()
{
   T data;
   if (head != nullptr)
   {
       if (head->next == nullptr)
       {
           data = head->data;
           delete(head);
           head = nullptr;
           return data;
       }
       else
       {
           Node<T> *temp = head;
           data = temp->data;
           head = head->next;
       }
   }
   return data;
}


template <class T>
T LinkedList<T>::deleteFromTail()
{
   if (head == nullptr)
       return 0;
   if (head->next == nullptr)
   {
       T data = head->data;
       delete(head);
       head = nullptr;
       return data;
   }
   Node<T> *temp = head;
   while (temp->next->next != nullptr)
   {
       temp = temp->next;
   }
   T data = temp->next->data;

   // Delete last node
   delete (temp->next);

   // Change next of second last
   temp->next = nullptr;
   return data;
}


template <class T>
void LinkedList<T>::InsertToHead(T data)
{
   Node<T> * newNode = new Node<T>(data, nullptr);

   if (head == nullptr)
       head = newNode;
   else
   {
       newNode->next = head;
       head = newNode;
   }
}


template <class T>
void LinkedList<T>::InsertToTail(T data)
{
   Node<T> * newNode = new Node<T>(data, nullptr);

   if (head == nullptr)
       head = newNode;
   else
   {
       Node<T> *temp = head;
       while (temp->next != nullptr)
           temp = temp->next;
       temp->next = newNode;
   }

}


template <class T>
int LinkedList<T>::getSize()
{
   int size = 0;
   Node<T> *temp = head;
   while (temp != nullptr)
   {
       size++;
       temp = temp->next;
   }
   return size;
}
template <class T>
void LinkedList<T>::deleteNode(T data)
{
   if (head == nullptr)
       return;
   if (head->next == nullptr && head->data == data)
   {
       head->next = nullptr;
       return;
   }
   if (head->data == data)
   {
       head = head->next;
       return;
   }
   Node<T> *curr = head;
   Node<T> *prev = head;
   while (curr != nullptr)
   {
       if (curr->data == data)
       {
           break;
       }
       prev = curr;
       curr = curr->next;
   }
   if (curr == nullptr)
       return;
   if (curr->next == nullptr)
   {
       prev->next = nullptr;
       delete curr;
       return;
   }
   prev->next = curr->next;
}

template <class T>
void LinkedList<T>::print()
{
   if (head == nullptr)
   {
       cout << "Linked list is empty" << endl;;
       return;
   }

   cout << head->data << " ";

   if (head->next == nullptr)
   {
       cout << endl;
       return;
   }

   Node<T>* currNode = head->next;
   Node<T>* prevNode = head;


   while (currNode->next != nullptr)
   {
       cout << currNode->data << " ";
       prevNode = currNode;
       currNode = currNode->next;
   }

   cout << currNode->data << endl;
   return;
}


#endif

main.cpp:

//
//  main.cpp
//
//  Copyright 穢 Tali Moreshet. All rights reserved.
//

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

using namespace std;

int main(int argc, const char * argv[]) {
    
    /*** For part (b): Testing of stack: ***/
    cout << endl << endl << "*** Int stack: ***" << endl;
    StackFromList<int> intStack;

    cout << "Pushing to the stack: 1 2 3 4" << endl;

    intStack.push(1);
    intStack.push(2);
    intStack.push(3);
    intStack.push(4);

    cout << "The top of the stack was " << intStack.pop() << endl;
    cout << "The top of the stack was " << intStack.pop() << endl;

    cout << "Pushing to the stack: 5 6" << endl;

    intStack.push(5);
    intStack.push(6);

    cout << "The stack is ";
    if (!intStack.isEmpty())
        cout << "not ";
    cout << "empty" << endl;

    cout << "The top of the stack was " << intStack.pop() << endl;
    cout << "The top of the stack was " << intStack.pop() << endl;
    cout << "The top of the stack was " << intStack.pop() << endl;
    cout << "The top of the stack was " << intStack.pop() << endl;

    cout << "The stack is ";
    if (!intStack.isEmpty())
        cout << "not ";
    cout << "empty" << endl;


    /*** For part (c): Testing of queue: ***/
    cout << endl << endl << "*** Char queue: ***" << endl;
    QueueFromList<char> charQueue;

    cout << "Enqueueing to the queue: a b c d" << endl;

    charQueue.enqueue('a');
    charQueue.enqueue('b');
    charQueue.enqueue('c');
    charQueue.enqueue('d');

    cout << "The head of the queue was " << charQueue.dequeue() << endl;
    cout << "The head of the queue was " << charQueue.dequeue() << endl;

    cout << "Enqueueing to the queue: e" << endl;

    charQueue.enqueue('e');

    cout << "The queue is ";
    if (!charQueue.isEmpty())
        cout << "not ";
    cout << "empty" << endl;

    cout << "The head of the queue was " << charQueue.dequeue() << endl;
    cout << "The head of the queue was " << charQueue.dequeue() << endl;
    cout << "The head of the queue was " << charQueue.dequeue() << endl;

    cout << "The queue is ";
    if (!charQueue.isEmpty())
        cout << "not ";
    cout << "empty" << endl;


    return 0;
}

In: Computer Science

Write a java program that creates a hashtable with 10 objects and 5 data members using...

Write a java program that creates a hashtable with 10 objects and 5 data members using mutator and accessor methods for each data member.

In: Computer Science

Describe the following access networks connected to your home: DSL, HFC, and FTTH.What are the advantages...

Describe the following access networks connected to your home: DSL, HFC, and FTTH.What are the advantages and dis-advantages of each?

In: Computer Science

An excellent example of a program that can be greatly simplified by the use of recursion...

An excellent example of a program that can be greatly simplified by the use of recursion is the Chapter 4 case study, escaping a maze. As already explained, in each maze cell the mouse stores on the maze stack up to four cells neighboring the cell in which it is currently located. The cells put on the stack are the ones that should be investigated after reaching a dead end. It does the same for each visited cell. Write a program that uses recursion to solve the maze problem. Use the following pseudocode:

exitCell(currentCell)

if currentCell is the exit

  success;

  else exitCell(the passage above currentCell);

  exitCell(the passage below currentCell);

exitCell(the passage left to currentCell);

  exitCell(the passage right to currentCell);

Here is the code from the Chapter 4 Case Study:

#include <iostream>

#include <string>

#include <stack>

using namespace std;

template<class T>

class Stack : public stack<T> {

public:

T pop() {

T tmp = top();

stack<T>::pop();

return tmp;

}

};

class Cell {

public:

Cell(int i = 0, int j = 0) {

x = i; y = j;

}

bool operator== (const Cell& c) const {

return x == c.x && y == c.y;

}

private:

int x, y;

friend class Maze;

};

class Maze {

public:

Maze();

void exitMaze();

private:

Cell currentCell, exitCell, entryCell;

const char exitMarker, entryMarker, visited, passage, wall;

Stack<Cell> mazeStack;

char **store; // array of strings;

void pushUnvisited(int,int);

int rows, cols;

friend ostream& operator<< (ostream& out, const Maze& maze) {

for (int row = 0; row <= maze.rows+1; row++)

out << maze.store[row] << endl;

out << endl;

return out;

}

};

Maze::Maze() : exitMarker('e'), entryMarker('m'), visited('.'),

passage('0'), wall('1') {

Stack<char*> mazeRows;

char str[80], *s;

int col, row = 0;

cout << "Enter a rectangular maze using the following "

<< "characters:\nm - entry\ne - exit\n1 - wall\n0 - passage\n"

<< "Enter one line at at time; end with Ctrl-z:\n";

while (cin >> str) {

row++;

cols = strlen(str);

s = new char[cols+3]; // two more cells for borderline columns;

mazeRows.push(s);

strcpy(s+1,str);

s[0] = s[cols+1] = wall; // fill the borderline cells with 1s;

s[cols+2] = '\0';

if (strchr(s,exitMarker) != 0) {

exitCell.x = row;

exitCell.y = strchr(s,exitMarker) - s;

}

if (strchr(s,entryMarker) != 0) {

entryCell.x = row;

entryCell.y = strchr(s,entryMarker) - s;

}

}

rows = row;

store = new char*[rows+2]; // create a 1D array of pointers;

store[0] = new char[cols+3]; // a borderline row;

for ( ; !mazeRows.empty(); row--) {

store[row] = mazeRows.pop();

}

store[rows+1] = new char[cols+3]; // another borderline row;

store[0][cols+2] = store[rows+1][cols+2] = '\0';

for (col = 0; col <= cols+1; col++) {

store[0][col] = wall; // fill the borderline rows with 1s;

store[rows+1][col] = wall;

}

}

void Maze::pushUnvisited(int row, int col) {

if (store[row][col] == passage || store[row][col] == exitMarker) {

mazeStack.push(Cell(row,col));

}

}

void Maze::exitMaze() {

int row, col;

currentCell = entryCell;

while (!(currentCell == exitCell)) {

row = currentCell.x;

col = currentCell.y;

cout << *this; // print a snapshot;

if (!(currentCell == entryCell))

store[row][col] = visited;

pushUnvisited(row-1,col);

pushUnvisited(row+1,col);

pushUnvisited(row,col-1);

pushUnvisited(row,col+1);

if (mazeStack.empty()) {

cout << *this;

cout << "Failure\n";

return;

}

else currentCell = mazeStack.pop();

}

cout << *this;

cout << "Success\n";

}

int main() {

Maze().exitMaze();

return 0;

In: Computer Science

. In this exercise we will evaluate the performance difference between two CPU architectures: CISC (Complex...

. In this exercise we will evaluate the performance difference between two CPU architectures: CISC (Complex Instruction Set Computing) and RISC (Reduced Instruction Set Computing). Generally speaking, CISC CPUs have more complex instructions than RISC CPUs and therefore need fewer instructions to perform the same tasks. However, typically one CISC instruction, since it is more complex, takes more time to complete than a RISC instruction. Assume that a certain task needs P CISC instructions and 2P RISC instructions, and that one CISC instruction takes 8T ns to complete, and one RISC instruction take 2T ns.

a: Under this assumption, calculate the time that the CISC CPU will take to complete the task?

b: Calculate the time that the RISC CPU will take to complete the task?

c: Which CPU would complete the task faster?

d: By what percentage should the clock frequency of the slower CPU change to catch up with the faster CPU for this task?

In: Computer Science