Questions
C++ CLASSES 1. Define a class date that has day, month and year data members. 2....

C++

CLASSES

1. Define a class date that has day, month and year data members.

2. Define a class reservation with following data members:

- An integer counter that generates reservation numbers.

- An integer as a reservation number. The counter is incremented each time a reservation object is created. This value will be assigned as the reservation number.

- Number of beds.

- Reservation date from class date.

3. Define a class rooms with data members:

- Room number

- Number of beds (1 or 2).

- A 2D int array (12 by 30) that show the availability of the room on each day of the year. The rows are the months and columns are days of month. If the room in available on a specific date, the array element value is zero. If the room has been reserved, the array element value has the reservation number.

4. Define a manager class with data member:

- A variable motel_size that indicates the number of rooms of motel.

- An array of pointers to rooms.

- An array of pointers to guests.

Member Functions:

- Function that processes a reservation received as parameter. If unsuccessful the function returns zero. If the reservation is successful (if the a room with requested # of beds is available during the required dates) the function returns reservation number.

- Function that receives reservation number as parameter and outputs the details of reservation.

- Function that receives reservation number and date as parameters and cancels reservation.

- Function that dictates the availability of single and double rooms on a required date.

5. Main function:

Creates manager, and reservation objects. This function calls the manager member function to process reservations.

In: Computer Science

Explain the differences between a replay attack and a Man-in-the-middle attack.

Explain the differences between a replay attack and a Man-in-the-middle attack.

In: Computer Science

Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...

Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.

In: Computer Science

In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0...

  1. In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0 to 4π). Checkpoints of the requirements:
    1. Generate your independent variables first; the step size should be no larger than 0.1 so that it has enough samples to get smooth lines. Plot the two waves on the same graph.  
    2. Specify the line color and styles: red dashed line for sine & blue solid line with dot markers for cosine.
    3. Include axis labels and a descriptive title (for example: sin and cos graph).

d. Include a legend

e. Set the x limits from 0 to 4??

answer for e.

In: Computer Science

Constructors/Destructors - Initialize your data. Allocate memory if using a dynamically allocated array. The destructor should...

  • Constructors/Destructors - Initialize your data. Allocate memory if using a dynamically allocated array. The destructor should deallocate the memory. The constructor should take a single int variable to determine the size. If no size is specified (default constructor), then the size should be set to 50.

  • operator[](size_t) - This should return the location with the matching index. For example if given an index of 3, you should return the location at index 3 in the list.

Location class/struct - This class/struct should have the following public member variables: name, address, city, postal code, province, latitude, longitude, minimum price range, and max price range.

#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

// "Location.h"

using std::getline;
using std::ifstream;
using std::string;
using std::stringstream;
class Location {
public:
string name, address, city, postalCode, province;
double latitude, longitude;
int priceRangeMax, priceRangeMin;
};

class PizzaZine {
private:
Location *pizzaLocations;
size_t size;

public:
// PizzaZine(const size_t & = 50);
// work
PizzaZine() { pizzaLocations = new Location[50]; }
~PizzaZine() { delete[] pizzaLocations; }

Location &operator[](size_t);

// This function is implemented for you
void readInFile(const string &);
};
// PizzaZine::PizzaZine() { pizzaLocations = new Location[50]; }
// PizzaZine::~PizzaZine() { delete[] pizzaLocations; }

Location &PizzaZine::operator[](size_t index) { return pizzaLocations[index]; } // this is where the code ends of my written code rest is skeleton

void PizzaZine::readInFile(const string &filename) {
ifstream inFile(filename);
Location newLoc;

string line;
string cell;

// Read each line
for (int i = 0; i < size; ++i) {
// Break each line up into 'cells'
getline(inFile, line);
stringstream lineStream(line);
while (getline(lineStream, newLoc.name, ',')) {
getline(lineStream, newLoc.address, ',');
getline(lineStream, newLoc.city, ',');
getline(lineStream, cell, ',');
if (!cell.empty()) {
newLoc.postalCode = stoul(cell);
}

getline(lineStream, newLoc.province, ',');
getline(lineStream, cell, ',');
newLoc.latitude = stod(cell);
getline(lineStream, cell, ',');
newLoc.longitude = stod(cell);

newLoc.priceRangeMin = -1;
getline(lineStream, cell, ',');
if (!cell.empty()) {
newLoc.priceRangeMin = stoul(cell);
}

newLoc.priceRangeMax = -1;
getline(lineStream, cell, ',');
if (!cell.empty() && cell != "\r") {
newLoc.priceRangeMax = stoul(cell);
}
pizzaLocations[i] = newLoc;
}
}
}

the main cpp shouldnt matter as much as all of that was skeleton code

main.cpp:15:15: error: no matching constructor for initialization of 'PizzaZine'
PizzaZine top10(10);
^ ~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
main.cpp:29:15: error: no matching constructor for initialization of 'PizzaZine'
PizzaZine top200(200);
^ ~~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
main.cpp:36:15: error: no matching constructor for initialization of 'PizzaZine'
PizzaZine top400(400);
^ ~~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
3 errors generated.

In: Computer Science

Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of...

  1. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the a Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume object. The remaining lines consist of a single character followed by a space followed by a number. The character will be one of ‘U” or ‘D’ which stand for “up” and “down” respectively. The function will create a new Volume object and then process each line of the file by calling the appropriate method of the Volume object which changes the value of the Volume. The function then returns the final Volume object.   Guidelines/hints:
    1. This is a standalone function, it should NOT be inside (indented within) the class. It should be listed in the module after the Volume class and without indentation.
    2. Note that the first line of the file will be treated differently than all the other lines. Probably the easiest way to do this is to 1) open the file, 2) call the .readline() method (no s!) which reads a single line, the initial value of the Volume, then 3) call the .readlines() method which reads the rest of the lines. Item 2) will be used to set the initial Volume and 3) will be iterated over to represent turning the volume up and down some number of time.
    3. Make sure you return the final Volume object.

##### Volume #####

# set and get

>>> v = Volume()

>>> v.set(5.3)

>>> v

Volume(5.3)

>>> v.get()

5.3

>>> v.get()==5.3 # return not print

True

>>>

# __init__, __repr__, up, down

>>> v = Volume(4.5) # set Volume with value

>>> v

Volume(4.5)

>>> v.up(1.4)

>>> v

Volume(5.9)

>>> v.up(6) # should max out at 11

>>> v

Volume(11)

>>> v.down(3.5)

>>> v

Volume(7.5)

>>> v.down(10) # minimum must be 0

>>> v

Volume(0)

# default arguments for __init__

>>> v = Volume() # Volume defaults to 0

>>> v

Volume(0)

# can compare Volumes using ==

>>> # comparisons

>>> v = Volume(5)

>>> v.up(1.1)

>>> v == Volume(6.1)

True

>>> Volume(3.1) == Volume(3.2)

False

# constructor cannot set the Volume greater

# than 11 or less than 0

>>> v = Volume(20)

>>> v

Volume(11)

>>> v = Volume(-1)

>>> v

Volume(0)

>>>

##### partyVolume #####

>>> partyVolume('party1.txt')

Volume(4)

>>> partyVolume('party2.txt')

Volume(3.75)

>>> partyVolume('party3.txt')

Volume(0.75)

# make sure return not print

>>> partyVolume('party1.txt')==Volume(4) # return not print

True

>>> partyVolume('party2.txt')==Volume(3.75)

True

>>> partyVolume('party3.txt')==Volume(0.75)

True

use python3.7

In: Computer Science

Java Asks the user to enter a binary number ,example: 1011011 Validates that the entry is...

Java

  1. Asks the user to enter a binary number ,example: 1011011
  2. Validates that the entry is a binary number. Nothing but a binary number should be allowed.
  3. The program converts and displays the binary number to its base 10 equivalent, Example 1112 = 710
  4. The user must be asked if he/she wants to continue entering numbers or quit.
  5. Keeps a record in a txt file named outDataFile.txt with the history of all numbers entered and the associated results, in the following format:
Sample Output

You entered 111

Its base 10 equivalent is 7

  1. No infinite loops, examples include:
    1. for(;;)
    2. while(1)
    3. while(true)
    4. do{//code}while(1);
  2. No break statements to exit loops
  3. No labels or go-to statements
  4. If you violate any of these restrictions, you will automatically get a score of ZERO!

SPECIFIC RESTRICTIONS FOR THIS ACTIVITY

You should develop your own method, do not use Integer.parseInt (String s, int radix)

*********************************************************************************************************************************

This is my code so far, it works but once I ask the user to try another binary. The Binary doesn't come out right

***********************

import java.util.Scanner; // Needed for the Scanner class
import java.io.*; // Needed for File I/O classes

public class Binary
{
public static void main(String[] args) throws IOException
{

   String userEntry; // To hold the userEntry
   String again = "y";
   int binary = 0;
   int bin = 0;
   int decimal = 0;
   int i = 0;


// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);

   PrintWriter outputFile = new PrintWriter("outDataFile.txt");

   while (again.equalsIgnoreCase("y"))
{


        // Get the user's name.
           System.out.println("Enter a Binary String: ");
           userEntry = keyboard.nextLine();
           System.out.println("\nYou entered the number: " + userEntry );
           outputFile.println("You entered the number: " + userEntry);

           //validate userName
           userEntry = checkUserEntry (userEntry);
           binary = Integer.parseInt(userEntry);
           boolean result = isBinary(binary);

           if(result == true)
      {
           bin = binary;

           while(binary != 0)
       {
           decimal += (binary%10)*Math.pow(2, i++);
           binary = binary /10;

       }
           System.out.println("its base 10 equivalent of " + bin +" is " + decimal );
           outputFile.println("its base 10 equivalent of " + bin +" is " + decimal );
       }
       else
       {
           System.out.println("This is not a Binary Number, try again");
       }

       System.out.println("\n\nWould you like to try another number? (y/Y). Anything else will quit");
       again = keyboard.nextLine();

      }
      outputFile.close();
      System.out.println("Goodbye");

}//end main


   public static boolean isBinary(int binary)
   {
       int Input = binary;
           while (Input != 0)
               {
                   if (Input % 10 > 1)
                   {
                       return false;
                   }
           Input = Input / 10;
               }
                       return true;
   }

public static String checkUserEntry (String userAnswer)
{

   int userAnswerLength = userAnswer.length();
   int counter = 0;//to iterate through the string
   // Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);

   while(userAnswerLength==0)
   {
               System.out.println("That is not a number >= 0, try again");
               userAnswer = keyboard.nextLine();
               userAnswerLength = userAnswer.length();
       }

   while(counter < userAnswerLength)
   {
           if(!Character.isDigit(userAnswer.charAt(counter)))
           {
               System.out.println("That is not a number >= 0, try again ");
               userAnswer = keyboard.nextLine();
               userAnswerLength = userAnswer.length();
               counter = 0;
           }
           else
           {
               counter++;
           }
           while(userAnswerLength==0)
           {
                  System.out.println("That is not a number >= 0, try again");
                   userAnswer = keyboard.nextLine();
                   userAnswerLength = userAnswer.length();
           }
       }

       return userAnswer;
}

}//end class ValidateUserName

In: Computer Science

Please do Part III Part I Problem statement: Given an array of 'n' non-duplicate integers, find...

Please do Part III


Part I

Problem statement:

Given an array of 'n' non-duplicate integers, find pairs of integers from the array that make the sum equal to K.

Eg. [1, 2, 7, 11, 6, 9, 5] K= 12

Soln: (1,11), (7,5).

Part II

Write an Oracle for testing this program using Data Flow Testing. As usual, write down test cases in a tabular form with reasons, inputs, expected output etc.


Part III  

1.       Identify the basic blocks in your program and draw the flow graph

2.       Identify as many independent paths as possible with a minimum of three paths)

3. Classify these as simple paths and loop-free paths

4.       Identify the definition, P-uses, and C-uses throughout the program

5.       Identify the def-use associations of variables if any.


need solution to it the earliest possible

Program in java would be needed

In: Computer Science

(Problem is from the textbook Data Structures using C++) Add a function to the dateType class....

(Problem is from the textbook Data Structures using C++)

Add a function to the dateType class.

The function's name is compareDates.

Its prototype is

int compareDates(const dateType& otherDate;

The function returns -1 if otherDate is greater than than this date

The function returns 0 if otherDate equals this date

The function returns 1 if otherDate is less than this date

Examples

dateType d1(1, 1, 2019);

dateType d2(11,1, 2019)

d1.compareDates(d2) returns -1

d2.compareDates(d1) returns 1

d2.compareDates(d2) returns 0

<<<<< dateType.h >>>>>>

#ifndef H_addressType

#define H_addressType

#include

#include

using namespace std;

class addressType

{

public:
void setStreet(string myStreet);
void setCity(string mCity);
void setState(string myState);
void setZIP(int myZIP);

string getStreet() const;

string getCity() const;

string getState() const;

int getZIP() const;

void printAddress() const;

addressType(string = "", string = "", string = "",

int = 0);

private:

string street;

string city;

string state;

int ZIP;

}

#endif

void addressType::setStreet(string myStreet)

{

street = myStreet;

} // end function setStreet

void addressType::setCity(string myCity)

{

city = myCity;

} // end function setCity

void addressType::setState(string myState)

{

state = myState;

} // end functioni setState

void addressType::setZIP(int myZIP)

{

ZIP = myZIP;

} // end function setZIP

string addressType::getStreet() const
{
return street;
} // end function getStreet

string addressType::getCity() const

{

return city;

} // end function getCity

string addressType::getState() const

{

return state;

} // end function getState

int addressType::getZIP() const

{
return ZIP;

} // end function getZIP

void addressType::printAddress() const

{

cout << "\n\t" << getStreet() << ", " << getCity()

<< "\n\t" << getState() << " - " << getZIP();

} // end function printAddress

addressType::addressType(string myStreet, string myCity,

string myState, int myZIP)

{

setStreet(myStreet);

setCity(myCity);

setState(myState);

setZIP(myZIP);

} // end constructor addressType

In: Computer Science

Write a class Volume that stores the volume for a stereo that has a value between...

  1. Write a class Volume that stores the volume for a stereo that has a value between 0 and 11. Usage of the class is listed below the problem descriptions. Throughout the class you must guarantee that:
    1. The numeric value of the Volume is set to a number between 0 and 11. Any attempt to set the value to greater than 11 will set it to 11 instead, any attempt to set a negative value will instead set it to 0.
    2. This applies to the following methods below: __init__, set, up, down

You must write the following methods:

  1. __init__ - constructor.   Construct a Volume that is set to a given numeric value, or, if no number given, defaults the value to 0.   (Subject to 0 <= vol <=11 constraint above.)
  2. __repr__ - converts Volume to a str for display, see runs below.
  3. set – sets the volume to the specified argument (Subject to 0 <= vol <=11 constraint above.)
  4. get – returns the numeric value of the Volume
  5. up – given a numeric amount, increases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  6. down – given a numeric amount, decreases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  7. __eq__ - implements the operator ==.   Returns True if the two Volumes have the same value and False otherwise.

use python 3.7

In: Computer Science

(16%) Convert decimal +47 and +38 to binary, using the signed-2’s-complement representation and enough digits to...

  1. (16%) Convert decimal +47 and +38 to binary, using the signed-2’s-complement representation and enough digits to accommodate the numbers, Then, perform the binary equivalent of (+47)+(-38) and (-47)+(-38) using addition. Convert the answers back to decimal and verify that they are correct.

In: Computer Science

Correct all errors in the provided script. Remember that some errors are fatal (result in an...

Correct all errors in the provided script. Remember that some errors are fatal (result in an error message) while others simply cause the program to produce incorrect results.

You can assume that you have fixed all errors when the checker passes all tests.

%***************************************************************************************

%It is recommended that you debug this program offline and submit only once you have corrected the errors

%***************************************************************************************

%%

%These 3 loops all calculate the sum of the integers from 1 through 1000

for number = 1:1000

total = total + number;

end

fprintf('The sum of the numbers from 1 through 1000 is %i\n', total);

k=0;

theTotal = 0;

while k <1000

theTotal = theTotal + k;

end

fprintf('The sum of the numbers from 1 through 1000 is %i\n', theTotal);

theTotal_2 = 0;

while k >1000

theTotal_2 = theTotal_2 + k;

k = k-1;

end

fprintf('The sum of the numbers from 1 through 1000 is %i\n', theTotal);

%%

%These structures all do the same thing - find the roots of a quadratic,

%and print out the real roots, if any

a = 1;

b = 3;

c = 2;

discriminant = b^2 - 4ac;

if discriminant > 0

root1 = (-b+sqrt(b^2 - 4*a*c))/(2*a);

root2 = (-b-sqrt(b^2 - 4*a*c))/(2*a);

fprintf('The roots are %f and %f\n', root1, root2);

elseif discriminant == 0

root1 = -b/(2*a);

root2 = NaN;

fprintf('The root is %f and %f\n', root1);

else

fprintf('There are no real roots\n');

end

aa = 1;

bb = -8;

cc = 16;

discriminant = bb^2 - 4*aa*cc;

switch discriminant

case discriminant>0

root3 = (-bb+sqrt(bb^2 - 4*aa*cc))/(2*aa);

root4 = (-bb-sqrt(bb^2 - 4*aa*cc))/(2*aa);

fprintf('The roots are %f and %f\n', root3, root4);

case discriminant == 0

root3 = -b/(2*a);

root4 = NaN;

fprintf('The root is %f\n', root3);

otherwise

fprintf('There are no real roots\n');

end

%%

%This program calculates and plots the Fibonacci numbers that are less than

%100

fibonacciNumber=[1, 1];

%first time through the loop, calculating the 3rd Fibonacci number

index = 3;

while fibonacciNumber < 100

fibonacciNumber(end+1) = fibonacciNumber(end) + fibonacciNumber(end-1);

index = index + 1;

end

try

assert(sum(fibonacciNumber>=100)==0)

%The following lines will only be executed if the assertion passes

fprintf('There are %i Fibonacci numbers that are less than 100;', length(fibonacciNumber));

fprintf('They are: \n')

fprintf('%i\n', fibonacciNumber);

plot(1:index, fibonacciNumber)

catch ME

switch ME.identifier

case 'MATLAB:assertion:failed'

disp('Incorrect set of Fibonnaci numbers.')

case 'MATLAB:samelen'

disp('error in plot - vectors not the same length')

otherwise

disp('Something is wrong with the Fibonacci number code')

end

end

%%

%This program calls the user-defined function, GPA() to calculate a

%student's grade point average

Grades = 'ABACAABBDAC';

Credits = [43454453324];

Name = "Joe";

GPAValue = gradePointAverage(grades, credits);

fprintf('%s''s GPA is %d\n', GPAValue);

function [ gradePointAverage] = GPA(letterGrades, numCredits )

%UNTITLED3 Summary of this function goes here

% Detailed explanation goes here

qualityPoints = (letterGrades=='A')*4 + (letterGrades=='B')*3 + (letterGrades=='C')*2 + (letterGrades=='D')*1;

totalPoints = sum(qualityPoints.*credits);

gradePointAverage = totalPoints/sum(credits);

end

In: Computer Science

Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...

Write in Java

  1. Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question)
    1. a method to return the botanical (Latin) name of the plant
    2. a method that describes how the plant is used by humans (as food, to build houses, etc)
  2. Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information:
    1. list 2 dishes (meals) that the vegetable can be used in
    2. where this vegetable is grown

The Vegetable class should have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method

Child classes should call parent methods whenever possible to minimize code duplication.

The driver program must test all the methods in the Vegetable class, and show that the new methods added to the Plant class can be called by each of the child classes. Include comments in your output to describe what you are testing, for example   System.out.println(“testing Plant toString, accessor and mutator”);. Print out some blank lines in the output to make it easier to read and understand what is being output.

public class Plant {
  
private String name;
private String lifespan;

public Plant(){
name = "no name";
lifespan = "do not know";
}
public Plant(String newName, String newlife)
{
name = newName;
lifespan = newlife;
}
public String getName()
{
return name;
}
public String getlife()
{
return lifespan;
}
public void setName(String newName)
{
name = newName;
}
public void setLifeSpan(String newlife)
{
lifespan = newlife;
}
public void set(String newName, String newlife)
{
name = newName;
lifespan = newlife;
}
public String toString()
{
return "Name:"+name+"\nLifeSpan:"+lifespan;
}
}

In: Computer Science

What is Link State Routing? What are its advantages and disadvantages?

What is Link State Routing? What are its advantages and disadvantages?

In: Computer Science

Please use the python 3.7 for this assigments Q1 Write a program that accepts the lengths...

Please use the python 3.7 for this assigments

Q1 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.

Q2 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides.

[FIGURE 3.5] The semantics of a while loop The following example is a short script that prompts the user for a series of numbers, computes their sum, and outputs the result. Instead of forcing the user to enter a definite number of values, the program stops the input process when the user simply presses the return or enter key. The program recognizes this value as the empty string. We first present a rough draft in the form of a pseudocode algorithm: set the sum to 0.0 input a string while the string is not the empty string convert the string to a float add the float to the sum input a string print the sum Note that there are two input statements, one just before the loop header and one at the bottom of the loop body. The first input statement initializes a variable to a value that the loop condition can test. This variable is also called the loop control variable. The second input statement obtains all of the other input val- ues, including one that will terminate the loop. Note also that the input must be received as a string, not a number, so the program can test for an empty string. If the string is not empty, we assume that it represents a number, and we convert it.

Q3 Modify the guessing-game program of Section 3.5 so that the user thinks of a number that the computer must guess. The computer must make no more than the minimum number of guesses.

In: Computer Science