Adding on to 5-8b with the rectangle - cube inheritance, we add on another subclass of rectangle for a colored rectangle that adds a new field for the color, the constructors should either set an argument to the color or initialize the color to a default blue, and the print should call the rectangle print and then add on a statement to print the color. The new version of the super class and two sub classes are attached. Create a main that declares an array of three rectangle pointers. Each element should be a different kind of object that “is a” rectangle (rectangle, cube, colored rectangle), then separately run the three different constructors (you can send it any values that match up with the argument constructors) and assign to each element of the array (ex. spot 0 rectangle, spot 1 cube, spot 2 colored rectangle). Then in a for loop, print the address of each object that "is a" rectangle (the address in the pointer) and then use dynamic binding to call the print function to print each of the objects in the array.
/rectangle5-12.h
#ifndef rectangle512_h
#define rectangle512_h
#include<iostream>
using namespace std;
class rectangle512
{
protected:
float length;
float width;
float area;
float perimeter;
public:
rectangle512()
{
length = 1;
width = 1;
area = 1;
perimeter = 4;
}
rectangle512(float l, float w)
{
length = l;
width = w;
area = length * width;
perimeter = 2 * (length + width);
}
void virtual print()
{
cout << "Length is " << length << endl;
cout << "Width is " << width << endl;
cout << "Area is " << area << endl;
cout << "Perimeter is " << perimeter <<
endl;
}
};
#endif
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//colorrectangle5-12.h
#include"rectangle5-12.h"
#include<iostream>
#include<cstring>
using namespace std;
class colorrectangle512 : public rectangle512
{
private:
char color[20];
public:
colorrectangle512() : rectangle512()
{
strcpy(color, "blue");
}
colorrectangle512(float l, float w, char c[]) : rectangle512(l,
w)
{
strcpy(color, c);
}
void print()
{
rectangle512::print();
cout << "Color is " << color << endl;
}
};
---------------------------------------------------------------------------------------------------------------------------------------
//cube5-12.h
#include"rectangle5-12.h"
#include<iostream>
using namespace std;
class cube512 : public rectangle512
{
private:
float depth;
public:
cube512() : rectangle512()
{
depth = 1;
area = 2 * length * width + 2 * length * depth +
2 * width * depth;
perimeter = 2 * (length + width) + 2 * (length + depth) +
2 * (width + depth);
}
cube512(float l, float w, float d) : rectangle512(l, w)
{
depth = d;
area = 2 * length * width + 2 * length * depth +
2 * width * depth;
perimeter = 2 * (length + width) + 2 * (length + depth) +
2 * (width + depth);
}
void print()
{
rectangle512::print();
cout << "Depth is " << depth << endl;
}
};
In: Computer Science
A faculty has many departments. A department belong to one faculty.
Faculty has Faculty ID, Faculty name, Faculty Address
Department has Department ID, Department name
Department can have many teachers. Teacher only belongs to one department,
Teacher has teacherID, teacher_name, teacher_address and phone_number
Teacher can teach many students. Student can be taught by many teachers.
Student has student_id and student_name
Student can register many courses. Courses can be registered by many students
Course has courseID, course_name
Department can have many courses. Course belong to one department
In: Computer Science
/**
* This class maintains an arbitrary length list of integers.
*
* In this version:
* 1. The size of the list is fixed after the object is
created.
* 2. The code assumes there is at least one element in the
list.
*
* This class introduces the use of loops.
*
* @author Raymond Lister
* @version September 2015
*
*/
public class ListOfNVersion02PartA
{
public int[] list; // Note: no "= {0, 1, 2, 3}" now
/**
* This constructor initializes the list to the same values
* as in the parameter.
*
* @param element the initial elements for the list
*/
public ListOfNVersion02PartA(int [] element)
{
// make "list" be an array the same size as "element"
list = new int[element.length];
// add whatever code is required to complete the constructor
} // constructor ListOfNVersion01Skeleton(int [] element)
/**
* @return the number of elements stored in this list
*/
public int getListSize()
{
return 999; // replace "999" with the correct answer
/* See Nielsen page 85-86,
* section 4.2.3 Retrieving the size of arrays: length
*
* See Parsons page 45,
* section 3.3.4 The Array “length” Field and also page 47
*/
} // method getListSize
/**
* @return the last element in the list
*/
public int getLast()
{
return 999; // replace "999" with the correct answer
/* See Nielsen page 85-86,
* section 4.2.3 Retrieving the size of arrays: length
*
* See Parsons page 45,
* section 3.3.4 The Array “length” Field and also page 47
*/
} // method getLast
/**
* prints the contents of the list, in order from first to
last
*/
public void printList()
{
System.out.print("{");
// add and/or modify code to complete the method
System.out.print("}");
} // method printList
/**
* This method is NOT examinable in this test.
*
* prints the contents of the list, in order from first to last,
and
* then moves the cursor to the next line
*/
public void printlnList()
{
printList();
System.out.println();
} // method printlnList
/**
* @return the number of times the element occurs in the list
*
* @param element the element to be counted
*/
public int countElement(int element)
{
// add and/or modify code to complete the method
return 999;
} // method countElement
/**
* @return the number of times the replacement was made
*
* @param replaceThis the element to be replaced
* @param withThis the replacement
*/
public int replaceAll(int replaceThis, int withThis)
{
// add and/or modify code to complete the method
return 999;
} // method replaceAll
/**
* @return the first position in list occupied by the parameter
value, or -1 if it is not found
*
* @param findThis the value to be found
*/
public int findUnSorted(int findThis)
{
// This algorithm is known as "linear search"
return 999;
// add and/or modify code to complete the method
} // method findUnSorted
/**
* @return the position of the smallest element in the array,
between positions "first" and "last"
*/
public int minPos()
{
return 999;
// add and/or modify code to complete the method
} // method minPos
/**
* Inserts an element in the last position. The elements already in
the
* list are pushed down one place, and the element that was
previously
* first is lost from the list.
*
* @param newElement the element to be inserted
*/
public void insertLast(int newElement)
{
// add and/or modify code to complete the method
} // method insertLast
} // class ListOfNVersion02PartA
In: Computer Science
a) Find a bug in the code snippet below. Assume that a, b, c and d are correctly declared and initialized integer variables.
a = b+c if (a=d) then
print *,”A equals to D” else
print *,”A does not equal D” end if
b) Find a bug in the code snippet below. Assume that a,b,and c are correctly declared and initialized integer variables.
if (a+b) > c) then print *,”Sum of A+B is greater than C”
end if
In: Computer Science
Write a series of codes using WHILE loops C++
1. Ask the user for a number and adds even numbers for 1 to the user entered number.
2. Write another piece of code that asks the user for 2 numbers and adds up the numbers between and including the numbers.
3. Write another piece of code that asks user for a file name and then add up all the numbers for the file.
In: Computer Science
Analysis of Algorithims
Bubble sort for 12, 2, 3, 21, 11, 10,8
Binary search for K=12 in the array A={2, 3, 5, 7,11,15, 16,18,19}
selection sort for 12, 2, 3, 21, 11, 10,8
In: Computer Science
*Need 200 words for all 6 questions in total with some websites for resources*
In: Computer Science
Write this code in Python only.
Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.
In: Computer Science
Explain "In a virtual network, service is described in a data structure, and exists entirely in a software abstraction layer, reproducing the service on any physical resource running the virtualization software.
The configuration attributes of the service can be found in software with API interfaces, thereby unlocking the full potential of networking devices."
In: Computer Science
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level.
Example:
$ ./compare Enter starting date: 09/13/2018 Enter ending date: 09/17/2018 09/13/2018 West 09/14/2018 West 09/15/2018 West 09/16/2018 West 09/17/2018 West
Explanation:
| Date | East (ft) | West (ft) | |
|---|---|---|---|
| 09/13/2018 | 581.94 | 582.66 | West is higher |
| 09/14/2018 | 581.8 | 582.32 | West is higher |
| 09/15/2018 | 581.62 | 581.94 | West is higher |
| 09/16/2018 | 581.42 | 581.55 | West is higher |
| 09/17/2018 | 581.16 | 581.2 | West is higher |
In: Computer Science
First, Calculate the 1/3 in binary form using 8-digits. Then convert binary form back to decimal. Why and what is the error in binary representation ?
In: Computer Science
The coding must be formatted in Python.
Write a function matrix_power(A, n) that computes the power An using Boolean arithmetic and returns the result. You may assume that A is a 2D list containing only 0s and 1s, A is square (same number of rows and columns), and n is an integer ≥ 1. You should call your previously written matrix multiply boolean function. Example: Let R = [ [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0] ] Then calling matrix power(R, 2) should return [ [0, 0, 1, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1] ]
In: Computer Science
Maze in C++
Simple Maze Program – Project Specifications:
1. Create a simple maze game that a player must traverse to win.
3. The maze must be text-based and adjustable from 5x5 to 20x20. • Player gets to choose size either as:
1) any size in the range from 5-20 by 5-20. 2) selects from 4 set size options [5x5,10x10,15x15, and 20x20] • the player can choose among different mazes. • You will need to figure out how to denote your location in the maze.
For a 5x5 maze you have 25 actual spots that are valid, if you can get to them. • You will need to figure out a way to know if you can move in a particular direction or not. You cannot move East if there is a wall to your East.
4. The maze must be displayed with a current position of the player after each move. • Display the Text-based Maze to the player - top-down view • Players sees the maze layout (walls and openings), but not what is in each maze area (e.g. Items, locked door, or mobs)
5. The maze must contain Randomized Items for the player to pick up or interact with: • At the start of the game -- Items are randomly placed in the maze • Only story specific items at the starting and ending locations, do not need to be randomized.
Some suggestion for Classes:
1. Maze -- data and functions associated with maintaining and drawing the maze
2. Items -- data and functions associated with each object in the maze
3. Player -- data and functions associated with the player
4. Backpack -- data and functions associated with stuff player picks up in maze
Some suggestion for Functions – mostly if classes not used:
1. Function to display Maze Game Introduction.
2. Function to display Game Help.
3. Function to display the maze for the player.
4. Function to get move direction from player.
5. Function to display information about current location.
6. Function to display information about a specific item.
7. Function to display current inventory
8. Function to display menu or user prompt for next command.
9. Function to display whether the player won or lost
11.The Maze Game Program needs to include:
• A game introduction displayed to the player to welcome them to the game. • Initialize all the game elements.
• Create a Play Again Loop so the player can play again.
• Create an internal Game Loop so that the player can progress through the game one command at a time.
• User Prompts to let the player know how to interact with the game and what commands are valid at this time. This prompt can either be 1 line or a menu display. • A help display on command.
• Quit must be accepted as a command to stop the game at any time. • The maze must be displayed with current position after every command is acted upon.
• You must give the player information/feedback of their current position and what is around them (like items) after each command to let them know their status.
• You must let the player know they won or lost or quit to end the play Game Loop.
• A game farewell message must be given before you end the game.
In: Computer Science
Write a MARIE assembly language program that will read an “array” of positive decimal values stored in memory and output the smallest value. Use variable addr to store the location of the first data item. Use variable length to store the number of items in your array.
Your code should be organized such that adding an additional array item would only involve adding the data line (ie. 021 dec 400) and updating the length variable (ie. length, dec 5). You can assume there will be at least one data value.
Use comments throughout your program. Save your program as h9part1.mas and upload to our course web site.
/sample data, note: addresses will vary depending on your implementation
015 addr, hex 017
016 length, dec 4
017 dec 100
018 dec 200
019 dec 50
020 dec 300
In: Computer Science
Java Programming Problem:
Define a generic method called checkOrder() that checks if four items are in ascending, neither, or descending order. The method should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order.
The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, Strings, characters, or doubles.
Ex. If the input is:
bat hat mat sat 63.2 96.5 100.1 123.5
the output is:
Order: -1 Order: -1
The following is the current code for the problem:
import java.util.Scanner;
public class WhatOrder {
// TODO: Define a generic method called checkOrder() that
// takes in four variables of generic type as arguments.
// The return type of the method is integer
// Check the order of the input: return -1 for ascending,
// 0 for neither, 1 for descending
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Check order of four strings
System.out.println("Order: " + checkOrder(scnr.next(), scnr.next(),
scnr.next(), scnr.next()));
// Check order of four doubles
System.out.println("Order: " + checkOrder(scnr.nextDouble(),
scnr.nextDouble(), scnr.nextDouble(), scnr.nextDouble()));
}
}
In: Computer Science