Questions
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....

Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header.

Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program

2: class Rectangle in three files. In this lab, we will use class inheritance to write a new class called Box. Separate the Box class definition and implementation in Box.h and Box.cpp. The class Box inherits class Rectangle with public inheritance. The class Box has one extra data member: private: int height; A. Write the following constructors and member functions for class Box. Try to use the Rectangle class as much as possible.

1) Write a setHeight function to set the height according to the parameter. The valid value for the height should be positive. Use 1 for an invalid value.

2) Write a getHeight function to return the height.

3) Override the print function to output the length, width, and height of a box. Hints: use the print function of the Rectangle class.

4) Write a default constructor to initialize length, width, and height to 1.

5) Write an overloaded constructor that accepts three int arguments to initialize length, width, and height. The valid value for the height should be positive. Use 1 for an invalid value. Hints: call the overloaded constructor of the Rectangle class in the heading of the overloaded constructor of the Box class.

6) Write a function getVolume to calculate and return the volume of a Box object. Hints: call the getArea function of the Rectangle class. Hints: use the getArea function of the Rectangle class.

7) Write a function equals to check if two Box objects have the same dimension. Return true if they are equal in length, width, and height; otherwise, return false. Hints: use the equals function of the Rectangle class. A Box object is also a Rectangle object. B. In the function main, write statements to declare objects of class Box and test the above 2 constructors and 5 member functions.

Your project is expected to contain five source files: Rectangle.h, Rectangle.cpp, Box.h, Box.cpp, Lab7.cpp.

Rectangle.h

#ifndef Rectangle_H
#define Rectangle_H


class Rectangle                         //define a class
{
public:
        static int getCount();          //static member function

        void print() const;             //member functions

        void setLength(int a);          //mutator function
        void setWidth(int b);

        int getLength() const;                  //accessor function
        int getWidth() const;
        int getArea() const;

        bool equals(const Rectangle&) const;

//      Rectangle();                            //default constructor
        Rectangle(int a = 1, int b = 1);        //constructor with default parameters
        Rectangle(const Rectangle& x);

private:
        int length;                                     //data members
        int width;
        static int count;                       //static member variable
};

#endif

Rectangle.cpp

#include <iostream>
#include "Rectangle.h"

using namespace std;

int Rectangle::count = 0;

int Rectangle::getCount()
{
        return count;
}

void Rectangle::print() const
{
        cout << "length = " << length;
        cout << ", width = " << width << endl;
}

void Rectangle::setLength(int a)
{
        if (a > 0)
                length = a;
        else
                length = 1;
}

void Rectangle::setWidth(int b)
{
        if (b > 0)
                width = b;
        else
                width = 1;
}

int Rectangle::getLength() const
{
        return length;
}

int Rectangle::getWidth() const
{
        return width;
}

int Rectangle::getArea() const
{
        return length*width;
}

bool Rectangle::equals(const Rectangle& x) const
{
        return (length == x.length && width == x.width);
}

/*
Rectangle::Rectangle()
{
        length = 1;
        width = 1;
        count++;
}
*/

Rectangle::Rectangle(int a, int b)
{
        setLength(a);
        setWidth(b);
        count++;
}

Rectangle::Rectangle(const Rectangle& x)
{
        setLength(x.length);
        setWidth(x.width);
        count++;
}

In: Computer Science

lab requires you to use Oracle VIEW to implement a virtual database on DBSEC schema, for...

lab requires you to use Oracle VIEW to implement a virtual database on DBSEC schema, for example, on CUSTOMER table. Your task is to develop a single SQL script that will perform all the following tasks:

Table created for this assignment is listed below:

create table CUSTOMER_VPD(

SALES_REP_ID NUMBER(4),

CUSTOMER_ID NUMBER(8) NOT NULL,

CUSTOMER_SSN VARCHAR(9),

FIRST_NAME VARCHAR(20),

LAST_NAME VARCHAR(20),

ADDR_LINE VARCHAR(40),

CITY VARCHAR(30),

STATE VARCHAR(30),

ZIP_CODE VARCHAR(9),

PHONE VARCHAR(15),

EMAIL VARCHAR(80),

CC_NUMBER VARCHAR(20),

CREDIT_LIMIT NUMBER,

GENDER CHAR(1),

STATUS CHAR(1),

COMMENTS VARCHAR(1025),

USER_NAME VARCHAR(30)

);

Tasks:

Populate the CUSTOMER_VPD table with four rows of records. Pay attention to the column CTL_UPD_USER,

Create a VIEW named as MY_VIEW to display only rows that belong to the logged in user

Grant SELECT and INSERT privilege on MY_VIEW to DBSEC_CLERK

Insert one row of data into MY_VIEW as DBSEC_CLERK by using the following data

Verify your data insertion by query MY_VIEW. You (as DBSEC_CLERK) should only see one row of data you have inserted. This signifies the success of your implementation.

In: Computer Science

In the same file, complete the following exercises in the author’s pseudocode as presented in the...

In the same file, complete the following exercises in the author’s pseudocode as presented in the
text book and material on Blackboard in this chapter, and following all requirements for good
program design that were shown in Chapter 2 and all examples since then.

At the Summer Olympic Games every four years, for historical reasons, athletes represent
National Olympic Committees (NOCs) rather than strictly countries. For the sake of convenience
in our program, let us refer to them simply as “nations”. As of the 2016 Rio Olympics, then,
there were 206 nations eligible to participate in the Olympics. Write a program that could be
used to represent the medal table for the next Olympics that will be held in Tokyo in 2020. Since
we do not know how many nations will actually participate, our program will have to plan on
there being a maximum of 225 nations (in case some more NOCs are recognized before the 2020
Olympics), but must adapt to fewer nations actually being present. So, write a program that

1. Allows a user to enter
a. The names of the nations that are participating
b. The number of gold medals that nation has won
c. The number of silver medals it has won
d. The number of bronze medals it has won
e. “ZZZ” as the nation’s name to indicate that they have finished entering input

2. Outputs a list of sentences that describe each nation’s performance, e.g., for the 2016
Olympics, to describe the performance of the United States, this program would have
output “United States won 46 gold, 37 silver, and 38 bronze
medals, for a total of 121 medals” . Below this list, the program must
output the total number of gold medals awarded, silver medals awarded and bronze
medals awarded, and total of all medals awarded.

3. Scans for and outputs
a. The names of the nations with the most and least gold medals, along with their
gold medal counts, e.g., “United States won the most gold
medals: 46”
b. Similarly, the names of the nations with the most and least silver and bronze
medals respectively

4. Allows the user to enter the name of a nation that they want to search for, and if it finds
that nation, outputs a sentence in the format shown in #2 above.

All of the above must be done by applying the concepts and algorithms shown in Chapter 6, both
in the text book and in the material provided on Blackboard, and building on what we have
learned in all the chapters before this one.

The only data that this program stores is the names of the nations, and the matching counts of
gold, silver and bronze medals. All calculations and scanning for highest and lowest, etc., must
be done by the program after the user has entered the sentinel to indicate the end of their input.
All output sentences described above must be generated when they are required.

Book this is from is "Programming Logic and Design 8th Edition" by: Joyce Farrell. Must be written in pseudocode that resembles that in the book.

this is what I have so far. It probably isn't right, but it will at least give you some structure to follow. Any help is appreciated.

Start
   Declarations
       string EXIT = ZZZ
       NATION_CAPACITY = 225
       string NATION_NAME[NATION_CAPACITY]
       num goldMedals
       num silverMedals
       num bronzeMedals
       num totalMedals
       num count
       num nextNation
       num mostGold
       num leastGold
       num mostSilver
       num leastSilver
       num mostBronze
       num leastBronze

   output "Welcome to our Medal Tracker Program."
   output "This program will allow the user to enter the name of nations participating in the olympics, allow
       the user to enter the number of gold, silver, and bronze medals that nation has won."

   output "Please enter the name of the first nation (type ", ZZZ, " to stop): "
   input nextNation

   count = 0
  
   while nextNation <> ZZZ AND count < NATION_CAPACITY
       NATION_NAME[NATION_CAPACITY] = nextNation

       output "Please enter the amount of gold medals this nation has won: "
       input goldMedals[count]

       output "Please enter the amount of silver medals this nation has won: "
       input silverMedals[count]

       output "Please enter the amount of bronze medals this nation has won: "
       input bronzeMedals[count]

       count = count + 1

       output "Please enter the next nation or ", ZZZ, " to stop: "
       input nextCustomerID
   endwhile

   output "You entered data for ", count, " nations."

   totalMedals = goldMedals + silverMedals + bronzeMedals

   output "The nation ", nextNation, " won ", goldMedals, " gold medals, ", silverMedals, " silver medals, and ", bronzeMedals, "
       bronze medals, for a total of ", totalMedals, " medals.

   mostGold =

In: Computer Science

The expression below (approximately) calculates the volume of a cylinder. Extract the expression into a function...

The expression below (approximately) calculates the volume of a cylinder. Extract the expression into a function named calculate_volume, and then replace the existing calculations with function calls.

Do in Python

In: Computer Science

NEED IN JAVA Problem statement. This application will support the operations of a technical library for...

NEED IN JAVA

Problem statement.

This application will support the operations of a technical library for an R&D organization. This includes the searching for and lending of technical library materials, including books, videos, and technical journals. Users will enter their company ids in order to use the system; and they will enter material ID numbers when checking out and returning items.  

Each borrower can be lent up to five items. Each type of library item can be lent for a different period of time (books 4 weeks, journals 2 weeks, videos 1 week). If returned after their due date, the library user's organization will be charged a fine, based on the type of item ( books $1/day, journals $3/day, videos $5/day).

Materials will be lent to employees with no overdue lendables, fewer than five articles out, and total fines less than $100.  

R & D Library 
books
UnderstandingMathematics 0015B
EngineeringAsAService 0012A
FundamentalAlgorithms 0008A
BigJava 0019C
SortingAndSearching 0071A
MathematicalComputations 0004B
journals
FeasibilityOfTheWeb X980
StudyOfAComet X324
ACaseStudyOfBehavioralActions X234
HowToKeepAJob X210
XgonGiveItToYa X821
videos
TedTalkSeries 12.W
LectureSeries 16.S
  1. You will write classes from the last in-class assignment, R&DLibrary. R&DLibrary is the main file in which a user can choose to enroll themselves, check out an item, return an item, pay a fine and display their account (what is currently checked out, accumulated fines).
  2. Write a material class that calculates the fine based off of the type of item, the length it’s been checked out and whether or not it’s even been checked out.
  3. Lastly, write a employee Class that contains the username of a user, the items that person has checked out, a copy of the accumulated fines and the number of items checked out.
  4. Create the program using repl.it online IDE and saving it to a files named, R&DLibrary.java, Employee.java, MaterialCard.java.
  5. Download all the files from repl.it.
  6. At the top of the empty file, write the following comment, modifying it to reflect your personal in- formation. Writing these comments on top of your programs helps other developers understand basic information about your programs and is a good habit to develop.
  7. /*

    * Program: LibraryReservation.java

    *

    * Author 1: FULL NAME

    *

    * Date:   THE CURRENT DATE

    * Course:  

    *

    * Program Description:

    *

    * WRITE PROGRAM DESCRIPTION

    *

    */

In: Computer Science

A. Working at Music Best You are planning a road trip and want to create a...

A. Working at Music Best

You are planning a road trip and want to create a playlist of your favorite songs. Assume that the song titles are in an array of strings. Create a shuffle of your songs (permutation of your original songs). Use the Fisher-Yates shuffle algorithm that works in O(n) running time. We will use a method that creates pseudo-random numbers (see end for help) in O(1) running time. The basic idea is to start from the last element, swap it with a randomly selected element from the whole array (including last). In the next step, you will consider the array from 0 to n-2 (size reduced by1), and repeat the process until you reach the first element. Write a program that uses the provided Playlist.txt as input and outputs the shuffled array in a file called LastNameFirstNamePlaylist.txt. Follow the next pseudocode: To shuffle an array a of n elements (indices 0..n-1):

for i=n-1 down to 1 j= random integer with 0 <= j < i

exchange a[j] and a[i]

Count the time to read from the file, to shuffle the songs and to create the output. Note: To count the time use system.currentTimeMillis().

Create appropriate JUnits to test your program. Help with JUnits:

Instructions for developing JUnit:

• To compare two text files in Junit, you can try the following code. Use BufferedReader to read the input files.

BufferedReader Out=new BufferedReader (new FileReader (<Path of output file>));

BufferedReader In=new BufferedReader (new FileReader (<Path of input file>));

while ((expectedLine = In.readLine ()) != null) {

String actualLine = Out.readLine ();

assertEquals (expectedLine, actualLine);

}

• Set seed value as 20.

Random r=new Random();

r.setSeed(20);

Compare the output file with attached see next:

if you use nextDouble() use Target1.txt to compare

double d = random.nextDouble();

int j = (int)(d*arr.length);

else if you use nextInt() use Target2.txt

Programming Standards:

• Your header comment must describe what your program does.

• You must include a comment explaining the purpose of every variable or named constant you use in your program.

• You must use meaningful identifier names that suggest the meaning or purpose of the constant, variable, function, etc.

• Precede every major block of your code with a comment explaining its purpose. You don't have to describe how it works unless you do something tricky.

• You must use indentation and blank lines to make control structures more readable.

Deliverables:

Your main grade will be based on (a) how well your tests cover your own code, (b) how well your code does on your tests (create for all non-trivial methods), and (c) how well your code does on my tests (which you have to add to your test file). For JUnit tests check canvas.

Use cs146S19.<lastname>.project1 as your package, and Test classes should be your main java file, along with your JUnit java tests.

Do not use any fancy libraries. We should be able to compile it under standard installs. Include a readme file on how to compile the project.

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

MY SOLUTION:

package RandomMusic;

import static org.junit.Assert.*;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;

*playMusicTest.java


public class playMusicTest {

@Test
public void playMusictest() throws IOException
{
  
File file = new File("src\\RandomMusic\\Playlist.txt");
File file1 = new File("src\\RandomMusic\\Target1.txt");
// read input playlist
BufferedReader in = new BufferedReader(new FileReader(file));
// read output target
BufferedReader out = new BufferedReader(new FileReader(file1));
  
String[] playList = new String[459]; // create an array
int i=0; // element of array
String str;
  
// read content of Playlist.txt then copy the content to array
while((str = in.readLine())!=null)
{
playList[i] = str;
i++;
}
  
// random number
Random rand = new Random(0);
rand.setSeed(20);
  
// swap the chosing song.
for(int j = playList.length - 1;j>0;j--)
{
int index = rand.nextInt(j);
String tmp;
tmp = playList[index];
playList[index] = playList[j];
playList[j]= tmp;
}
  
// compare output of playlist = content of target file
for(int k=0; k<playList.length;k++)
{
String actualLine = out.readLine();
assertEquals(playList[k],actualLine);
  
}
  
}

}

*RandomMusic.java

package RandomMusic;

import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Random;
import java.io.*;


public class RandomMusic {
  
String[] playList = new String[459]; // String of playList
int i = 0;
Random rand; // random
BufferedReader in; // read file
  
  
// Open a Text File
public void openFile() throws IOException
{
try {
File file = new File("src\\RandomMusic\\Playlist.txt");
in = new BufferedReader(new FileReader(file));
String str;
while((str = in.readLine())!=null)
{
playList[i] = str;
i++;
}
  
} catch(Exception e) {
System.out.println("Could not find the data file!");
}
  
}
  
// close File
public void closeFile() throws IOException
{
in.close();
  
}

// Swap song in playlist
public void swap(int index, int j)
{
String tmp;
tmp = playList[index];
playList[index] = playList[j];
playList[j]= tmp;
}
  
// Random song in playlist then swap if the song chose
public void playMusic()
{
rand = new Random();
for(int j = playList.length - 1;j>0;j--)
{
int index = rand.nextInt(j);
swap(index,j);
}
}
  
// print out playlist
public void printOut()
{
for(int j=0; j<playList.length;j++)
{
System.out.println(playList[j]);
}
}
  
// Main program
public static void main(String[] args) throws IOException
{
RandomMusic favorMusic = new RandomMusic(); // create RandomMusic
favorMusic.openFile(); // read file
favorMusic.playMusic(); // random music
favorMusic.printOut(); // print out playlist
favorMusic.closeFile(); // close file
}

}

*openFileTest

package RandomMusic;

import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;

import org.junit.Test;

// Check playlist file is exists
public class openFileTest {

@Test
public void openFiletest() throws IOException
{
File file = new File("src\\RandomMusic\\Playlist.txt");
assertTrue(file.exists());
}

  
}

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

I am getting error in playMusicTest.java.... Please help.

In: Computer Science

Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor...

Lab to be performed in Java.

Lab:

1.) Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Write a driver class to test that demonstrates that an exception happens for these scenarios

2.) Write a class named InvalidTestScore by reusing the code in TestScores class you wrote for 1) so that it throws an InvalidTestScore exception. Write a driver class to test that demonstrates that an exception happens for these scenarios.

Note 1) and 2) are two separate programs that must be handed in as well as your test score array.

---- Create a class TestScores and TestScores constructor should accept an array of test scores as its argument. Users will enter 5 test scores use a scanner to get input from the console.

---- Create a method that returns or print to console the correct average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException.

---- Create a class InvalidTestScore by reusing the code of TestScores that print to console the line “Test score values should not be greater than 100 or negative” when IllegalArgumentException is thrown.

In: Computer Science

I. Answer part A, B, and C 1a) Return true if the given int parameter is...

I. Answer part A, B, and C

1a)

Return true if the given int parameter is both positive and less than 10, and false otherwise. Remember that 0 is not positive!


positiveLessThan10(10) → false
positiveLessThan10(9) → true
positiveLessThan10(11) → false

1b)

Return true if the parameters are in ascending order, from left to right. Two values that are equal are considered to be in ascending order. Remember, you can just type return true or return false to return true or false. Both true and false are reserved words in Java.


isAscending(1, 2, 3) → true
isAscending(1, 2, 2) → true
isAscending(3, 2, 1) → false

1c)

Return true if the parameters are in ascending order, from left to right, or in descending order from left to right. Two values that are equal are considered to be in either ascending or descending order.


isAscendingOrDescending(1, 2, 3) → true
isAscendingOrDescending(1, 2, 2) → true
isAscendingOrDescending(3, 2, 1) → true

In: Computer Science

3. Show the string that would result from each of the following string formatting operations. If...

3. Show the string that would result from each of the following string formatting operations. If the operation is not legal, explain why. Use Python shell to solve this question

(a) "Looks like {1} and {0} for breakfast".format("eggs", "spam") =>

(b) "There is {0} {1} {2} {3}".format(1,"spam", 4, "you") =>

(c) "Hello {0}".format("Susan", "Computewell") =>

(d) "{0:0.2f} {0:0.2f}".format(2.3, 2.3468) =>

(e) "{7.5f} {7.5f}".format(2.3, 2.3468) =>

(f) "Time left {0:02}:{1:05.2f}".format(1, 37.374) =>

(g) "{1:3}".format("14") =>

In: Computer Science

After reviewing the resources for this module, discuss the power of clustering and association models. Give...

After reviewing the resources for this module, discuss the power of clustering and association models. Give an example of a company that collects or uses data for various reasons. How can clustering or association models help the company complete the sentence "You might also be interested in

In: Computer Science

I need to write a C++ program that appends "not" into the string without using the...

I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it.

Examples:

is is = is not is not

This is me = This is not me

What is yellow? = What is not yellow?

The sky is pink = The sky is not pink

isis = isis

What happened to you? = What happened to you?

In: Computer Science

Research and set up a mock-up IT policy pertaining to the use of mobile devices covering...

Research and set up a mock-up IT policy pertaining to the use of mobile devices covering personal cell phones, wearables, and company laptops and tablets. Please give the following:

  • cover sheet
  • IT strategy
  • Physical map of area coverage
  • end user usage policy
  • minimum requirements
  • local, state and Federal laws and guidelines ( if applicable)
  • an example of the policy

In: Computer Science

In JAVA please! The log class will allow to store multiple string messages but one at...

In JAVA please!

The log class will allow to store multiple string messages but one at a time (via record(..)), and also get back the whole sequence of messages (via read()).

assume and gurantee that each message is a single line of text.

the fields can be of my/your choice

four different methods in this class include;

public Logger() . establishes a new and empty log.

public Log duplicate() . this is not a constructor, but creates a no-aliases copy of this log and returns it. This becomes useful for when sharing the information without allowing modification.

public String[] read() . this will return an array of strings where each item in the array is the next line of the recorded content.

public void record(String msg) . this will record the given message as the next line in the log file.

here you will assume there are no newline characters in the message (the behavior is not defined if they are present; this means they must not be accounted for but if you want you can)

In: Computer Science

Let the schema R = (A,B,C) and the set F = {A → B,C → B}...

Let the schema R = (A,B,C) and the set F = {A → B,C → B} of FDs be given. Is R in 3NF? Why or why not?

In: Computer Science

Two communication devices are using a single-bit even parity check for error detection. The transmitter sends...

  1. Two communication devices are using a single-bit even parity check for error detection. The transmitter sends the byte 10101010 and, because of channel noise,
  1. the receiver gets the byte 10011010. Will the receiver detect the error? Why or why not?
  2. the receiver gets the byte 10111010. Will the receiver detect the error? Why or why not?
  3. Compute the Internet checksum for the data block E3 4F 23 96 44 27 99 D3. Then perform the verification calculation.

In: Computer Science