Questions
the goal is for you to develop an approach that improves up on the array-based implementation...

the goal is for you to develop an approach that improves up on the array-based implementation in some way.For example, perhaps you want to take an approach that avoids the cost of re-allocating the array when it's full,e.g. using a linked-list. Of course, with a linked-list the cost of accessing an element will jump from O(1) to O(N), so that’s a costly trade-off. Perhaps you can think of a better approach that avoids the cost of reallocating the array, while retaining O(1) access to any element in most cases? In short, think of ways to break your myvector class, and write code to make sure your vector class works as required.

you are also required to add three additional functions to your myvector class, as defined below:

// // erase

// // erase the element at position i from the vector by overwriting it and

// reducing the size (# of elements); the ith element is returned //

// Assume: 0 <= i < Size // T erase(int i);

// // [] // // returns a reference to the element at position i so the element can

// be read or written //

// Assume: 0 <= i < Size //

T erase(int i);

T& operator[ ](int i);

// // [] //

// returns a reference to the element at position i so the element can

// be read or written //

// Assume: 0 <= i < Size

T* rangeof(int i, int j)

// // rangeof // // Returns the elements in the range of positions i..j, inclusive. // The elements are returned in a dynamically-allocated C-style array. // // Example: if i is 2 and j is 4, then an array containing 3 // elements is returned: element position 2, element position 3, and // element position 4. // // Assume: 0 <= i <= j < Size //

Do not add a destructor

use pointers in some way, above and beyond a single pointer to a dynamicallyallocated array. A simple one or two-way linked-list is a valid approach, but will not receive full credit.

Do not use any of the built-in containers of C++ (e.g. do not use std::vector to implement myvector)

main.cpp and function.cpp are read only function

myvector.h is a todo function

main.cpp

//
// Project #01: input movie review data from a file, and output moviename, # of
// reviews, average review, and # of reviews per star.
//
// File example "movie1.txt":
// Finding Nemo
// 5
// 4
// 5
// 4
// 5
// -1
//
// Output:
// Movie: Finding Nemo
// Num reviews: 5
// Avg review: 4.6
// 5 stars: 3
// 4 stars: 2
// 3 stars: 0
// 2 stars: 0
// 1 star: 0
//

#include <iostream>
#include <fstream>
#include <string>

#include "myvector.h"

using namespace std;

// functions from student.cpp:
myvector<int> InputData(string filename, string& moviename);
double GetAverage(myvector<int> reviews);
myvector<int> GetNumStars(myvector<int> reviews);

int main()
{
myvector<int> reviews;
myvector<int> numstars;
double avg;
string filename, moviename;

//
// 1. input filename and then the review data:
//
cin >> filename;

reviews = InputData(filename, moviename);

cout << "Movie: " << moviename << endl;
cout << "Num reviews: " << reviews.size() << endl;

//
// 2. average review
//
avg = GetAverage(reviews);
cout << "Avg review: " << avg << endl;

//
// 3. # of 5 stars, 4 stars, etc
//
numstars = GetNumStars(reviews);

for (int i = numstars.size(); i > 0; --i)
{
//
// i is 5, 4, 3, 2, 1:
//
if (i == 1)
cout << i << " star: " << numstars.at(i - 1) << endl;
else
cout << i << " stars: " << numstars.at(i - 1) << endl;
}

return 0;
}

functions.cpp

//
// Project #01: input movie review data from a file, and output moviename, # of
// reviews, average review, and # of reviews per star.
//

#include <iostream>
#include <fstream>
#include <string>

#include "myvector.h"

using namespace std;

//
// InputData
//
// Inputs the movie data from the given file, returning the moviename
// (via the parameter) and the individual reviews (via the returned
// vector). The reviews are ratings in the range 1..5.
//
// File format: the first line is the moviename. The name is followed
// by N > 0 reviews, one per line; each review is a value in the range
// 1-5. The last review is followed by a sentinel value (0 or negative)
// which is discarded.
//
// File example "movie1.txt":
// Finding Nemo
// 5
// 4
// 5
// 4
// 5
// -1
//
myvector<int> InputData(string filename, string& moviename)
{
myvector<int> V;
ifstream file(filename);
int x;

if (!file.good())
{
cout << "**Error: unable to open '" << filename << "'." << endl;
return V; // empty vector:
}

getline(file, moviename);

//
// input and store all reviews until sentinel is
// reached (0 or negative):
//
file >> x;

while (x > 0)
{
V.push_back(x);

file >> x; // next value:
}

// done, return vector of reviews:
return V;
}

//
// GetAverage
//
// Returns the average of the values in the vector; if the vector
// is empty then 0.0 is returned.
//
double GetAverage(myvector<int> V)
{
double sum = 0.0;
double avg;

for (int i = 0; i < V.size(); ++i)
{
sum += V.at(i);
}

if (V.size() == 0) // beware of divide-by-0:
avg = 0.0;
else
avg = sum / static_cast<double>(V.size());

return avg;
}

//
// GetNumStars
//
// Given a vector of reviews --- each review in the range 1-5 --- returns
// a vector of counts denoting the # of reviews of each rating. In other
// words, if we think of the reviews as "stars", the function returns a
// vector of 5 counts in this order: # of reviews of 1 star, # of reviews of
// 2 stars, ..., # of reviews of 5 stars.
//
// Example: suppose reviews contains the reviews 1, 5, 5, 2, 1, 4, 5. Then
// the function returns a vector containing 5 counts: 2, 1, 0, 1, 3.
//
myvector<int> GetNumStars(myvector<int> reviews)
{
myvector<int> numstars(5); // 1, 2, 3, 4, 5 stars

// let's make sure all the counts are initialized to 0:
for (int i = 0; i < numstars.size(); ++i)
{
numstars.at(i) = 0;
}

//
// for each review, increase count for that particular star (1-5):
//
for (int i = 0; i < reviews.size(); ++i)
{
int star = reviews.at(i); // 1-5:

numstars.at(star - 1)++; // index 0-4:
}

// return counts:
return numstars;
}

myvector.h

// Project #01: myvector class that mimics std::vector, but with my own
// implemenation outlined as follows:
//
// ???
//

#pragma once

#include <iostream> // print debugging
#include <cstdlib> // malloc, free

using namespace std;

template<typename T>
class myvector
{
private:
T* A;
int Size;
int Capacity;

public:
// default constructor:
myvector()
{
Size = 0;

Capacity = 1000;

A = new T[Capacity];
}

// constructor with initial size:
myvector(int initial_size)
{
Capacity = initial_size;

Size = initial_size;

A = new T[Capacity];
}

// copy constructor for parameter passing:
myvector(const myvector& other)
{
//
// we have to make a copy of the "other" vector, so...
//
A = new T[other.Capacity]; // allocate our own array of same capacity
Size = other.Size; // this vector is same size and capacity
Capacity = other.Capacity;

// make a copy of the elements into this vector:
for (int i = 0; i < Size; ++i)
A[i] = other.A[i];
}

int size()
{
//
//
//
return Size;
}

T& at(int i)
{
//
//
//
return A[i]; // this is WRONG, but compiles
}

void push_back(T value)
{
if (Size >= Capacity) {

int *temp = new int[2 * Capacity];

for (int i = 0; i < Size; i++)

temp[i] = A[i];

A = temp;

}

A[Size] = value;

Size++;
}

};

If you find better methods to improve the "myvector.h" you can try to update it but it still needs to be a template and I need it to have the erase, operator, and rangeof function in the file.

In: Computer Science

#include "pch.h" #include <iostream> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() {        FILE...

#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
       FILE *fp;
       char c;

       errno_t err;
       err = 0;
       err = fopen_s(&fp,"Desktop/test.txt", "r"); file is on my desktop but I err=2 but I don't think it is opening the file?
       printf("%d\n", err);
       if (err == 2)
       {
           printf("The file was opened\n");
           while (1)
           {
               c = fgetc(fp) ?? Getting error when I try to read a file.;
               if (c == EOF)
               {
                   break;
               }
               printf("%c", c);
           }
       }
       else
       {
           printf("The file was not opened\n");

       }
       fclose(fp);

       return(0);
}

In: Computer Science

develop a methodology for parallelized data wrangling, listing the appropriate techniques and the order they should...

develop a methodology for parallelized data wrangling, listing the appropriate techniques and the order they should be conducted.

In: Computer Science

1.Since all projects are different, how can you determine what should be included in the project...

1.Since all projects are different, how can you determine what should be included in the project concept and project plan?

minimum - 150-200 words please

In: Computer Science

The Open Systems Interconnection (OSI) Layer 3 (Network Layer) is one   of the layers that performs...

The Open Systems Interconnection (OSI) Layer 3 (Network Layer) is one   of the layers that performs packet segmentation. The OSI Layer 3 is   roughly equivalent to the Internet Layer of the Transmission Control   Protocol/Internet Protocol (TCP/IP) model, and Layer 4 (Transport Layer) of the OSI model is roughly equivalent to the Host-to-Host layer of the TCP/IP model. The above two layers perform network segmentation. Based on the above information, answer the following questions:

  • Describe in detail how packets are segmented by the Host-to-Host   Layer (Transport Layer) and Internet Layer of the TCP/IP model.
  • Do all packets arrive at their destination in the order in which they were segmented and transmitted? Why or why not?
  • Describe how segmented packets are rearranged or reassembled at   the packets' destination to ensure that received segmented packets   match the order in which they were segmented and transmitted.
  • How are errors handled during transmission of segmented packets?
  • What is the difference between a TCP segment and an IP packet?

Please answer the above questions to write your paper of 4–5 pages

In: Computer Science

5 How Many Stacks? An NFA has no stack. It recognizes regular languages. A PDA is...

5 How Many Stacks?

An NFA has no stack. It recognizes regular languages.

A PDA is defined as an NFA with one stack. It recognizes context-free languages.

Prove that a PDA with two stacks recognizes Turing-recognizable languages

In: Computer Science

Please Complete this C Code using the gcc compiler. Please include comments to explain each added...

Please Complete this C Code using the gcc compiler. Please include comments to explain each added line.

/*This program computes the Intersection over Union of two rectangles
as a percent:

IoU = [Area(Intersection of R1 and R2) * 100 ] / [Area(R1) + Area(R2) - Area(Intersection of R1 and R2)]

The answer will be specified as a percent: a number between 0 and 100.
For example, if the rectangles do not overlap, IoU = 0%. If they are
at the same location and are the same height and width, IoU = 100%.
If they are the same area 30 and their area of overlap is 10, IoU =
20%.

Input: two bounding boxes, each specified as {Tx, Ty, Bx, By), where
   (Tx, Ty) is the upper left corner point and
   (Bx, By) is the lower right corner point.
These are given in two global arrays R1 and R2.
Output: IoU (an integer, 0 <= IoU < 100).

In images, the origin (0,0) is located at the left uppermost pixel,
x increases to the right and y increases downward.
So in our bounding box representation, it will always be true that:
Tx < Bx and Ty < By.

Assume images are 640x480 and bounding boxes fit within these bounds and
are always of size at least 1x1.

IoU should be specified as an integer (only the whole part of the division),
i.e., round down to the nearest whole number between 0 and 100 inclusive.

FOR FULL CREDIT (on all assignments in this class), BE SURE TO TRY
MULTIPLE TEST CASES and DOCUMENT YOUR CODE.
*/

#include
#include

//DO NOT change the following declaration (you may change the initial value).
// Bounding box: {Tx, Ty, Bx, By}
int R1[] = {64, 51, 205, 410};
int R2[] = {64, 51, 205, 410};
int IoU;

/*
For the grading scripts to run correctly, the above declarations
must be the first lines of code in this file (for this homework
assignment only). Under penalty of grade point loss, do not change
these lines, except to replace the initial values while you are testing
your code.

Also, do not include any additional libraries.
*/

int main() {

// insert your code here

IoU = -999; // Remove this line. (It's only provided so that shell code compiles w/out warnings.)

printf("Intersection over Union: %d%%\n", IoU);
return 0;
}

In: Computer Science

IN PYTHON 1) Pig Latin Write a function called igpay(word) that takes in a string word...

IN PYTHON

1) Pig Latin

Write a function called igpay(word) that takes in a string word representing a word in English, and returns the word translated into Pig Latin. Pig Latin is a “language” in which English words are translated according to the following rules:

  • For any word that begins with one or more consonants: move the consonants to the end of the word and append the string ‘ay’.

  • For all other words, append the string ‘way’ to the end.

  • For the above you can assume that ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ are vowels, and any other letter is a consonant. This does mean that ‘y’ is considered a consonant even in situations where it really shouldn’t be.

For this exercise, you can assume the following:

  • There will be no punctuation.

  • All letters will be lowercase

  • Every word will have at least one vowel (so we won’t give you a word like “by”)

Write a helper function that finds the index of the first vowel in a given word, and use that in your main function.

Hints:

  • To find the index of the first vowel in a given word, since you’re interested in the indexes, looping through the indexes of the string using range, or enumerate, or a while loop may work better than a direct for loop on the characters.

  • Use slicing to break up the string into all of the letters before the vowel, and all of the letters from the vowel onwards.

Examples:

>>> igpay('can')

'ancay'

>>> igpay('answer')

'answerway'

>>> igpay('prepare')

'eparepray'

>>> igpay('synthesis')

'esissynthay'

In: Computer Science

upload cvs file dialog it's sub menu bar and when I click this I want to...

upload cvs file dialog

it's sub menu bar and when I click this I want to popup file dialog and select cvs file

<a href="#" id="loadCSV">Load CSV file</a>

In: Computer Science

The human resources department for your company needs a program that will determine how much to...

The human resources department for your company needs a program that will determine how much to deduct from an employee’s paycheck to cover healthcare costs. Health care deductions are based on several factors. All employees are charged at flat rate of $150 to be enrolled in the company healthcare system. If they are married there is an additional charge of $75 to cover their spouse/partner. If they have children, the cost is $50 per child. In addition, all employees are given a 10% deduction in the total cost if they have declared to be a “non-smoker”.

Your goal is to create a program that gathers the employee’s name, marital status, number of children and whether or not they smoke tobacco for a single employee. While gathering this information, if the user enters at least one invalid value, the program must display one error message telling the user they made a mistake and that they should re-run the program to try again. The program must then end at this point. However, if all valid values are entered, the program should calculate the total cost of the healthcare payroll deduction and then print a well-formatted report that shows the employee’s name, marital status, total number of children, and smoker designation, and total deduction amount.

Please write a pseudocode for the above problem. Don't forget to validate the inputs as necessary.

In: Computer Science

irst, you will complete a class called HazMath (in the HazMath.java file) that implements the interface...

irst, you will complete a class called HazMath (in the HazMath.java file) that implements the interface Mathematical (in the Mathematical.java file). These should have the following definitions:

  • public boolean isPrime(int n)

    You cannot change the signature for the method. This method is similar to the ones we've discussed in the lab and will return true or false depending on if the passed in integer values is prime or not, respectively. Return false if the invoker passes in a number less than 1. A prime number is one that is not evenly divisible by any other number. For example, if we have number 2, it should return True, and if we have number 55, it will return False. Some sample assertions (Note that for these assertions we've not added a. message, which is optional):

    assert isPrime(2);
    assert isPrime(53);
    assert !isPrime(55);
    assert !isPrime(24);
    assert !isPrime(-37337);
    

    Prime numbers form the basis of cryptography! Read into why this is a little bit. Really cool stuff.

  • public int sumOfSums(int n)
    You cannot change the signature for the method. This method takes an integer, n, and computes the sum of each of the sums of each integer between 1 and n. For example, the sum of the sums of 3 is (1) + (1 + 2) + (1 + 2 + 3) = 10. Some sample assertions:
    assert sumOfSums(1) == 1;
    assert sumOfSums(3) == 10;
    assert sumOfSums(6) == 56;
    assert sumOfSums(25) == 2925;
    assert sumOfSums(-5) == 0;
    

This is first program:

public class HazMath implements Mathematical {

// Fill-in methods to implement the Mathematical interface
   public boolean isPrime(int n)
{

       return false;
   }

   public int sumOfSums(int n) {
      
       return 0;
   }

    public static void main(String[] args)
{
HazMath HM=new HazMath();
       assert HM.isPrime(3);
       assert !HM.isPrime(-37337);
       assert HM.sumOfSums(1) == 1;
       assert HM.sumOfSums(-5) == 0;
System.out.println("All tests passed. VICTORY!");

   }
}

This is the second program:

import java.lang.*;

public interface Mathematical
{
// Validate each Char
public boolean isPrime(int n);

// Validate each Char in row with size 3
public int sumOfSums(int n);

}

In: Computer Science

Given the following set of keys: {1, 2, 3} determine the number of distinct left-leaning red-black...

Given the following set of keys: {1, 2, 3} determine the number of distinct left-leaning red-black trees that can be constructed with those keys. Draw the tree for each possible key-insertion order, showing the transformations involved at each step.

In: Computer Science

Which of the following is TRUE about horizontal data merges using R? (Multiple answers can be...

Which of the following is TRUE about horizontal data merges using R? (Multiple answers can be selected)

a) Both data frames must have the same number of columns

b) Both data frames must have the same number of rows

c) The data frames must have at least one column with values in common

d) The data frames must have at least one column with the same name

e) Both data frames must have the same order of columns from left to right

In: Computer Science

i want Solution From Question Number 5 Solution Of questions 1-4 in Previou Post Note (I...

i want Solution From Question Number 5 Solution Of questions 1-4 in Previou Post
Note (I Want ScreenShot For Solution)

Use Kali Linux Commands to show me the following:
1. Who are you?
2. Change directory to Downloads
3. Make a new directory
4. Make a new text file under your name (Ghada.txt)
5. Write a paragraph about Cyber security (4 to 5 sentences) >>simply open the file and write
inside it
6. Change the permission to be 764
7. Open the file but with a cyber security match Show me each and every step with figure
b. Enter into Portswagger lab (Username enumeration via subtly different responses)

https://portswigger.net/web-security/authentication/password-based/lab-username-enumerationvia-subtly-different-responses
Show me step-by-step how to use burp to get the username and password. Name the username list

with your name ex. Ghada_usename.txt and Ghada_password.txt
Use Seed Machine (the same SQL injection website)to conduct SQL Injection such that:
1. Update Boby nickname to be your name (by Alice)
2. Update Boby password to be (your name as a password) (by Alice).

In: Computer Science

(1) a. sentence generation The sentence you need to generate is shown below: Sentence: John fed...

(1) a. sentence generation

The sentence you need to generate is shown below:

Sentence: John fed a bear in the park.

In this question, you should start from the target structure, a sentence (= S). Then you expand S by applying the rule S --> S PP. There is another rule that can expand S, namely S --> NP VP. However, if you apply S --> NP VP before S --> S PP, you will not be able to include PP. Therefore, S --> S PP is the correct rule to apply first, as has been given in the table below (together with two other steps). Remember to insert the lexical items when you get to a leaf node like D or N where no rule can be further applied. If your answers are correct, then all the 14 blanks should be filled.

The rules and lexicon that you need to generate the sentence are given as below:

Rules:

S --> NP VP
NP --> D NP
VP --> V PP
VP --> V NP
S --> S PP
PP --> P NP
AdjP --> Adv Adj
NP --> N
CP --> C S
Lexicon:

V --> saw, kicked, fed

P --> in, at

D --> a, the

N --> John, bear, park

You will need only a subset of the rules for this question.

Step

Sentence generating process

0 S

1 S --> S PP

2 S --> NP VP

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

Done!

(1)   b. Expand the rules and lexicon

What do you need to add to the previous rules and lexicon if you want to generate the following sentence:

The boy saw a brown bear in the park.

New rule(s) that needs to be added:

____________________

New lexical item(s) that needs to be added:
_____________________
______________________

In: Computer Science