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.
In: Computer Science
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.
In: Computer Science
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 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
##### 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
You entered 111 Its base 10 equivalent is 7 |
---|
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 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.
In: Computer Science
(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
You must write the following methods:
use python 3.7
In: Computer Science
In: Computer Science
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
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?
In: Computer Science
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