Questions
You are to use your code from part A of this assignment and add to it....

You are to use your code from part A of this assignment and add to it. In this part of the project, you are to do the following:
1. In the count_voters function you are to add code to:
• Count the number of votes for Trump
• Count the number of votes for Biden
• Count the number of females
• Count the number of males
• Count the number of Democrats
• Count the number of Republicans
• Count the number of females for Trump
• Count the number of females for Biden
• Count the number of males for Trump
• Count the number of males for Biden
• Count the number of Democrats for Trump
• Count the number of Republicans for Biden
• Count the number of voters who think Trump has done a better job to manage the economy
• Count the number of voters who think Trump has done a better job to manage the civil unrest
• Count the number of voters who think Trump has done a better job to manage the coronavirus
2. In the voter_stats function you are add code to calculate the following:
• percent of female voters for Trump
• percent of female voters for Biden
• percent of male voters for Trump
• percent of male voters for Biden
• percent of Democrats voting for Trump
• percent of Republicans voting for Biden
• percent of voters thinking Trump has done better to manage the economy
• percent of voters thinking Trump has done better to manage the civil unrest
• percent of voters thinking Trump has done better to manage the coronavirus
3. In the print_stats function, you are to add code to also print the following:
• Print the Candidate who won
• Total number of voters
• Total number of female voters
• Total number of male voters
• Total number of Democrats
• Total number of Republicans
• percent of female voters for Trump
• percent of female voters for Biden
• percent of male voters for Trump
• percent of male voters for Biden
• percent of Democrats voting for Trump
• percent of Republicans voting for Biden
• percent of voters thinking Trump has done better to manage the economy
• percent of voters thinking Trump has done better to manage the civil unrest
• percent of voters thinking Trump has done better to manage the coronavirus
All of the required data, counts, percentages etc… are to be private members of the class, NOT the linked list. Therefore, no data will be passed among functions in this code.
Be careful to define the data correctly, counts are integer and percentages are double. You must also use variable names that are easy to follow as to what they mean. For example, call the females for Trump, int trump_females;
You could have multiple loops within the count_voter function to search the linked list multiple times. There is code on blackboard to show how to search the list. You should do one count at a time and print it in the print_stats function to make sure it works. Then move on to the next one.
You are to copy your code to word along with a screen print of the final output copied to the same word document.

Here is part A:

#include <iostream>
#include <string>
using namespace std;

class vote
{
private:
struct votenode
{
char candidate;
char registered;
char gender;
char covid;
char economy;
char civil;
votenode *next;
};
votenode *first, *previous, *current;

public:

void read_voters();
void count_voters();
void voter_stats();
void print_stats();
};

int main()
{
vote data;
data.read_voters();
data.count_voters();
data.voter_stats();
data.print_stats();
system("pause");
return 0;
}

void vote::read_voters()
{
string more = "yes";
first = new votenode;
previous = first;
while (more == "yes")
{
current = new votenode;
system("cls");
cout << "Enter your voter registration (D for Democrat or R for Republican) ";
cin >> current->registered;

cout << endl << "Enter your gender (M for Male or F for Female) ";
cin >> current->gender;

cout << endl << "Enter the candidate you are voting for (T for Trump or B for Biden) ";
cin >> current->candidate;

cout << endl << "Who do you think is doing best on economy? (T for Trump or B for Biden) ";
cin >> current->economy;
cout << endl << "Who do you think is doing best on civil unrest? (T for Trump or B for Biden) ";
cin >> current->civil;

cout << endl << "Who do you think is doing best on covid-19? (T for Trump or B for Biden) ";
cin >> current->covid;

current->next = 0;
previous->next = current;
previous = current;
cout << endl << "Enter more data yes/no ";
cin >>more;
}//END OF WHILE LOOP
}//END OF READ_VOTER

void vote::count_voters()
{
cout << "Executing count_voter" << endl;
}

void vote::voter_stats()
{
cout << "Executing voter_stats" << endl;
}

void vote::print_stats()
{
system("cls");
cout <<"All Voter Data Entered" << endl;
current = first->next;
while (current!= 0)
{
cout <<"Gender:" << current->gender << " Registration:" << current->registered <<" Candidate:" << current->candidate << endl;
cout<<"Economy:"<< current->economy << " Civil:"<< current->civil <<" Covid:"<< current->covid << endl<<endl;
current = current->next;
}
}

In: Computer Science

Has protection for proprietary software gone too far, as some critics suggest? (b) If not, why?...

Has protection for proprietary software gone too far, as some critics suggest? (b) If not, why? (c) If so, what are the implications for innovation and competition in the computer industry? (d) How can we achieve an appropriate balance between those who hold legal rights to proprietary information and ordinary users who wish to access, share, and communicate that information? Defend your answer. Please elaborate (beyond a yes or no answer) and provide your “theoretical” rationale in support of your responses. (knowledge)

In: Computer Science

This week, we learned that there are four levels of abstraction of a data model. They...

This week, we learned that there are four levels of abstraction of a data model. They are contextual, conceptual, logical, and physical. Briefly explain each level with a focus on the differences between them. When working on the final project for this course, many students go directly to the physical model. What would you say to these students? Why would you say so?

In: Computer Science

Write a .m function file on MATLAB that reads the parameters stored in the file missile...

Write a .m function file on MATLAB that reads the parameters stored in the file missile data.txt into MATLAB. The function should have the following declaration: function [X0, Y0, Z0, m0, mf, Thmag0, theta, phi, Tburn] = read input( input filename, M id) where input filename is a string variable denoting the name of the file to be read and M_id is an integer which denotes the missile ID. The outputs are the initial position (X0, Y0, Z0), initial and landing mass (m0, mf), initial thrust magnitude (Thmag0), aunch angles (theta and phi) and burn time (T burn). When the input M_id is not available in the file, the function should set all outputs to NaN and display an error warning message to screen. Use "importdata" or "textscan" function to read the parameters.

The text file is:

# Missile parameters in the following order from left to right:
# Missile ID
# Initial position in X0, Y0, Z0 coordinate (m)
# Initial mass and landing mass: m0 and mf (kg)
# Initial thrust magnitude Thmag0 (N) 
# Direction angle (degree): theta, phi
# Burn time Tburn (s)   
1       0.12    29999.14        1.54    700     90      100000.00       -41.24  52.01   11.11
2       0.15        0.54        2.54    700     90      101000.00        32.65  53.02   11.05
3       0.10      101.43        2.43    700     90       99000.00        20.18  53.62   11.09
4       0.16    29812.45        2.12    700     90       96000.00       -15.65  50.51   11.13
5       0.11    15432.98        0.15    700     90       90000.00         5.86  49.07   11.02
6       0.14    29934.54        2.24    700     90       85000.00       -25.34  51.52   11.05
7       0.13      212.43        1.23    700     90       80000.00        10.24  50.05   11.98
        

In: Computer Science

Hello Everyone, Can anyone tell me why my program will not run? I am trying to...

Hello Everyone,

Can anyone tell me why my program will not run? I am trying to work on abstract base classes... not sure what is going on.

import math

from abc import ABC

from abc import abstractmethod

#TODO: convert this to an ABC

class Shape(ABC):

def __init__(self):

self.name = ""

def display(self):

print("{} - {:.2f}".format(self.name, self.get_area()))

#TODO: Add an abstractmethod here called get_area

@abstractmethod

def get_area(self):

if self.name == "Circle":

get_area()= 3.14 * radius * radius

else:

get_area() = self.length * self.width


#TODO: Create a Circle class here that derives from Shape

class Circle(Shape):

def __init__(self):

super().__init__()

self.name = "Circle"

self.radius = 0.0

get_area()

#TODO: Create a Rectangle class here that derives from Shape

class Rectangle(Shape):

def __init__(self):

super().__init__()

self.name = "Rectangle"

self.length = 0.0

self.width = 0.0

get_area()


def main():

#TODO: Declare your list of shapes here

s = Shape()

c = Circle()

r = Rectangle()

radius = []

length = []

width = []

command = ""

while command != "q":

command = input("Please enter 'c' for circle, 'r' for rectangle or 'q' to quit: ")

if command == "c":

radius = float(input("Enter the radius: "))

#TODO: Declare your Circle here, set its radius, and

# add it to the list

self.name = "Circle"

radius.apphend

return radius

elif command == "r":

length = float(input("Enter the length: "))

width = float(input("Enter the width: "))

#TODO: Declare your Rectangle here, set its length

# and width, and add it to the list

self.name = "Rectangle"

return length, width

length.apphend

width.apphend


# Done entering shapes, now lets print them all out:

s.display()

#TODO: Loop through each shape in the list, and call its display function

for i in Shape():

s.display()

if __name__ == "__main__":

main()

In: Computer Science

Write a C program, char.c, which prints the numerical value of the special character constants given...

Write a C program, char.c, which prints the numerical value of the special character constants given below. Don’t just look up the codes and print them directly from your program. You should have your program output the values of the character constants by using them as string literals within your printf() statements.
Your output should be presented in a neat, orderly, tabular format as shown below:
Char Constant Description Value '\n' newline '\t' horizontal tab '\v' vertical tab '\b' backspace '\r' carriage return '\f' form feed '\\' backslash '\'' single quote (apostrophe) '\"' double quote '\0' null


Use the following guidelines to develop your program:


Declare your variables with appropriate data types.
Assign values to your variables.
Perform your calculations.
Generate appropriate output.



Points to Remember: Make sure you are creating a C program and not a C++ program. The .c suffix to your source code will invoke the C compiler while the .cpp suffix will invoke the C++ compiler. As this is a class in C and not C++, please make sure your source code uses the .c suffix. You should not be using any global variables in your program. A global variable is a variable declared outside of main().
Output from your program should be sent to the terminal window (your screen) as well as the requested csis.txt output file. Be sure to read the document on Capturing Program Output. Your full name and Palomar ID number must appear as a comment in the source file that contains main().

In: Computer Science

In each regional branch of Marc-Lu sales company, every salesclerk has a monthly base salary. The...

In each regional branch of Marc-Lu sales company, every salesclerk has a monthly base salary. The salesclerk also takes a bonus at the end of each month based on the following criteria: If the salesclerk has been with the company for three or less years, the bonus is $100 for each year that he or she has worked there. If the salesperson has been with the company for more than three years and less or five years, the bonus is $200 for each year that he or she has worked there otherwise the bonus is $ 300. The salesclerk can also earn an extra bonus as follows: If the total sale made by the salesclerk for the month is more than $ 5,000 but less than $10,000 he or she receives a 3% commission on the sale. If the total sale made by the salesclerk for the month is at least $ 10,000 he or she receives a 6% commission on the sale.

a) Design an algorithm that calculates the monthly payment of a salesclerk at given regional branch.

b) List all the variables required to write this program.

c) Use the algorithm in (a) to write a complete C++ program to calculate monthly payment of a salesclerk at a given regional branch.

In: Computer Science

A system of caves is a group of connected underground tunnels. Design an ADT for a...

A system of caves is a group of connected underground tunnels. Design an ADT for a cave and a cave system. An archaeologist should be able to add a newly discovered cave to a cave system. He/she can enter this system through only one cave and exit the system only through a different cave. Duplicate caves – based on GPS coordinates – are not permitted. Archaeologists should also be able to list the caves in a given cave system.

File Submission

• Cave.java

Cave object containing Cave Name and Cave GPS coordinates (Latitude and Longitude) and any other appropriate attributes if needed

• CaveInterface.java

Interface containing method definition to add and remove caves

• CaveStack.java

Stack implementation of CaveInterface.java

• CaveStackDemo.java

Demonstrate adding, removing and listing caves. Prompt the user for various cave names and GPS coordinates to show your implementation.

In: Computer Science

JavaScript Form Validation Name: a text box where the content must start with 1 upper case...

JavaScript Form Validation

Name: a text box where the content must start with 1 upper case characters and no special character (i.e. !, @, #, $, %, &, *). Number is not allowed. The text box must not be empty.


Module code: a text box where the content must start with 3 lower case alphabets and follows by 4 digits where the first digit cannot be zero. This textbox can be empty.

All validation error messages must be italic and in red colour and besides the HTML element.

There should be a validation error displayed for every error.

Example:

If the user enters a number and special characters in the Name textbox, a message should say on the side "Numbers are not allowed!" in red and italic.

If the user leaves the name Textbox empty after submission, there should be an error message on the side saying "Name cannot be empty!"

If the user enters uppercase characters followed by the number starting with zero in the Module code TextBox, a message should say on the side "Content must start with 3 lower case alphabets!" followed by "First digit cannot be zero!"

In: Computer Science

C++ file=.class definitions.h Define a Fraction class with num and den as its private data. Include...

C++ file=.class definitions.h

Define a Fraction class with num and den as its private data. Include a constructor to initialize the fraction to 0/1, a copy constructor, a destructor, and overloading functions to overload the assignment operator =, the comparison operators <, >, ==, !=, arithmetic operators +, +=, -, -=, *, *=, /, /=, as well as friend functions (non-member) to overload << and >> to output and input a fraction (see book example). Also, include a private member function called reduce() that gets called after arithmetic operations to reduce the frraction. +, -, *, / must return the result of the operation; e.g.: the sum or difference of the two fractions. +=, -=, *= and /= must assign the result of the operation to the object that's invoking the operation; i.e.: frac1 += frac2 must modify frac1 to make it equal to the sum of the two fractions, but frac1 + frac2 must simply return the sum.

If n1/d1 and n2/d2 are two fractions, their sum fraction's numertor is: n1 * d2 + n2 * d1 and its denominator is d1 * d2. To compare the two fractions, you can compare n1 * d2 with n2 * d1.

In: Computer Science

What is the difference between analytical skills and research skills?

What is the difference between analytical skills and research skills?

In: Computer Science

(10 marks) Write a function to check whether string s1 is a substring of string s2....

Write a function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. For example, the function should return 2 if s1 is "to" and s2 is "October". If s1 is "andy" and s2 is "candy", then the function should return 1. The function prototype is as follows: int indexOf(const char *s1, const char *s2).

In: Computer Science

Project 4 – The Nearest Neighbors Classification Algorithm This project will require you to implement a...

Project 4 – The Nearest Neighbors Classification Algorithm This project will require you to implement a version of the Nearest Neighbors classification algorithm. This version, the Three Nearest Neighbors (or 3NN for short), is one of the more intuitive classification algorithms, and one of the easier ones to code. This Nearest Neighbors family of algorithms is useful because it does not require any special “training” to work. You simply need previous data to compare to. What is classification? With classification, the goal is to use previously collected data to train an algorithm to correctly classify future data. If I have a data set on the measurements of the sepal (the part of a flower that encloses a petal) length and width of two kinds of irises, setosa and versicolor, I can use that data to predict what kind of iris another flower is from sepal measurements alone. Our classification algorithm would be trained to draw a line between the two regions we can see in the scatterplot, as so: Figure 1 Figure 2 Deciding that future data on one side of the line should be setosa, and the other side should be versicolor. Note that we would not expect such a classifier to be perfect: You can see that one of the data points for setosa is on the versicolor side of the boundary in this example. Rather, we would expect the classification algorithm to work an acceptable amount of the time. What is acceptable depends on the application. Definitions Training Data – Data used when implementing the classification algorithm to draw boundaries. In the above example, the x and o data points are the training data. Class – Different categories that training data has been divided into. In the above example, setosa and versicolor are classes. Test Data – Data for which we do not know the class. We will use the classification algorithm to help us guess which class it might come from. Data Space – The data involved with training and testing, in all of its demensions Nearest Neighbors Classifier The nearest neighbor classifier is relatively straightforward. First, it takes all of the dimensions of training data available and normalizes each dimension. An incoming piece of test data is also normalized based on the means and standard deviations of the training data. Once both test and training data are normalized, we wind up with a data space that might look like this: In the nearest neighbors algorithm, we look at the Euclidian distance between the test data and the training data. We then look at the closest K neighbors, where K is determined before training. In this example, and in this project, K = 3. Those closest neighbors then “vote,” with the class that has the largest number of closest neighbors being assigned as the class of the test data. Figure 3 In the above example (test data was sepal length 6 cm, sepal width 4cm), the 3NN algorithm classifies the test data as setosa: Because the three closest neighbors are all of the class setosa. In another test data case, with sepal length 5.75 cm and sepal width 3.5 cm, we also find that the class is setosa: As two of the three closest neighbors are of that class. In a third test data case, with sepal length as 5.2 cm and sepal width as 2.9 cm, we find the class is versicolor: Figure 4 Figure 5 As two of the three closest neighbors are of that class. Inputs and Outputs In this project, you will implement the 3NN algorithm in a MATLAB function. This algorithm will only work with data that is in 2 dimensions with 2 classes. This function will have two inputs: dataSet – A structure with the following fields: - data1 – A numerical array of doubles, the first dimension of a data set, of length N - data2 – A numerical array of doubles, the second dimension of a data set, also of length N - label – A cell array, the class labels of your data set. Each element is a vector string. Also of length N - name1 – A string with the first possible class label - name2 – A string with the second possible class label testData – A 1 x 2 array of doubles, where the first element is the value of your test data in dimension 1, and the second element is the value of your test data in dimension 2. This function will have one output: winner – A string with the label of the class assigned to testData. Your function should also produce a plot of the normalized Data space similar to figure 3. To create a plot of points instead of lines, use the following inputs to plot: plot(x,y,'Marker','o','LineStyle','none') Where the string after the input “Marker” determines the shape of each point, and “ ‘LineStyle’, ‘none’ “ prevents any lines from being drawn between points. Methods Figure 6 Please use the following methods to implement the 3NN algorithm: Step 1 Normalize both dimensions of your training data set. Then normalize your test data using the mean and standard deviation of your training data. You now have enough data to generate the required plot. Step 2 Find the Euclidian distance between your test data and all training data using the Pythagorean theorem with your normalized data. Step 3 Find the three points in the training dataset that are closest to your test data. Step 4 Have the three nearest neighbors “vote” to see which class has more representation in the nearest neighbors. Hint: This is where you will want to use the label, name1, and name2 fields. Use the result of voting to set the output. Testing Code I have prepared three test datasets for you, that you can find in the files: - iris.mat, which is the data set in the above examples - diabetes.mat, which is blood glucose and ages of patients 5 years prior for people with and without diabetes - wheat.mat, which is the area and compactness of the kernals of two varieties of wheat seed You should be able to use your visualizations to check whether your nearest neighbors algorithms are working properly. Hint: Try choosing test data in some of the less “crowded” locations of your data space.

In: Computer Science

Task 1: This is the instructions for the previous set, where we worked with list of...

Task 1: This is the instructions for the previous set, where we worked with list of lists as character records, (there is already a solved Chegg for task 1 (J. [40 points]). I need help with the code of converting isInrecord(), AddToRecord(), createRecord(), and frequencies() from task J to use dictionaries instead of lists (as is asked in task A, which is located below the line of ########).

J. [40 points]
This tasks includes working with lists and lists of lists.

For this task, you'll keep track of how many times a certain value occurs in a set of data. You'll be tracking and counting characters, i.e. how many times any letter, digit, or punctuation mark appears in a string. You'll be writing Python code to create and work with such character records. What is a character record? It's the information about how many times any character (in a string or text) appears in that string or text. Let's look at this example:

  1. For example, we may want to keep track of how many times does the letter 'o' appear in the string "Kokomo?" ...it appears 3 times.
  2. The letter 'k' appears in the string "Kokomo?" just 1 time, if we consider 'k' (small case) and 'K' (capitalized) to be different letters.
  3. And the letter '?' appears in the string "Kokomo?" only 1 time.
  4. For Task J, you'll be representing the data structure for character records as a list of pairs (i.e. lists of two-item lists). The first item in each pair is the character, and the second is an integer representing how many times that character appears in some particular string. So if ['e',20] is in the list, that means that there are 20 lowercase e's in the string. Here's an example of such a data structure: [['K',1],['o',3],['k',1],['m',1],['?',1]], which represents a string with 1 K, 3 o's, 1 k, 1 m, and 1 question mark (perhaps "Kokomo?"?). Any time you see the words "character record" in Task J, you can assume it refers to a list of pairs like this (where the first item in the pair is a one-character string and the second is an integer).

    steps in Task J:
  5. For this task, save your function(s) in the same script named ps08-characterRecords.py as in the above Tasks B, etc. You'll be putting all of the code you write for Task J into this script. Include a comment in your script, explaining how you are representing character records. This comment is your data definition[1], and it might start with something like:

    ?

    1

    # a *character record* is a list of two-item lists where...

    This comment is a kind of informal data definition. After this comment, you can and should use the words "character record" as part of your other comments in the submitted Python code.

    [1]This is in addition to another writing requirement:
    all functions you write for A201/A597 must have a correctly and well-defined docstring, including a signature and a purpose statement.

  6. Write a Python function named isInRecord() that takes one character and one character record as parameters, and returns True if the character is listed in the character record, False otherwise. So 'o' and [['K',1],['o',3],['k',1],['m',1],['?',1]] should have the isInRecord() return True, and 'c' and  [['K',1],['o',3],['k',1],['m',1],['?',1]] should have isInRecord() return False.
  7. Write a Python function named addToRecord() code that takes one character and one character record, and adds an occurrence of that character to the character record. Note that if the character doesn't already have an entry, it should create one. Note that this part of the script should be modifying the existing character record, not creating a new character record. Here is an example how this would work:

    ?

    1

    myCharRecord = [['K',1],['o',3],['k',1],['m',1],['?',1]]

    then adding 'o' to myCharRecord:

    ?

    1

    2

    myCharRecord

    [['K',1],['o',4],['k',1],['m',1],['?',1]]

    then adding 'X' to myCharRecord:

    ?

    1

    2

    myCharRecord

    [['K',1],['o',4],['k',1],['m',1],['?',1],['X',1]]

  8. Write a Python function named createRecord() that takes any string, and returns out a new character record from that string. So starting from "Kokomo?" should generate [['K',1],['o',3],['k',1],['m',1],['?',1]]. If you reuse your previous code for the above parts of Task J, this shouldn't be too hard.
  9. Write a Python function named frequencies() that takes one character and one character record, and returns one number: the frequency associated with that character in the given character record. If the character doesn't appear in the character record, it should return 0. So for example, 'o' and [['K',1],['o',3],['k',1],['m',1],['?',1]] ) should return 3 and 'X' and [['K',1],['o',3],['k',1],['m',1],['?',1]] ) should return 0.

#################################################################################################################################################

  1. [16 points]
    For Task A, you'll be reimplementing the character-frequency character record script that you first implemented for Problem Set 08 Task J.
    However, this time you need to use dictionaries instead of lists of two-item lists.

    You should be representing a character record by a dictionary with single-character strings as keys and integers as values.
    So for example, the character-frequency character record for "Kokomo?" would be {'K':1, 'o':3, 'k':1, 'm':1, '?':1}.

    Write your Python code for Task A in a script called ps09-taskA.py.
    Place all of the code you write for Task A into this script. Include a comment in your script, explaining how you are representing character records. This comment is your data definition[1], and it might start with something like:

    ?

    1

    # a *character record* is a dictionary where...

    This comment is a kind of informal data definition. After this comment, you can and should use the words "character record" as part of your other comments in the submitted Python code.

    Note[1]This is in addition to the usual requirement:
    all functions you write for A201/A597 must have a correctly and well-defined docstring, including a signature and a purpose statement.


    Implement four functions named in the same way as you named them for Problem Set 08 Task J, i.e.:Please refer to Problem Set 08 Task J instructions about how those functions should process "character record" data.

    Note 1: the purpose statement for those 4 functions is going to be pretty similar to the purpose statement in Problem Set 08 Task J , but the signature will be necessarily different, since we're now using dictionaries instead of lists of lists.

    Note 2: the script solving this task may be a little less complex than the Problem Set 08 Task J script: this is because here we are using our new data definition for character records (i.e. using dictionaries), and there's a very simple built-in Python command that can be used to determine whether or not a particular character appears in the character record. Make sure you know what that command is, before you implement Task A.
    • Write a Python function named isInRecord()
    • Write a Python function named addToRecord()
    • Write a Python function named createRecord()
    • Write a Python function named frequencies()
      (Hint: this should be a lot easier than if you were working with lists of lists. To implement this function, no loops are needed at all. The only slightly tricky part is dealing with the case when the character isn't present in the histogram.)

############################# my code that needs to be converted from list of list into dictionaries (they can be modified as much as needed )############################

def isInRecord(char,charRec):
""" returns True if character is in character Record, otherwise false

string, charRecord -> Boolean Value"""
for i in charRec:
if i[0]==char:
return True
return False


def addToRecord(char,charRec):
""" returns new character record with updated frequency of each character occurance

character, charRecord(myCharRecord) -> list of character records"""
check=False
for i in charRec:
if i[0]==char:
check=True
if not check:
charRec.append([char,1])
myCharRecord = [['K',1],['o',3],['k',1],['m',1],['?',1]]


def createRecord(pString):
""" returns character records for argument entered

string -> list of character records"""
aList=[]
for i in pString:
addToRecord(i,aList)
return aList


def frequencies(char,charRec):
""" returns number for frequency of character in charRec list

character, charRecord -> integer"""
for i in charRec:
if i[0]==char:
return i[1]
return 0

In: Computer Science

a Composite class representing arithmetic expression. Participants: Expression – interface. Operations: double calculate(), boolean isTree(). Constant...

a Composite class representing arithmetic expression.

Participants:

  • Expression – interface. Operations: double calculate(), boolean isTree().
  • Constant – represent a number. Leaf node.
  • Plus, Minus, Div, Mul – binary operations. Use abstract BinaryOperation class to implement common functionality

Q. Create a code implementing a pattern, Implementing Composite implies multiple class. By my estimate, at least 3. In minimal Composite implementation, classes have two methods (or a constructor and 1 method). extensive coding is not required. (using Java)

In: Computer Science