Questions
Although pass-by-reference can be used to substitute all pass-by-value functions, why is pass-by-value be considered safer?...

  1. Although pass-by-reference can be used to substitute all pass-by-value functions, why is pass-by-value be considered safer?
  2. When passing an integer array to a function, why do you also need to pass the number of elements in that array?

In: Computer Science

each one of the following languages defined over {0,1}, give the transition diagram of a deterministic,...

each one of the following languages defined over {0,1}, give the transition diagram of a deterministic, single tape Turing Machine.

{03i 1 02i 1 0i | i > 0}

In: Computer Science

Provided that c1, c2 and c3 are of appropriate ranges. Use transform() algorithm so that it...

Provided that c1, c2 and c3 are of appropriate ranges. Use transform() algorithm so that it copies the larger of the corresponding elements from c1 and c2 to c3. That is, if

   c1 = {1, 2, 3, 4, 5} and   c2 = {5, 4, 3, 2, 1}

   then c3 should become c3={5, 4, 3, 4, 5}

In: Computer Science

name two differences in Chappe's and mMorse's inventions

name two differences in Chappe's and mMorse's inventions

In: Computer Science

C++ Lexicographical Sorting Given a file of unsorted words with mixed case: read the entries in...

C++ Lexicographical Sorting

Given a file of unsorted words with mixed case: read the entries in the file and sort those words lexicographically. The program should then prompt the user for an index, and display the word at that index. Since you must store the entire list in an array, you will need to know the length. The "List of 1000 Mixed Case Words" contains 1000 words.

You are guaranteed that the words in the array are unique, so you don't have to worry about the order of, say, "bat" and "Bat."

For example, if the array contains ten words and the contents are

cat Rat bat Mat SAT Vat Hat pat TAT eat

after sorting, the word at index 6 is Rat

You are encouraged to use this data to test your program.

In: Computer Science

This is a c++ code. Write a series of assignment statements (complete executable code) that find...

This is a c++ code. Write a series of assignment statements (complete executable code) that find the first three positions of the string “and” in a string variable sentence. The positions should be stored in int variables called first, second and third. You may declare additional variables if necessary. The contents of sentence should remain unchanged. The sentence can be completely random.

Im having a large problem with this. It's a simple c++ code, but im unable to get it. Thank you.

In: Computer Science

Please write JavaScript and HTML code for the following problems Problem 1 - Array Usage Ask...

Please write JavaScript and HTML code for the following problems

Problem 1 - Array Usage

Ask the user to enter positive numeric values. Store each value in an array. Stop reading values when the user enters -1. After all values have been entered, calculate the sum and the average of the values in the array (if you do not know what a sum or average is, or how to calculate them, it is your responsibility to look up this information). Print out the values entered by the user, the sum of those values, and the average value.

You must create one function that calculates the sum of the values in the array and one function that calculates the average of the values in the array.

  • Your sum function should take one parameter (an array) and return the sum
  • Your average function should take one parameter (an array) and return the average

Problem 2 - Circles

For this problem, you will create a simple HTML page that allows the user to draw circles by clicking inside of a canvas element.

The HTML page shall contain a title, a header, two text fields, and a canvas. The title shall include your name. The header shall contain the text "Problem 2". The first text field shall have a label indicating that the field controls the number of circles that will be drawn. The second text field shall have a label indicating that the field controls the radius of the circles that will be drawn. The canvas shall have a height of 400 pixels and a width of 600 pixels.

The HTML page shall also contain a script that uses an event listener to draw circles whenever the user clicks inside of the canvas element with their mouse. The number of circles to draw, and the radius of the circles, shall be obtained from the text fields. Each circle shall be colored with an alpha value of 0.1. The canvas shall be cleared before any circle is drawn. The x and y position of each circle shall be randomly determined. You can use the following code to assign a random value to x and y:

 let x = Math.floor(Math.random() * (width - 2 * r)) + r;
 let y = Math.floor(Math.random() * (height - 2 * r)) + r;

In: Computer Science

code in C Step 1 Write a program that will read in a list of addresses...

code in C

Step 1

  • Write a program that will read in a list of addresses (100 maximum) from a file.
  • The program should read records from a file until an EOF is found.
  • The program must read one character at a time from the file using fgetc.

For example: chrLetter = fgetc( pfilInput );

  • No partial addresses/records will be given.
  • The format of the addresses is: RecordID, Full Name, Street, City, State, ZipCode

Step 2

  • Store the addresses in an array of structures.
  • Use the typedef below
  • You will have to parse the input lines to separate the fields.
  • You will have to separate full name into first, middle and last name.
  • Trim all leading and trailing whitespace for EACH field.

typedef struct

{

      long lngRecordID;

      char strFirstName[ 50 ];

      char strMiddleName[ 50 ];

      char strLastName[ 50 ];

      char strStreet[ 100 ];

      char strCity[ 50 ];

      char strState[ 50 ];

      char strZipCode[ 50 ];

} udtAddressType;

Step 3

  • Call a subroutine from main and pass the array of structures as a parameter. In the subroutine, load all the addresses from the file into the array of structures.

Step 4

  • Call a subroutine from main and pass the array of structures as a parameter. In the subroutine, print out all the addresses. Make it look pretty. Don’t print out blank records. For example:

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

Customer #1

            First Name:          Luke

            Middle Name:      

            Last Name:          Skywalker

            Address:              123 Elm Street

            City:                    Corusant

            State:                  Ohio

            Zip Code:             45202

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

Customer #2

Extra Credit

  • After you read in the addresses call a subroutine to sort the addresses alphabetically by last name, first name. Try the quick sort in the STL (standard template library).

Extra Extra Credit

  • Eliminate any duplicates addresses (just check street and zip code).

In: Computer Science

C++ language: Class Song The class will have the following private attributes: Title (string) Artist (string)...

C++ language:

Class Song

The class will have the following private attributes:

  • Title (string)
  • Artist (string)
  • Album (string)
  • PlayTime (integer)
  • Year (integer)

It will also have the following public member functions:

  • default constructor setting the playtime to 0 and year to 0.
  • a constructor using Title, Artist, Album, Year, and PlayTime as arguments
  • accessors and mutators for all private attributes
  • a void function 'Play' that will print out the information about the song in the following format (provided)
Playing *Title* by  *Artist*  *playtime* seconds
  • a comparison operator == that uses title, artist and album (but not year and playtime) for comparing two songs.

Implement the missing functions using the template provided.

Class MusicLibrary

MusicLibrary has the following private attributes

  • int maxSongs
  • int numSongs
  • Song * mySongs
  • int numSongsPlayList
    • Song** playList;

Note that mySongs is a pointer that will be used to initialize a dynamic array of songs. You need to handle this dynamic array correctly (e.g. shallow copies, memory deallocation etc.)

playList is a dynamic array of pointers to Songs in the mySongs array.

The class also includes the following public member functions:

  • bool function addSong taking title, artist, album, playtime, year (provided)
  • readSongsFromFile (provided)
    • some accessors (provided)

This class is partially implemented. Complete the following:

  • implement a constructor taking the number of songs as an argument
  • implement a copy constructor
  • implement the public function 'playRandom' which plays all songs of the library ( by invoking the play function of each song) in pseudo-random fashion by alternating songs from the beginning and from the end of the list, until all songs have been played. For example, if the library has 7 songs, the songs will be played in the following order: 0, 6, 1, 5, 2, 4, 3
    • implement the public function addSongToPlayList which stores a pointer to a song in the library in the array of Song pointer. The input to this method is an integer denoting the position of the song in the MusicLibrary

If the Playlist is full, print the following error message

Could not add Song to PlayList. PlayList is full

If the integer denoting the position of a song in the MusicLibrary is invalid, print the following error message

Invalid song
  • implement the public function 'playPlaylist' which plays the songs in the playlist in the same order as the songs have been added to the playlist.

A sample main file has been provided showing the utilization of the functions, as well as a sample input file.

IMPORTANT

  • Classes and methods names must match exactly for unit testing to succeed.
  • Submissions with hard coded answers will receive a grade of 0.

main.cpp:

#include <iostream>

#include <string>

#include "Song.h"

#include "MusicLibrary.h"

using namespace std;

int main()

{

string filename;

int numsongs;

cout << "Enter number of Songs " << endl;

cin >> numsongs;

cout << "Enter filename with information about the songs" << endl;

cin >> filename;

MusicLibrary mylibrary(numsongs);

mylibrary.readSongsFromFile(filename);

mylibrary.playRandom();

for (int i = numsongs-1; i >= 0; i--) {

mylibrary.addSongToPlayList(i);

}

mylibrary.playPlaylist();

return 0;

}

musicLibrary.cpp:

#include <iostream>

#include <fstream>

#include <sstream>

#include <string>

#include "MusicLibrary.h"

MusicLibrary::MusicLibrary(int maxsongs)

{

   // implement constructor

}

MusicLibrary::MusicLibrary(MusicLibrary& other)

{

   // implement copy constructor

}

MusicLibrary::~MusicLibrary()

{

delete[] mySongs;

delete[] playList;

}

int MusicLibrary::getnumSongs()

{

   return numSongs;

}

int MusicLibrary::getmaxSongs()

{

   return maxSongs;

}

int MusicLibrary::getnumSongsPlayList()

{

   return numSongsPlayList;

}

bool MusicLibrary::addSong(string title, string artist, string album, int year, int time)

{

if (numSongs == maxSongs) {

cout << "Could not add song to library. Library is full" << endl;

return false;

}

mySongs[numSongs].setTitle(title);

mySongs[numSongs].setArtist(artist);

mySongs[numSongs].setAlbum(album);

mySongs[numSongs].setYear(year);

mySongs[numSongs].setPlayTime(time);

numSongs++;

return true;

}

bool MusicLibrary::addSong(Song& song)

{

if (numSongs == maxSongs) {

cout << "Could not add Ssong to library. Library is full" << endl;

return false;

}

mySongs[numSongs] = song;

numSongs++;

return true;

}

void MusicLibrary::readSongsFromFile(string filename)

{

ifstream input;

input.open(filename);

bool cont = true;

if (input.is_open()) {

string line;

while ( getline(input, line) && cont ) {

string title, artist, album;

string s_year, s_time;

int year;

int time;

istringstream inSS(line);

getline(inSS, title, ',');

getline(inSS, artist, ',');

getline(inSS, album, ',');

getline(inSS, s_year, ',');

getline(inSS, s_time);

year = stoi(s_year);

time = stoi(s_time);

cont = addSong(title, artist, album, year, time);

};

}

else {

cout << "could not open file " << filename << endl;

}

}

void MusicLibrary::playRandom()

{

   // implement this method

}

bool MusicLibrary::addSongToPlayList(int pos)

{

// implement this method

}

void MusicLibrary::playPlaylist()

{

   // implement this method

}

musicLibrary.h:

#pragma once

#include <string>

#include "Song.h"

using namespace std;

class MusicLibrary

{

private:

int maxSongs;

int numSongs; // number of Songs in library

Song* mySongs; // dynamic array storing all Songs

int numSongsPlayList; // number of Songs in Playlist

Song** playList; // dynamic array of pointers to Songs

public:

MusicLibrary(int maxsongs);

MusicLibrary(MusicLibrary& other);

~MusicLibrary();

   int getnumSongs();

   int getmaxSongs();

   int getnumSongsPlayList();

bool addSong(string title, string artist, string album, int year, int time);

bool addSong(Song& song);

void readSongsFromFile(string filename);

bool addSongToPlayList(int pos);

void playRandom();

void playPlaylist();

};

song.cpp:

#include <iostream>

#include "Song.h"

void Song::Play()

{

cout << "Playing "<< Title << " by " << Artist << " " << PlayTime << " seconds" << endl;

}

// Add code for constructors, accessors, mutators, and == operator.

song.h:

#pragma once

#include <string>

using namespace std;

class Song {

private:

string Title;

string Artist;

string Album;

int Year;

int PlayTime;

public:

   // Add declaration for constructors, accessors and mutators

   // Add declaration for overloading the == operator

void Play();

};

songs.txt:

Zoo Station, U2, Achtung Baby, 1991, 203
Youngblood, 5 Seconds of Summer, Youngblood, 2018, 311
Money for Nothing, Dire Straits, Brothers in Arms, 1986, 501
Summer of 69, Bryan Adams, Reckless, 1984, 178
Livin on a Prayer, Bon Jovi, Slippery when Wet, 1986, 241

In: Computer Science

in simple C++: 2. Create a structure Fraction which contains a numerator and a denominator then...

in simple C++:

2. Create a structure Fraction which contains a numerator and a denominator then do the following:
a. Write a function void printFraction(Fraction f) which prints out a fraction in the following format; e.g. if the numerator is 2 and the denominator is 5, it will print out 2/5
b. Write a function Fraction mult(Fraction f1, Fraction f2) which returns a new fraction which is the product of f1 and f2.
c. Write a function Fraction add(Fraction f1, Fraction f2) which returns a new fraction which is the sum of f1 and f2. You may simply multiply each fraction by the other’s denominator to find a common denominator; e.g. (3/4)+(5/6) = (3*6/4*6)+(5*4/6*4) = 38/24. You do NOT have to reduce the fractions.

In: Computer Science

PYTHON QUESTION Create a subclass of the Dog class named anything appropriate (e.g. Bulldog, Chihuahua, German...

PYTHON QUESTION

Create a subclass of the Dog class named anything appropriate (e.g. Bulldog, Chihuahua, German Shepherd, etc). This subclass should consist of the following:

1. It should inherit the __init__ method from the Dog class, but add one new attribute at instantiation.

2. It should add two new methods that were not in our Dog class

3. It should overwrite one of the methods that existed in the Dog class.

-------

I'm not entirely sure where I should add this information to my dog class, nor how I should go about overwriting one of the methods.

-------

class Dog:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def description(self):
        return self.name + ' is' + str(self.age) + ' years old.'

    def speak(self):
        return self.name + ' barks!'

    def run(self):
        return self.name + ' is running!'

    def fetch(self, toy):
        print(self.run())
        print(self.name + ' fetched the ' + toy)
        print(self.name + ' is bringing it back!')


    def wags_tail(self):
        return self.name + ' is so happy!'

    def isolder(self, dog2):
        if self.age > dog2.age:
            return True
        else:
            return False

dog1 = Dog('Hurc', 2)
dog2 = Dog('Sammy', 5)
print(dog1.description())
print(dog1.speak())
print(dog1.run())
dog1.fetch('ball')
print(dog1.wags_tail())
print(dog1.isolder(dog2))

In: Computer Science

Do this in python with code that I can copy and run Design and implement class...

Do this in python with code that I can copy and run

Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:

Assume that the station and volume settings range from 1 to 10.

  1. A private variable of type int named station to represent a station number. Set to
  2. A private variable of type int named volume to represent the volume setting. Set to 1.
  3. A private variable of type boolean named on to represent the radio on or off. Set to false.
  4. A non-argument constructor method to create a default radio.
  5. Method getStation() that returns the station.
  6. Method getVolume() that returns the volume.
  7. Method turnOn() that turns the radio on.
  8. Method turnOff() that turns the radio off.
  9. Method stationUp() that increments the station by 1 only when the radio is on.
  10. Method stationDown() that decrements the station by 1 only when the radio is on.
  11. Method volumeUp() that increment the volume by 1 only when the radio is on.
  12. Method volumeDown() that decrements the volume by 1 only when the radio is on.
  13. Method toString()to printout a meaningful description of the radio as follows(if the radio is on):

The radio station is X and the volume level is Y. Where X and Y are the values of variables station and volume. If the radio is off, the message is: The radio is off.

Now design and implement a test program to create a default radio object and test all class methods on the object in random order. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.

Sample run:

Turn radio on:

The radio station is 1 and the volume level is 1.

Turn volume up by 3:

The radio station is 1 and the volume level is 4.

Move station up by 5:

The radio station is 6 and the volume level is 4.

Turn volume down by 1:

The radio station is 6 and the volume level is 3.

Move station up by 3:

The radio station is 9 and the volume level is 3.

Turn radio off.

The radio is off.

Turn volume up by 2: The radio is off.

Turn station down by 2: The radio is off.

In: Computer Science

1) As a software engineer what are your legal and ethics responsibilities when you work for...

1) As a software engineer what are your legal and ethics responsibilities when you work for medical and military application?

2) What are the two levels of system design? Describe their corresponding main purpose briefly

3) What is double blind test? How to use this test to objectively compare the goodness of two software system, (e.g... google vs Bing.)

4) Define and Describe the main pros and cons of three software cost estimation methods

Compare the following concepts ( state the respective definitions and the difference)

- understandability vs user-friendliness

-software debugging vs. software testing

-black-box testing vs white-box testing

-software re-engineering vs reverse software engineering

In: Computer Science

Describe how you would adapt the RGB color model in WebGL to allow you to work...

Describe how you would adapt the RGB color model in WebGL to allow you to work with a subtractive color model.

In: Computer Science

Cyber Security class 1. Your task is to compute a session key KAB in Diffie-Hellman Key...

Cyber Security class

1. Your task is to compute a session key KAB in Diffie-Hellman Key Exchange (DHKC) with Elliptic Curves. Your private key is a = 6. You receive Bob’s public key B = (5,9). The elliptic curve being used is defined by y2 ≡ x3+x+6 mod 11.

2. In RSA Digital Signature, Suppose Bob wants to send a signed message (x = 4) to Alice. The first steps are exactly the same as it is done for an RSA encryption: Bob computes his RSA parameters and sends the public key to Alice. We know p = 3, q =11, and bob choose e=3. (Hint: We learn RSA algorithm and key generation in Week 7)

(a) What is the public key pair Bob sends to Alice?

(b) What is the value of signature s?

(c) What is the value of verkpubA(x,s)? Show all intermediate steps clearly.

Prove in RSA digital signature, verkpubA(x,s) = x

In: Computer Science