Questions
prove lcs algorithm class finds the optimal solution

prove lcs algorithm class finds the optimal solution

In: Computer Science

Copy Constructor and Operator Overloading. You are given a Date class that stores the date as...

Copy Constructor and Operator Overloading.

You are given a Date class that stores the date as day, month, year and an image of a flower.

The image of the flower is an object which stores a simple string with the flowers type.

This is an example of class composition/aggregation. There are a few important things to bear in mind.

  1. Need for copy constructor
  2. Ability to do operator overloading
  3. Need to release dynamic memory – using destructor

You are given the specification files Date.h and Image.h. Write the implementation files Date.cpp and Image.cpp. You are given a driver that creates Date objects, copies date objects and compares date objects. Your implementations should make the driver produce the correct output.

main.cpp

#include <iostream>
#include "Date.h"
int main()
{
Date first(1,2,2019,"Rose");
Date second(1,3,2019,"Lily");
Date third(first);
  
cout<<"First Date : "<<first.toString()<<endl;
cout<<"Second Date: "<<second.toString()<<endl;
cout<<"Third Date: "<<third.toString()<<endl;

if (second>first) cout<<"Second Date is more recent"<<endl;
first.setPic("Change");
cout<<"First Date now: "<<first.toString()<<endl;
cout<<"Third Date now: "<<third.toString()<<endl;
Date fourth= second;
cout<<"Fourth Date: "<<fourth.toString()<<endl;
second.setPic("Hibiscus");
cout<<"Second Date now: "<<second.toString()<<endl;
cout<<"Fourth Date now: "<<fourth.toString()<<endl;

}

Image.h
#include <string>
using namespace std;

class Image
{
string picture;
public:
Image(string s);
string getPicture();
void setPicture(string newPic);
};

Date.h

using namespace std;
#include <vector>
#include<memory>
#include<string>
#include "Image.h"
#include<iostream>
class Date{
int day,month,year;
shared_ptr<Image> pic;
//Image *pic;

public:
Date();
Date(int day, int month, int year, string picture);
Date(const Date &copyDate);// copy constructor

bool operator>(const Date &otherDate);// operator overlaoding

int getDay() const;

string getPicture()const; //returns the string representing the picture from the image object

shared_ptr<Image> getPic() const; // returns the image

int getMonth() const;
int getYear() const;

void setPic(string newPic) const;

Date& operator=(const Date &otherDate);// operator overloading


string toString();

};

Goal:
Write the implementation files Date.cpp and Image.cpp.

Expected Output:
First Date : Date: 2/1/2019 Rose
Second Date: Date: 3/1/2019 Lily
Third Date: Date: 2/1/2019 Rose
Second Date is more recent
First Date now: Date: 2/1/2019 Change
Third Date now: Date: 2/1/2019 Rose
Fourth Date: Date: 3/1/2019 Lily
Second Date now: Date: 3/1/2019 Hibiscus
Fourth Date now: Date: 3/1/2019 Lily

In: Computer Science

Q#2 Write a C++ program that reads 10 integer values and stores them in an array....

Q#2
Write a C++ program that reads 10 integer values and stores them in an array. The program should find and display the average of the array elements and how many elements are below the average.

In: Computer Science

Q#3 Write a C++ program to read 10 temperatures in Celsius and to store the temperatures...

Q#3
Write a C++ program to read 10 temperatures in Celsius and to store the temperatures in an array of integers, then it should convert the temperatures to Fahrenheit and store the new values rounded to the nearest integer in another array . The program should display both temperatures in a table form.   
F = 9/5 x C + 32 where F is temp in Fahrenheit and C temperature in Celsius

In: Computer Science

list the different cabling types and their issues (deficiencies) that come up when you use them...

list the different cabling types and their issues (deficiencies) that come up when you use them in a network. What cable works the best or would you suggest and why?

This assignment should be a minimum of one page in length

In: Computer Science

I am to complete the following for Java but getting compiler errors...Implement a base class called...

I am to complete the following for Java but getting compiler errors...Implement a base class called Student that contains a name and major. Implement the subclass GraduateStudent, which adds a property called stipend.

Here is what I have for code with the compiler error following.

public class GraduateStudent extends Student {
  
   private double stipend;
  
   public GraduateStudent(String name, String major, double stipend) {
      
       super(name);
       super(major);
  
       this.stipend = stipend;
      
   }
  
   public void setStipend(double stipend) {
       this.stipend = stipend;
   }
  
   public double getStipend() {
       return stipend;
   }
}

public class Student {
  
protected String name;
protected String major;
  
public Student(String name, String major) {
this.name = name;
this.major = major;
}
  
public void setName(String name) {
this.name = name;
}
  
public String getName() {
return name;
}
  
public void setMajor(String major) {
this.major = major;
}
  
public String getMajor() {
return major;
}
}

GraduateStudent.java:7: error: constructor Student in class Student cannot be applied to given types;
                super(name);
                ^
  required: String,String
  found: String
  reason: actual and formal argument lists differ in length
GraduateStudent.java:8: error: call to super must be first statement in constructor
                super(major);
                     ^
2 errors
[ERROR] did not compile; check the compiler stack trace field for more info

PROGRAM EXECUTION STACK TRACE

[ERROR] did not compile; check the compiler stack trace field for more info

YOUR CODE'S OUTPUT

 
1 [ERROR] did not compile; check the compiler stack trace field for more info
2
3 false

In: Computer Science

Create a subclass of BinaryTree whose nodes have fields for storing preorder, post-order, and in-order numbers....

  1. Create a subclass of BinaryTree whose nodes have fields for storing preorder, post-order, and in-order numbers. Write methods preOrderNumber(), inOrderNumber(), and postOrderNumbers() that assign these numbers correctly. These methods should each run in O(n) time.

In: Computer Science

In this task you will complete the calculation and implement the Clear button. 1. When an...

In this task you will complete the calculation and implement the Clear button.

1. When an arithmetic operator is pressed retrieve the String from the JLabel, parse it to a Float value and assign it to a variable num1. Consult the Java API and the textbook to workout how to convert a String to a Float. Hint: use the same structure as when we convert a String to an Integer.

2. You should retrieve the operator and store it in a char variable op.

3. Follow the same procedure as before to input the second number. When the user presses the equals button retrieve the String from the label and assign the Float to a variable num2. Calculate the result and display it on the JLabel.

4. To complete the calculation define a private float method called calculate that accepts 3 parameters (char op, float num1, float num2). Use a switch statement to determine what operation to do and then return the result from the calculation.

5. Finally, if the user presses the Clear button then set num1 and num2 to 0 and set the text of the JLabel to 0.

import javax.swing.JFrame;
import javax.swing.*;
import java.awt.event.*;
/*
* Driver Class for the Calcultor
*
* @author
*/
public class CalculatorDriver {
public static void main(String[] args) {
// create JFrame object
JFrame frame=new JFrame("Simple Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create object of CalculatorPanel class
CalculatorPanel panel=new CalculatorPanel();
frame.getContentPane().add(panel); // add panel into frame
frame.pack();
frame.setResizable(false); // frame should not be resizable
frame.setLocation(400,300); // set location of frame
frame.setVisible(true); // make frame visible
}
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
* The calculator panel
* @author
*/
public class CalculatorPanel extends JPanel {
private static final long serialVersionUID = 1L;
private static final int CALC_WIDTH=250;
private static final int CALC_HEIGHT=225;

public CalculatorPanel() {
setLayout(new BorderLayout());
setBackground(Color.lightGray); // create the input/output panel
result = 0; // result variable of label
lastCommand = "=";
start = true;

// add the display
resultLabel = new JLabel("0", SwingConstants.RIGHT); // set the JLabel to RIGHT
resultLabel.setFont(new Font("Helvetica", Font.BOLD, 40)); // set the font size
add(resultLabel, BorderLayout.NORTH); // set the border layout to NORTH

// Action listener creates
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();

// CREATE A LAYOUT OF THE BUTTONS 4X4 grid
panel = new JPanel();
panel.setLayout(new GridLayout(4, 4)); //set the 4x4 grid
panel.setBackground(Color.DARK_GRAY); //set the background color

// add the button text and assign the action
addButton("7", insert);
addButton("8", insert);
addButton("9", insert);
addButton("/", command);
  
addButton("4", insert);
addButton("5", insert);
addButton("6", insert);
addButton("*", command);
  
addButton("1", insert);
addButton("2", insert);
addButton("3", insert);
addButton("-", command);

addButton("0", insert);
addButton(".", insert);
addButton("=", command);
addButton("+", command);
  
add(panel, BorderLayout.CENTER); // set the panel to center
}
  
// add button
private void addButton(String label, ActionListener listener) {
JButton button = new JButton(label);
button.setPreferredSize(new Dimension(55,30)); //set the button size
button.setFont(new Font("Helvetica", Font.BOLD, 15)); // set the font size
button.setForeground(Color.BLUE); //set the font color to blue
button.addActionListener(listener); // add the action listener
panel.add(button); // add the button to the panel
}

  
private class InsertAction implements ActionListener {
public void actionPerformed(ActionEvent event) {
String input = event.getActionCommand();
if (start) {
resultLabel.setText("");
start = false;
}
resultLabel.setText(resultLabel.getText() + input); //display the text to the label
}
}


private class CommandAction implements ActionListener {
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();

if (start) {
if (command.equals("-")) {
resultLabel.setText(command);
start = false;
} else
lastCommand = command;
} else {
calculate(Double.parseDouble(resultLabel.getText()));
lastCommand = command;
start = true;
}
}
}

// method that calculate the result of two inputs
public void calculate(double x) {
if (lastCommand.equals("+"))
result += x; // add
else if (lastCommand.equals("-"))
result -= x; // subtract
else if (lastCommand.equals("*"))
result *= x; // multiply
else if (lastCommand.equals("/"))
result /= x; // divide
else if (lastCommand.equals("="))
result = x; // equals
resultLabel.setText("" + result); // display the result to the label
}

//variables
private JLabel resultLabel;
private JPanel panel;
private double result;
private String lastCommand;
private boolean start;
}



  
  
/**
* Define the calculate method
* Perform the calculations on <i>num1</i> and <i>num2</i> depending on
* the operation <i>op</i>
* @param op the operation
* @param num1 the first number of the calculation
* @param num2 the second number of the calculation
* @return the result of the calculation
*/

Hello, I need a help for this section... Could you please resolve it? I need a code. It's java.

Thanks a lot!

In: Computer Science

1.Write a Java program that prompts the user for a month and day and then prints...

1.Write a Java program that prompts the user for a month and day and then prints the season determined by the following rules.

If an invalid value of month (<1 or >12) or invalid day is input, the program should display an error message and stop. Notice that whether the day is invalid depends on the month! You may assume that the user will never enter anything other than integers (no random strings or floats will be tested.)

Tips: Break this problem down into smaller pieces. This is always good practice when tackling a larger problem. Break it up into pieces that you can test individually and work on one piece at a time. You might try writing the pseudo-code for each piece.

First, see if you can get a month and ensure that it is valid. Test out only this piece of functionality before continuing. Make sure you test not only the good and bad cases, but also for boundary cases. For example, try entering -5, 0, 1, 4, 12, 13, and 56.

Next, see if you can get a day and ensure that it is valid. Test this piece too.

Finally, use the now-valid month and day to determine which season it is in. If you tested the earlier pieces, you will now know that any bugs are due to a problem here.

In: Computer Science

Objectives: • Learn to write test cases with Junit • Learn to debug code Problem: Sorting...

Objectives:

Learn to write test cases with Junit

Learn to debug code

Problem: Sorting Book Objects

Download the provided zipped folder from Canvas. The source java files and test cases are in

the provided

folder. The Book class models a book. A Book has a unique id, title, and author.

The BookStore class stores book objects in a List, internally stored as an ArrayList. Also, the

following methods are implemented for the BookStore class.

addBook(Book b):

sto

res the book in the book list.

getBookSortedByAuthor():

returns a book list sorted by author name descending

alphabetically.

getBooksSortedByTitle():

returns a book listed sorted by title descending alphabetically.

getBooks():

returns the current book list

.

deleteBook(Book b5):

removes the given book from the book list.

countBookWithTitle(String title):

iterates through the book list counting the number of

books with the given title. Returns the count of books with the same title.

Write test cases to test t

he implementation.

The test case method stubs have been created.

Fill out the method stubs. After filling in the test case method stubs, run BookStoreTest to test

the BookStore.java code. Find and fix bugs in the BookStore.java code by using the debugger o

n

the test case method stubs.

Grade:

For this lab, we will need to see either

1)

Fully functional code solving the problem as specified or

Book.java


public class Book {

   private int id; // the unique id assigned to book
   private String title; // book title
   private String authorName;// author of the book

   public Book() {
       super();
   }

   public Book(int id, String authorName, String title) {
       this.id = id;
       this.title = title;
       this.authorName = authorName;
   }

   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getAuthorName() {
       return authorName;
   }

   public void setAuthorName(String authorName) {
       this.authorName = authorName;
   }

   @Override
   public String toString() {
       return "\n Book [id=" + id + ", title=" + title + ", authorName="
               + authorName + "]";
   }

}

BookStore.java


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class BookStore {

   private List<Book> books; // store books in a list

   public BookStore() {
       books = new ArrayList<Book>();

   }

   public void addBook(Book b1) {
       books.add(b1);

   }

   public List<Book> getBooksSortedByAuthor() {
       List<Book> temp = new ArrayList<Book>(books);
       Collections.sort(temp, new Comparator<Book>() {
           public int compare(Book b1, Book b2) {
               return b1.getTitle().compareTo(b2.getAuthorName());
           }
       });
       return books;
   }

   public int countBookWithTitle(String title) {
       int count = 2;
       for (Book book : books) {
           if (book.getTitle() == title) {
               count++;
           }
       }
       return count;
   }

   public void deleteBook(Book b5) {
       books.remove(b5);
   }

   public List<Book> getBooks() {
       return books;
   }

   public List<Book> getBooksSortedByTitle() {
       List<Book> temp = new ArrayList<Book>(books);
       Collections.sort(temp, new Comparator<Book>() {
           public int compare(Book b1, Book b2) {
               return b1.getTitle().compareTo(b2.getAuthorName());
           }
       });
       return temp;
   }

}

BookStoreTest.java


import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

public class BookStoreTest {

   private BookStore store;
   private Book b1 = new Book(1, "Harper Lee", "To Kill a Mockingbird");
   private Book b2 = new Book(2, "Harper Lee", "To Kill a Mockingbird");
   private Book b3 = new Book(3, "Frances Hodgson", "The Secret Garden");
   private Book b4 = new Book(5, "J.K. Rowling",
           "Harry Potter and the Sorcerer's Stone");
   private Book b5 = new Book(4, "Douglas Adams",
           "The Hitchhiker's Guide to the Galaxy");

   /**
   * setup the store
   *
   */
   @Before
   public void setUpBookStore() {
       store = new BookStore();
       store.addBook(b1);
       store.addBook(b2);
       store.addBook(b3);
       store.addBook(b4);

   }

   /**
   * tests the addition of book
   *
   */

   @Test
   public void testAddBook() {
       store.addBook(b1);
       assertTrue(store.getBooks().contains(b1));

   }

   /**
   * tests the deletion of book
   *
   */

   @Test
   public void testDeleteBook() {

   }

   /**
   * tests sorting of books by author name
   *
   */

   @Test
   public void testGetBooksSortedByAuthor() {

   }

   /**
   * tests sorting of books by title
   *
   */

   @Test
   public void testGetBooksSortedByTitle() {

   }

   /**
   * tests the number of copies of book in store
   *
   */

   @Test
   public void testCountBookWithTitle() {

   }

}

In: Computer Science

Create a program in Java for storing the personal information of students and teachers of a...

Create a program in Java for storing the personal information of students and teachers of a school in a .csv (comma-separated values) file.

The program gets the personal information of individuals from the console and must store it in different rows of the output .csv file.

Input Format

User enters personal information of n students and teachers using the console in the following

format:

n

Position1 Name1 StudentID1 TeacherID1 Phone1

Position2 Name2 StudentID2 TeacherID2 Phone2

Position3 Name3 StudentID3 TeacherID3 Phone3

. . .

Positionn Namen StudentIDn TeacherIDn Phonen


Please note that the first line contains only an integer counting the number of lines

following the first line.

In each of the n given input lines,

  • Position must be one of the following three strings “student”, “teacher”, or “TA”.

  • Name must be a string of two words separated by a single comma only.

  • StudentID and TeacherID must be either “0” or a string of 5 digits. If Position is “teacher”, StudentID is zero, but TeacherID is not zero. If Position is “student”, TeacherID is zero, but StudentID is not zero. If Position is “TA”, neither StudentID nor TeacherID are zero.

  • Phone is a string of 10 digits.


If the user enters information in a way that is not consistent with the mentioned format,

your program must use exception handling techniques to gracefully handle the situation

by printing a message on the screen asking the user to partially/completely re-enter the

information that was previously entered in a wrong format.



Data Structure, Interface and Classes

Your program must have an interface called “CSVPrintable” containing the following three methods:

  • String getName ();

  • int getID ();

  • void csvPrintln ( PrintWriter out);

You need to have two classes called “Student” and “Teacher” implementing CSVPrintable

interface and another class called “TA” extending Student class. Both Student and Teacher classes must have appropriate variables to store Name and ID.

In order to store Phone, Student class must have a phone variable of type long that can store a 10-digit integer; while the Teacher class must have a phone variable of type int to store only the 4-digit postfix of the phone number.

Method getName has to be implemented by both Student and Teacher classes in the same way. Class Student must implement getID in a way that it returns the StudentID and ignores the TeacherID given by the input. Class Teacher must implement getID in a way that it returns the TeacherID and ignores the StudentID given by the input. Class TA must override the Student implementation of getID so that it returns the maximum value of StudentID and TeacherID.

Method csvPrintln has to be implemented by Student and Teacher classes (and overridden by TA class) so that it writes the following string followed by a new line on the output stream out:

getName() + “,” + getID() + “,” + phone



Output .csv File

The program must store the personal information of students, teachers and TAs in a commaseparated values (.csv) file called “out.csv”. You need to construct the output file by repetitively calling the csvPrintln method of every CSVPrintable object instantiated in your program. The output .csv file stores the information of every individual in a separate row; while each column of the file stores different type of information regarding the students and teachers (i.e. Name, ID and phone columns). Please note that you should be able to open the output file of your program using MS-Excel and view it as a table.

Sample Input/Output

Assume that the user enters the following four lines in console:

Teacher Alex,Martinez 0 98765 3053489999

Student Rose,Gonzales 56789 0 9876543210

TA John,Cruz 88888 99999 1234567890

The program must write the following content in the out.csv file.

Alex Martinez,98765,9999

Rose Gonzales,56789,9876543210

John Cruz,99999,1234567890

In: Computer Science

How is a const pointer similar and different from a reference variable? And please give a...

How is a const pointer similar and different from a reference variable? And please give a good example.

Please help! Thank you!

In: Computer Science

C++ language Briefly explain and write the pseudocode to delete an element from the red-black tree....

C++ language

Briefly explain and write the pseudocode to delete an element from the red-black tree. Include all cases for full credit.

In: Computer Science

This is a question about C# programming: True / False questions: for (int i=5; i <...

This is a question about C# programming:

True / False questions:

for (int i=5; i < 55; i+=5)
{ decimal decPrcPerGal = decGalPrc + i;
decPayPrc = iBuyGall * decPrcPerGal;
if (decPrcPerGal > decMAX_GALPRC) { continue; }
if (decPrcPerGal > decMAX_GALPRC) { break; }
Console.WriteLine(" {1} gallon(s) at {0,3} would cost {2,8:$###,##0.00}", decPrcPerGal, iBuyGall, decPayPrc); }

In the code above:

1. If decGalPrc is 10.57 decPrcPerGal will always be some number of dollars and 57 cents   True/ False?
2. In some cases, the loop’s code block will run several times without showing anything on the console True/ False?
3. Removing only the code if (decPrcPerGal > decMAX_GALPRC) { continue; } would change the output of the program   True/ False?
4. Removing only the code if (decPrcPerGal > decMAX_GALPRC) { break; } would change the output of the program True/ False?
5. Removing the code if (decPrcPerGal > decMAX_GALPRC) { continue; } Would allow the program to avoid performing some unnecessary steps   True/ False?

In: Computer Science

In Java 1a. Declare a legal identifier for a variable called test as type double. 1b....

In Java

1a. Declare a legal identifier for a variable called test as type double.

1b. Create an if.. else statement that will display You get an A if grade is at least 95 else it will display Maybe you get an A next time

In: Computer Science