Questions
Can this code be rewritten but keeping the same functions as the original and with detailed...

Can this code be rewritten but keeping the same functions as the original and with detailed comments. I'm going to post the original homework lab just in case.

Attached to this assignment is a Java program that converts a text file to a list of hexadecimal numbers. Each of those hexidecimal numbers represents the bit pattern of a character from the file with the parity bits (even parity) for a hamming code inserted. Each text character takes 8 bits and the hamming code adds 4 bits. This hamming code provides single-bit error correction. Requirements 1. The program must be written in Java. If you have not used Java before, you can learn it enough to do this assignment, by looking at the provided program. 2. You can use Eclipse to write, compile and test your program, but you may also use any other development environment you like. Only the .java file will be submitted. 3. The program will use the provided Hamming class. It will implement the decode function. The decode function is the reverse of the encode function, but it also performs single bit correction when necessary. 4. Display a message to the console when an error is corrected, as in the example below. 5. The main function must be rewritten to read hexidecimal numbers from hamming.txt file and write decoded and corrected text to output.txt. 6. Test the program with different input files. The instructor will test it with a hamming.txt file different from the one provided.

import java.io.*;
import java.util.*;
public  class Hamming
        {
        private char letter;     
        private int[] bits = new int[12];
        private int code;         
        public Hamming(char let) { letter = let; encode(); }
        public Hamming(int c) { code = c; decode(); }
        public int getCode() { return code; }
        public char getLetter() { return letter; }

        private void encode() {
                int value = letter;
                        for (int i = 0; i < 12; i++) {
                        if (i != 0 && i != 1 && i != 3 && i != 7) {
                                bits[i] = value % 2;
                                value /= 2;
                        }
                }
                
                bits[0] = bits[2] ^ bits[4] ^ bits[6] ^ bits[8] ^ bits[10]; // ^ is XOR in Java
                bits[1] = bits[2] ^ bits[5] ^ bits[6] ^ bits[9] ^ bits[10];
                bits[3] = bits[4] ^ bits[5] ^ bits[6] ^ bits[11];
                bits[7] = bits[8] ^ bits[9] ^ bits[10] ^ bits[11];

                code = 0;
                for (int i = 11; i >= 0; i--) {
                        code *= 2;
                        code += bits[i];
                }
        }

        private void decode() {
                int error = 0;
                int value = code;


                for (int i = 0; i < 12; i++) {
                        bits[i] = value % 2;
                        value /= 2;
                }


                if (bits[0] != (bits[2] ^ bits[4] ^ bits[6] ^ bits[8] ^ bits[10])) error += 1; 
                if (bits[1] != (bits[2] ^ bits[5] ^ bits[6] ^ bits[9] ^ bits[10])) error += 2;
                if (bits[3] != (bits[4] ^ bits[5] ^ bits[6] ^ bits[11])) error += 4;
                if (bits[7] != (bits[8] ^ bits[9] ^ bits[10] ^ bits[11])) error += 8;
                

                if (error != 0)
                        bits[error - 1] ^= 1;


                letter = 0;
                for (int i = 11; i >= 0; i--) {
                        if (i != 0 && i != 1 && i != 3 && i != 7) {
                                letter *= 2;
                                letter += bits[i];
                        }
                }

                if (error != 0)
                        System.out.println("Error in bit " + (error - 1) + " corrected in character " + letter);
        }

        public static void main(String[] args) throws FileNotFoundException
        {
                Scanner  inFile = new Scanner( new File("hamming.txt"));
                PrintStream outFile = new PrintStream(new File("output.txt"));
                String line;
                int code;
                        
                System.out.println("File hamming.txt opened");  
                while (inFile.hasNextInt(16)) {
                                code = inFile.nextInt(16);
                        
                                
                
                                Hamming ham = new Hamming(code);
                                        

                                outFile.print(ham.getLetter()); 
                        
                        }
                inFile.close();
                System.out.println("File output.txt closed");
        }
}

In: Computer Science

C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...

C# ( asp.net ) 2019 visual studio

I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format.

How can I sort these dates in ascending order?. Can you provide me some code. Thank you

In: Computer Science

Describe and discuss the main elements of the Entity-Relationship (E-R) model. Include an example. Briefly describe...

  1. Describe and discuss the main elements of the Entity-Relationship (E-R) model. Include an example.
  2. Briefly describe the process of converting an extended E-R model into a relational database design.
  3. How are one-to-many recursive relationships addressed using the relational model?
  4. Explain the representation of a one-to-many strong entity relationship in a relational database design.

In: Computer Science

Please answer these questions Data Processing and Analysis using python. Thank you Explain what does each...

Please answer these questions Data Processing and Analysis using python. Thank you

Explain what does each of the following functions do:

1. numpy.mean()

2. pandas.read_csv()

3. matplotlib.pyplot.plot()

In: Computer Science

// I can't get my cpp file to work with my header file and it always...

// I can't get my cpp file to work with my header file and it always says the error comes from compatibility I am using Visual Studio 2015 below is the error only my file path and program name has been erased. The issue comes up in my cpp file with the size_t empty and full functions.

// Error (active)       declaration is incompatible with "bool ListType::empty()" (declared at line 12 of ListType.h)        

// ListType header file

#ifndef ListType__h
#define ListType__h
#include
class ListType {
public:
   ListType();
   bool insert(int value);
   void eraseAll();
   void erase(int);
   bool find(int );
   size_t size();
   bool empty();
   bool full();
   const ListType & operator = (const ListType &other);
   friend std :: ostream & operator << (std :: ostream &out, const ListType &list);
protected:
   int list[100];
   size_t capacity;
   size_t count;
private:
};
#endif /* ListType__h */

//my cpp file

#include "ListType.h"
#include

ListType::ListType() {
   capacity = 100;
   count = 0;
}

bool ListType::insert(int value)
{
   bool result = false;
   if (!full()) {
       list[count] = value;
       ++count;
       result = true;

   }
   return result;
}

void ListType::eraseAll() {
   count = 0;
}
void ListType::erase(int value) {
   size_t i = 0;
   while (i < count&&value != list[i])++i;
   if (i < count) {
       list[i] = list[--count];
   }

}

bool ListType::find(int value) {
   bool result = false;
   if (!empty()) {
       size_t i = 0;
       while (i        result = (i    }
   return result;
}


size_t ListType::size() {
   return count;
}
size_t ListType::empty() {
   return count = 0;
}
size_t ListType::full() {
   return count == capacity;
}

const ListType& ListType:: operator=(const ListType& source) {
   if (this != &source) {
       count = source.count;
       for (size_t i = 0; i            list[i] = source.list[i];
       }
   }
   return *this;
}
std::ostream& operator<<(std::ostream &out, const ListType &other)

{

   out << "[ ";

   for (unsigned int i = 0;i

   {

       out << other.list[i] << " ";

   }

   out << "]";

   return out;

}

In: Computer Science

why do microwave antennas need line-of sight(los) communication. Rainfall affects both microwave communication and radio broiadcasting...

why do microwave antennas need line-of sight(los) communication. Rainfall affects both microwave communication and radio broiadcasting communication , which one will be more affected by rainfall?

In: Computer Science

Write a program in Java that reads in a set of positive integers and outputs how...

Write a program in Java that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data 15 40 28 62 95 15 28 13 62 65 48 95 65 62 65 95 95 -999

The output is

Number Count

13 1

15 2

28 2

40 1

48 1

62 3

65 3

95 4

In: Computer Science

Python Programming An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also...

Python Programming

An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 and 71 are prime numbers, so 17 and 71 are emirps. Write a program that displays the first 10 emirps.

In: Computer Science

C++ program that reads a positive integer number from a user and displays all binary numbers...

C++ program that reads a positive integer number from a user and displays all binary numbers from 0 to the number.

For the program, you can assume that the input number is a number between 0 and 100.

Sample Run 1: Assume that the user typed the following number.

5

This is the correct output of your program.

000

001

010

011

100

101

Sample Run 2: Assume that the user typed the following number.

0

This is the correct output of your program.

0

Sample Run 3: Assume that the user typed the following number.

3

This is the correct output of your program.

00

01

10

11

In: Computer Science

Creating Enumerations In this section, you create two enumerations that hold colors and car model types....

Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used.

1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW};

2. Save the file as Color.java.

3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN};

4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color.

public class Car {

private int year;

private Model model;

private Color color;

5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows:

public Car(int yr, Model m, Color c) {

year = yr;

model = m;

color = c;

}

6. Add a display() method that displays a Car object’s data, then add a closing curly brace for the class.

public void display() {

System.out.println("Car is a " + year + " " + color + " " + model);

}

}

7. Save the file as Car.java.

8. Open a new file in your text editor, and write a short demonstration program that instantiates two Car objects and assigns values to them using enumeration values for the models and colors.

public class CarDemo {

public static void main(String[] args) {

Car firstCar = new Car(2014, Model.MINIVAN, Color.BLUE);

Car secondcar = new Car(2017, Model.CONVERTIBLE, Color.RED);

firstCar.display();

secondcar.display();

}

}

9. Save the file as CarDemo.java, and then compile and execute it.

the output should be something like

"Car is a 2014 BLUE MINIVAN

Car is a 2017 RED CONVERTIBLE"

in Java

In: Computer Science

Here is the problem I am working on. I need to write a py program that:...

Here is the problem I am working on. I need to write a py program that:

Calculates a Cartesian Product Output, A x B of 2 lists. I want to limit each list to 5 numbers. It is kind of working, but I can't help think that there is a simpler way to express this problem. Please advise...

Here is my code:

def CartesianProductOutput(A,B):

    lst = []

    for x in A:

        t = []

        t.append(x)

        for y in B:

            temp = []

            for x in t:

                temp.append(x)

            temp.append(y)

            lst.append(temp)

    return lst

A = [1,2,3,4,5]

B = [1,2,3,4,5]

print(CartesianProductOutput(A,B))

In: Computer Science

Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer...

Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer help and guidance on this subject

can someone help he with part 4 i have no idea how to approach the problem and how to do it

I have compeleted a few parts to this project they are listed below

Part 1 – Displaying Cards Write a function to display (print) a card. sample program output void displayCard(int card) Prints the name of the card (ten of spades, queen of diamonds etc.). The parameter should be a value between 1 and 13, from which the type of card can be determined (1 = ace, 2 = two, …, 10, == ten, 11 = jack, 12 = queen, 13 = king). The card suit (clubs, diamonds, hearts or spades) should be determined randomly.

Part 2 – Generating Cards Write a function to get a card. int getCard() Returns a random value between 1 and 13, representing a card (ace, 2, …, queen, king). You do not have to keep track of which cards are dealt. So, if the game deals the queen of spades five times in row that is perfectly acceptable.

Part 3 – Determining a Cards Score Write a function to return a card's score. int cardScore(int card) Returns a value between 2 and 11 as described in the rules. Recall that the score is the card's value except that aces are worth 11 and face cards are worth 10. The card parameter represents the card for which the score is to be determined.

Part 4 – Dealing Cards Now that you've completed Parts 1 and 2 you can write a function that handles dealing cards. int deal(bool isPlayer, bool isShown) This function is responsible for: 1. Generating the next card to be dealt (Part 1) 2. Printing out what card was dealt (Part 2) and to whom, if needed (see below) 3. Returning the card's score (Part 3) The two Boolean parameters are related to printing out the card. The isPlayer parameter is used to determine whether the word PLAYER or DEALER should be printed at the start of the output. The isShown parameter is used to determine if the card should be printed – recall that the second card dealt to the dealer is hidden.

MYCODE

#include

#include

#include

#include

using namespace std;

void displaycard(int card, int suits){

string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };

cout << cardtype[card];

string suit[4]={" hearts"," diamonds"," spades"," clubs"};

cout << suit[suits];

}

int getcard(){

int card;

card = rand()%13;

return card;

}

int getsuit(){

int suits;

suits = rand() % 4;

return suits;

}

int cardScore(int card)

{

if (card == 11 || card == 12 || card == 13)

{

card = 10;

}

else if (card == 1)

{

card = 11;

}

else

{

card = card;

}

return card;

}

int deal(bool isPlayer, bool isShown){

int cardWhom;

int dealer;

if (cardWhom == true||dealer == true ){

cout << "PLAYER"<< endl;

}

else {

cout << "DEALER" << endl;

}

}

int main(){

srand((unsigned)time(0));

return 0;

}

In: Computer Science

IMPLEMENT the Following instructions into the String.hpp and String.cpp provided. DO NOT just simply copy the...

IMPLEMENT the Following instructions into the String.hpp and String.cpp provided. DO NOT just simply copy the code I give you as your answer

Intructions:

Implementation:

For your String class:

Implement method String String::substr(int start_pos, int count) const;. This will return the specified substring starting at start_pos and consisting of count characters (there will be less than count if it extends past the end of the string).

Implement method int String::find(char ch, int start_pos) const; which gives the first location starting at start_pos of the character ch or -1 if not found.

Implement method int String::find(const String & s, int start_pos) const; which gives the first location starting at start_pos of the substring s or -1 if not found.

Implement a method std::vector<String> String::split(char) const;

You will use std::vector<> (need to include <vector>) for storing the results of parsing the input data.

This method will return a vector of String split up based on a supplied character. For example given s = "abc ef gh", the call s.split(' ') will return a vector with three strings: "abc", "ef", and "gh".

std::vector has a number of operations defined including operator[], and size (number of elements in the vector).

-------------------------------------------------------------------------------------

string.hpp

-------------------------------------------------------------------------------------

#ifndef STRING_HPP
#define STRING_HPP

#include <iostream>

/**
 * @invariant str[length()] == 0
 *         && length()      == capacity()
 *         && capacity()    == stringSize - 1
 */
class String {
private:
    // helper constructors and methods
    String(int);
    String(int, const char *);
    void reset_capacity (int);

    char * str;

    // size includes NULL terminator
    int string_size;

public:

    // constructor: empty string, String('x'), and String("abcd")
    String();
    String(char);
    String(const char *);

    // copy ctor, destructor, constant time swap, and assignment
    String(const String &);
    ~String();
    void     swap          (String &);
    String & operator=     (String);

    // subscript: accessor/modifier and accessor
    char & operator[](int);
    char   operator[](int) const;

    // max chars that can be stored (not including null terminator)
    int capacity()      const;
    // number of char in string
    int length  ()      const;

    // concatenation
    String   operator+ (const String &) const;
    String & operator+=(String);

    // relational methods
    bool operator==(const String &)  const;
    bool operator< (const String &)  const;

    // i/o
    friend std::ostream& operator<<(std::ostream &, const String &);
    friend std::istream& operator>>(std::istream &, String &);

};

// free functios for concatenation and relational
String operator+       (const char *,   const String &);
String operator+       (char,           const String &);
bool   operator==      (const char *,   const String &);
bool   operator==      (char,           const String &);
bool   operator<       (const char *,   const String &);
bool   operator<       (char,           const String &);
bool   operator<=      (const String &, const String &);
bool   operator!=      (const String &, const String &);
bool   operator>=      (const String &, const String &);
bool   operator>       (const String &, const String &);

#endif

-------------------------------------------------------------------------------

string.cpp

-------------------------------------------------------------------------------

#include <cstring>
#include <iostream>
#include <cassert>
#include "string.hpp"

String::String(int n){
  string_size = n;
  str = new char[n];
  str[0] = '\0';
}

String::~String(){
  delete [] str;
}

String::String(int x, const char *str1){
  string_size = x;  
  str = new char[x];
  int pos = 0;

  while(str1[pos] != '\0')
    {
      str[pos] = str1[pos];
      ++pos;
    }
  str[pos] = '\0';
 }

void String::reset_capacity(int x){
  String str1(x, str);
  swap(str1);
}

String::String(){
  str = new char[1];
  str[0] = '\0';
  string_size = 1;
}

String::String(char ch){
  string_size = 2;
  str = new char[string_size];
  str[0] = ch;
  str[1] = '\0';
}

String::String(const char* s){
  int counter = 0;
  while(s[counter] != '\0'){
    ++counter;
  }
  string_size = counter + 1;
  str = new char[string_size];
  for(int i = 0; i < counter ; i++){
    str[i] = s[i];
    }
  str[counter] = '\0';
}

String::String(const String& s){
  string_size = s.string_size;
  str = new char[string_size];
  int pos = 0;
  for(int i = 0; i < string_size; ++i){
    str[i] = s.str[i];
    ++pos;
  }
}

int String::length() const{
  int size = 0;
  while(str[size] != '\0')
    ++size;
  return size;        
}

int String::capacity() const{
  return string_size - 1;
}

String& String::operator=(String str1){
  string_size = str1.string_size;
  for(int i = 0; i < string_size; i++){
    str[i] = str1.str[i];
  }
  return *this;
}

char& String::operator[](int i){
  assert(i >= 0);
  assert(i <= length());

  return str[i];
}

void String::swap(String& str1){
  int tempStr = string_size;
  string_size = str1.string_size;
  str1.string_size = tempStr;

  char* tempStr1 = str;
  str = str1.str;
  str1.str = tempStr1;
}

char String::operator[](int i) const{
  assert(i >= 0);
  assert(i <= length());

  return str[i];
}

bool String::operator==(const String& rhs) const{
  int pos = 0;
  while(str[pos] != '\0' && str[pos] == rhs.str[pos]){
    ++pos;
  }
  return str[pos] == rhs.str[pos];
}

std::istream& operator>>(std::istream& in, String& rhs){
  in >> rhs.str;
  return in;
}

std::ostream& operator<<(std::ostream& out, const String& rhs){
  out << rhs.str;
  return out;
}
        
bool String::operator<(const String& rhs) const{
  int pos = 0;
  while(str[pos] != '\0' && rhs.str[pos] != '\0' && str[pos] == rhs.str[pos]){
    ++pos;
  }
  return str[pos] < rhs.str[pos];
}

String String::operator+(const String& rhs) const{
  int offset2 = (length() + rhs.length()) + 1;
  String result(offset2);
  int offset = length();
  int count = 0;
  int pos = 0;
  
  while(str[count] != '\0'){
    result.str[count] = str[count];
    ++count;
  }
  
  while(rhs.str[pos] != '\0'){
    result.str[offset + pos] = rhs.str[pos];
    ++pos;
  }

  result.str[offset2 - 1] = '\0';
  
  return result;
}

String& String::operator+=(String rhs){
  int offset = length();
  int pos = 0;
 
  int newSize = (length() + rhs.length()) + 1;
  String result(newSize);
  reset_capacity(newSize);

  for(int x = offset; x < newSize; ++x){
    str[x] = rhs.str[pos];
    ++pos;
  }
  str[newSize - 1] = '\0';
  return *this;
}

String operator+(const char charArray[], const String& rhs){
  String s(charArray);
  return rhs + s;
}

String operator+(char s, const String& rhs){
  return s + rhs;
}

bool operator==(const char charArray[], const String& rhs){
  if(charArray == rhs){
    return true;
  }
  else{
    return false;
  }
}

bool operator==(char s, const String& rhs){
  if(s == rhs){
    return true;
  }
  else{
    return false;
  }
}

bool operator<(const char charArray[], const String& rhs){
  if(charArray < rhs){
    return true;
  }
  else{
    return false;
  }
}

bool operator<(char s, const String& rhs){
  if(s < rhs){
    return true;
  }
  else{
    return false;
  }
}

bool operator<=(const String& lhs, const String& rhs){
  if(lhs < rhs || lhs == rhs){
    return true;
  }
  else{
    return false;
  }
}

bool operator!=(const String& lhs, const String& rhs){
  if(lhs.length() != rhs.length()){
    return true;
  }
  int pos = 0;
  while(lhs[pos] != rhs[pos]){
    pos++;
  }
  if(pos == lhs.length()){
    return true;
    }
  return false;
}

bool operator>=(const String& lhs, const String& rhs){
  if(lhs > rhs || lhs == rhs) {
    return true;
  }
  else{
    return false;
  }
}

bool operator>(const String& lhs, const String& rhs){
  if(!(lhs <= rhs)){
    return true;
  }
  else{
    return false;
  }
}

In: Computer Science

Searching an Array for an Exact Match C++ This question is on MindTap Cengage Summary In...

Searching an Array for an Exact Match C++

This question is on MindTap Cengage

Summary

In this lab, you use what you have learned about searching an array to find an exact match to complete a partially prewritten C++ program. The program uses an array that contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the array for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan.

The file provided for this lab includes the input statements and the necessary variable declarations. You need to use a loop to examine all the items in the array and test for a match. You also need to set a flag if there is a match and then test the flag variable to determine if you should print the the Not a city in Michigan.message. Comments in the code tell you where to write your statements. You can use the previous Mail Order program as a guide.

Instructions

Ensure the provided code file named MichiganCities.cppis open.

Study the prewritten code to make sure you understand it.

Write a loop statement that examines the names of cities stored in the array.

Write code that tests for a match.

Write code that, when appropriate, prints the message Not a city in Michigan.

Execute the program by clicking the Run button at the bottom of the screen. Use the following as input:
Chicago
Brooklyn
Watervliet
Acme

// MichiganCities.cpp - This program prints a message for invalid cities in Michigan.  

// Input: Interactive

// Output: Error message or nothing

#include <iostream>

#include <string>

using namespace std;

int main()

{

// Declare variables

string inCity; // name of city to look up in array

const int NUM_CITIES = 10;

// Initialized array of cities

string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"};

bool foundIt = false; // Flag variable

int x; // Loop control variable

// Get user input

cout << "Enter name of city: ";

cin >> inCity;

// Write your loop here

  

// Write your test statement here to see if there is

// a match. Set the flag to true if city is found.

  

// Test to see if city was not found to determine if

// "Not a city in Michigan" message should be printed.

  

return 0;

} // End of main()

In: Computer Science

1. write SQL statements to create the following two tables: a) Department table that contains the...

1. write SQL statements to create the following two tables:

a) Department table that contains the following columns(dept_no,deptname,location) set the deptno to be the primary key.
b) Employee table contains the following columns(emp_no,empname,deptno,salary)set the emp_no to be the primary key and dept_no to be the foreign key.

2. Write SQL statements to Insert the following 3 rows in Employee table:

       (101,’Sami’,’D-101’,5000)
       (102,’Yousef’,’D-101’,4000)
       (103,’Sami’,’D-102’,7000)

3. Write SQL statements to Insert the following 3 rows in Department table:
       (‘D-101’,’Marketing’,’loc1’)
       (‘D-102’,’Sales’,’loc2’)
       (‘D-103’,’Finance’,’loc3’)

4. Create a view for employee at marketing department.

In: Computer Science