Questions
Explain in detail instruction cycle. Explain the architecture of 8085 register.

Explain in detail instruction cycle.
Explain the architecture of 8085 register.

In: Computer Science

Exercise: Advanced counting Complete the program below in the answer box by entering functions so the...

Exercise: Advanced counting

Complete the program below in the answer box by entering functions so the program can modify the value variable either by adding 1, adding 5, subtracting 1, or subtracting 5. There should only be one function updating the value. The functions subtract_one, add_one, etc. are helper functions as described above; they should simply call the value update function.

from tkinter import *
from tkinter.ttk import *

# Write your functions here

def main():
"""Set up the GUI and run it"""

global value, value_label
window = Tk()
value = 0
value_label = Label(window, text=str(value))
value_label.grid(row=0, column=0, columnspan=4)
subtract_five_button = Button(window, text="-5", command=subtract_five)
subtract_five_button.grid(row=1, column=0)
subtract_one_button = Button(window, text="-1", command=subtract_one)
subtract_one_button.grid(row=1, column=1)
add_one_button = Button(window, text="+1", command=add_one)
add_one_button.grid(row=1, column=2)
add_five_button = Button(window, text="+5", command=add_five)
add_five_button.grid(row=1, column=3)
window.mainloop()

main()

In: Computer Science

A file name is supposed to be in the form filename , ext . Write a...

A file name is supposed to be in the form filename , ext . Write a function that will determine whether a string is in the form of a name followed by a dot followed by a three - character extension , or not . The function should return 1 for logical true if it is in that form , or 0 for false if not ,

In: Computer Science

3 Design 3.1 Token Class The Token type, which is an enum type and used in...

3 Design
3.1 Token Class

The Token type, which is an enum type and used in the Token class, is defined as follows:

enum Token_type {ID, INT, OP, EQ, OpenBrace, CloseBrace, INVALID};

If string s, passed in to the constructor or set method, is an identifier then the token type is ID; is a nonnegative integer then the token type is INT; is one of +, -, *, / then the token type is OP; is = then the token type is EQ; is (, open parenthesis, then the token type is OpenBrace; is ), close parenthesis, then the token type is CloseBrace; is none of the above then the token type is INVALID. The constructor and set method are required to figure out the type of a token string.

Token class is used to store a “token”, which has three members and a few member functions. The members are:

type This field stores the type of the token. Its type is Token type whose definition is given earlier.

token This field stores the token. Its type is string.
priority This field stores the priority of the token when token is an operator

or a parenthesis. Its type is int. The member functions are:

Token() This default constructor initializes type to INVALID, token to empty string, and priority to -1.

Token(string s) This constructor takes in a string and treats it as a token. It sets the type and token member accordingly. For the current project, it sets the priority member to -1.

void set(string s) This method takes in a string and treats it as a token. It sets the members based on the new token s. Again, for the current project, it sets the priority member to -1.

2

int value() const This method returns the value associated with the token when token type is integer or identifier. In this assignment, if the type is INT, the integer represented as a string stored in token member should be converted to int and returned; if the type is ID, it returns -1; for all other types, it returns -2.

In the future assignment, we will be able to process assignment statement such as x=5 and a symbol table is used to associate x with 5. In this case, for token x, the function returns 5.

void display() const This method outputs the values of the token members in three lines. Each line begins with the member name, followed by “=”, followed by the value. This method is mainly for debugging use. For example, if token string is a12, we have:

     type = ID
     token = a12 (value is -1)
     priority = -1

Token type get type() const Getter for type member. string get token() const Getter for token member.
int get priority() const Getter for priority member.

Typically during the tokenizing process of the input string, we get a sequence of characters stored in a string, which is a token. We then use Token class via its constructor or set method to figure out if the token is valid or not and what type of token it is and so on. That is perhaps the most challenging programming (algorithmic) task for the implementation of the Token class. Since an expression is really a sequence of tokens in an abstract sense, the Token class is used by the Expression class to be designed next.

Since none of the member of the Token class involves pointer type and mem- ory allocation, the default copy constructor and assignment operator provided by the compiler should work just fine. We do not need to implement them.

3.2 Expression Class

The Exp type type, which is an enum type and used in the Expression class, is defined as follows:

enum Exp_type {ASSIGNMENT, ARITHMETIC, ILLEGAL};

For the current assignment, we are not required to figure out the type of an expression. We will do that in a later assignment. For the current project, we treat an expression in two ways: 1) as a string and 2) as a sequence of tokens (Token objects stored in a vector) obtained from the string.

Expression class is used to store an “expression”, which has five members and a few member functions. The members are:

3

original This field stores the original or not yet processed “expression”. Its type is string.

tokenized This field stores the expression as a sequence of tokens. Its type is vector.

postfix This field stores the expression as a sequence of tokens in postfix nota- tion provided the expression has arithmetic type. Its type is vector. This member is not used for the current homework assignment but will be used for the last assignment. The set method or con- structors of this assignment should leave it as an empty vector, that is to do nothing.

valid This field indicates whether the expression is a valid expression (no syntax error). Its type is bool. It is not used for the current homework assignment but will be used for the last assignment. The set method or constructors of this assignment should simply set it to false.

type This field indicates whether the type of the expression is ASSIGNMENT or ARITHMETIC expression or ILLEGAL. Its type is Exp type. It is not used for the current homework assignment but will be used for the last assignment. The set method or constructors of this assignment should simply set it to ILLEGAL.

The member functions are:

Expression() This default constructor initializes all fields to empty or false or ILLEGAL.

Expression(const string& s) This constructor takes in a string and treats it as an expression. It tokenizes the input string and sets the original and tokenized members accordingly. And it sets the other members based on the description given earlier (refer to each member description).

void set(const string& s) This method takes in a string and treats it as an expression. It tokenizes the input string and sets the original and tok- enized members accordingly. And it sets the other members based on the description given earlier.

void display() const This method output the values of the expression fields, one field per line. This method is mainly for debugging use.

original=a12=1?ab + -a0123c(a+123)*(ab-(3+4 )) tokenized = a12;=;1?ab;+;-;a;0123;c;(;a;+;12;3;);*;(;ab;-;(;3;+;4;);); number of tokens = 24
postfix =

valid = false
type = ILLEGAL

4

string get original() const Getter for original member.

vector get tokenized() const Getter for tokenized member.

other methods There are other methods such as to evaluate the expression, to transform the expression, and getters for other fields such as postfix, valid, or type. These methods will be needed for the last assignment. Since we have not studied the related concepts and algorithms, these member functions are omitted.

When we receive a string (maybe from a line of input or a hard coded value within the program), which would be an expression, we use Expression class to figure out if the expression is legal or not and what its type is and so on (use either the non default constructor or set method, and pass the string as its argument).

In order to do the above, the string (perhaps a line of input from the user) gets tokenized first by the Expression class via its constructor or set method. That is perhaps the most challenging programming (algorithmic) task for the current implementation of the Expression class.

Since none of the member of the Expression class involves pointer type and memory allocation, the default copy constructor and assignment operator pro- vided by the compiler should work just fine. We do not need to implement them.

4 Implementation

Please note the similarity between the constructor that takes a string parameter and the set method in Token class. We could implement the set method first. Then the constructor calls the set method to accomplish its tasks. The same can be said for the similarity between the non default constructor and set method in Expression class.

You should implement and test the Token class first. Then use it in the development of the Expresion class. The most challenging method to implement (develop the code for) is the set method of the Expression class. We need to figure out the right algorithm to tokenize. One of the reasons is that we cannot simply use space (a blank character) as a delimiter to tokenize. For instance, in (2+3)*4, we have 7 valid tokens. They are (, 2, +, 3, ), *, 4 and no space betweenthem. Butifitisgivenas( 2 + 3 ) * 4,wecouldusespace. Our method should work for any possible combination of spaces and tokens. You might first assume space is used to separate each token including special tokens and develop a solution. Then consider if you might add space to the given string to use your with space as delimiter solution earlier. This approach is perhaps less efficient than those algorithms that process the string once because it processes a string twice and might double its length. However, it is acceptable for this assignment.

5

For those students who would like a challenge, you might develop an efficient algorithm that tokenizes the string with one pass through the given string.

Token class implementation has .h and .cpp files and the same is true for Expression class. The homework3.cpp file contains the code for testing of both classes.

5 Test and evaluation

Have a main program to test the Token class by sending the constructor and set method many different “tokens” and display the results to see if they are correct or not. You may want to be creative and cover a wide range of possible “tokens” in your testing. Similarly, test the Expression class by sending the constructor and set method many different “expressions” and display the results to see if they are correct or not. You may want to be creative and cover a wide range of possible “expressions” in your testing.

In: Computer Science

DO THIS IN C# (PSEUDOCODE)Social Security Payout. If you’re taking this course, chances are that you’re...

DO THIS IN C# (PSEUDOCODE)Social Security Payout. If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called Social Security. In simplest terms, it’s a way to pay into a system and receive money back when you retire (and the longer you work and the higher your salary, the higher your monthly benefit). Interestingly, your employer will pay the same amount for you. The current tax rate is 6.2% until you make approximately $132,900. For this assignment, we’re going to help out hourly employees. Design (pseudocode) and implement (source code) a program that asks users how much they make per hour, the number of hours they work per week, and calculates the yearly income. For the second half, the program should calculate and display the amount of Social Security tax the user will pay for that year. You must write and use at least two functions in addition to the main function. At least one function must not have a void return type. Note, don’t forget to put the keywords “public” and “static” in front of your functions. Document your code and properly label the input prompt and the outputs as shown below.

Sample run 1: Enter hourly wage: 10 Enter your hours per week: 40 You will earn $20800.0 per year You will pay $1591.2 in Social Security tax Sample run 2: Enter hourly wage: 40 Enter your hours per week: 60 You will earn $124800.0 per year You will pay $9547.2 in Social Security tax

In: Computer Science

For the division method for creating hash functions, map a key k into one of m...

For the division method for creating hash functions,

map a key k into one of m slots by taking the remainder of k divided by m. The hash function is:

                        h(k) = k mod m,

            where m should not be a power of 2.

For the Multiplication method for creating hash functions,

            The hash function is h(k) = m(kA – k A ) = m(k A mod 1)

            where “k A mod 1” means the fractional part of k A; and a constant A in the range

0 < A < 1.

An advantage of the multiplication method is that the value of m is not critical.

Choose m = 2p for some integer p.

Give your explanations for the following questions:

(1) why m should not be a power of 2 in the division method for creating hash function; and

            (2) why m = 2p, for some integer p, could be (and in fact, favorably) used.

In: Computer Science

11. A business rule says that an employee cannot earn more than his/her manager. Assume that...

11. A business rule says that an employee cannot earn more than his/her manager.
Assume that each employee row has a foreign key which refers to a manger row.
a. Can this business rule be implemented using a fixed format constraint?
b. Can this business rule be implemented using a trigger?
12. Triggers should be created sparingly. Why?
13. Should you use a trigger to check the uniqueness of a primary key?

14. What is a Distributed Database system?
15. What advantages does a Distributed Database have over a Centralized Database?
16. Why do some users require data from multiple sites in a Distributed Database?

17. What is Horizontal Fragmentation within a DDBMS?

Note: Questions are based on DBMS (Distributed database and triggers)

In: Computer Science

You have a class named AirConditioner that has a private boolean field named on. It has...

You have a class named AirConditioner that has a private boolean field named on. It has method named turnOn that sets the field to true and one named turnOff that set it to false. It also has a method named isOn that returns the value of the on field. Fill in the blank to complete the turnOff method.

public void turnOff() {
    ______________________
}

In: Computer Science

Give an example that shows the greedy algorithm for activity selection that picks the activity with...

Give an example that shows the greedy algorithm for activity selection that picks the activity with the smallest start time first (and continues in that fashion) does not solve the activity selection problems correctly.

Please show your work! I will rate quality answers. Thank you.

In: Computer Science

1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to...

1. Copy the files from Assignment 1 to Assignment 3.

2. Modify the PetFoodCompany header to mention a friend function called "computeBonusBudget". This method should compute the bonus budget as netIncome() * BonusBudgetRate and this method should exist in the driver program - not the Class defintion.

3. Modify the output of the program to display the results of the computeBonusBudget.

Enter Total Sales: 1000
Enter Total Expenses: 600
Net Income = 400
Bonus Budget = 8

Here is the code:

PetFoodComp.h:

class PetFoodCompany
{
public:
  
PetFoodCompany();

char getQuart();
char* getCompany();
char* getDivision();

void setQuart(char quart);
void setTotalSales(float totalSales1);
void setTotalExpences(float totalExpences1);
void setCompany(char name[]);
void setDivision(char name1[]);


float getTotalSales();
float getTotalExpences();

double netIncome();
  

private:
  
char company[40];
char division[40];

static char quart;
static double BonusRate;

float totalSales;
float totalExpences;
  
  
};

PetFood.cpp:

#include <iostream>
#include <cstring>
#include "PetFoodComp.h"

using namespace std;


double PetFoodCompany::BonusRate = 0.02;
char PetFoodCompany::quart = '1';

PetFoodCompany::PetFoodCompany()
{
   strcpy(company, "myCompanyName");
}

char PetFoodCompany::getQuart()
{
   return quart;
}

float PetFoodCompany::getTotalSales()
{
   return totalSales;
}

float PetFoodCompany::getTotalExpences()
{
   return totalExpences;
}

char* PetFoodCompany::getCompany()
{
   return company;
}

char* PetFoodCompany::getDivision()
{
   return division;
}

void PetFoodCompany::setQuart(char quart1)
{
   if (quart1 == '1' || quart1 == '2' || quart1 == '3' || quart1 == '4')
       quart = quart1;
}

void PetFoodCompany::setTotalSales(float totalSales1)
{
   totalSales = totalSales1;
}

void PetFoodCompany::setTotalExpences(float totalExpences1)
{
   totalExpences = totalExpences1;
}

void PetFoodCompany::setCompany(char name[])
{
   strcpy(company, name);
}

void PetFoodCompany::setDivision(char dname[])
{
   strcpy(division, dname);
}

double PetFoodCompany::netIncome()
{
   return (totalSales - totalExpences);
}

PetFoodMain.cpp:

#include <iostream>
#include <cstring>
#include "PetFoodComp.h"


using namespace std;

int main()
{
   double totalSales, totalExpences;
   PetFoodCompany pet;
   cout << "Company Name is " << pet.getCompany() << "\n";
   cout << "Current Quarter is " << pet.getQuart() << "\n";


   cout << "Enter Total Sales: ";
   cin >> totalSales;

   cout << "Enter Total Expences: ";
   cin >> totalExpences;

   pet.setTotalExpences(totalExpences);
   pet.setTotalSales(totalSales);

   cout << "Net Income: " << pet.netIncome() << "\n";

   return 0;
}

In: Computer Science

Question 2. A programmer has to develop an instant messaging app used in mobile phone. He...

Question 2.
A programmer has to develop an instant messaging app used in mobile phone. He is considering the computer instruction set architecture of either RISC or CISC and the programming method of either translation or interpretation.
(a) Suggest and justify the most suitable instruction set architecture.
(b) Suggest and justify the most suitable programming method

In: Computer Science

Write a PL/SQL program that prints following: if sum of its digits raised to the power...

Write a PL/SQL program that prints following: if sum of its digits raised to the power n is equal to number itself, where n is total digits in number.

If the Input is: 129, then output of the program will be: 738

In: Computer Science

Database questions: USE THE FOLLOWING SQL CODE TO SOLVE NEXT QUESTIONS: CREATE TABLE ROBOT ( Serial_no...

Database questions:
USE THE FOLLOWING SQL CODE TO SOLVE NEXT QUESTIONS:
CREATE TABLE ROBOT
(
Serial_no INT NOT NULL,
Model VARCHAR(20) NOT NULL,
Manufacturer VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_no)
);
INSERT INTO ROBOT VALUES (1, 'Scara','Epson', 23200);
INSERT INTO ROBOT VALUES (2, 'ASSISTA','Mitsubishi', 17500);
INSERT INTO ROBOT VALUES (3, 'Lego Mindstorm','NXT', 650);
INSERT INTO ROBOT VALUES (4, 'Yumi','ABB', 40000);
INSERT INTO ROBOT VALUES (5, 'Pepper','Foxconn', 1600);
INSERT INTO ROBOT VALUES (6, 'Humanoid','Honda', 30000);
SELECT * FROM ROBOT ;
/*===================================================*/
CREATE TABLE OPTIONS
(
Serial_Num INT NOT NULL,
Option_name VARCHAR(20) NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Serial_num, Option_name),
FOREIGN KEY (Serial_num) REFERENCES ROBOT(Serial_no)
);
INSERT INTO OPTIONS VALUES (1, 'Self power', 10000);
INSERT INTO OPTIONS VALUES (1, 'Sense surrounding', 20000);
INSERT INTO OPTIONS VALUES (5, 'Extra Speed', 30000);
INSERT INTO OPTIONS VALUES (2, 'Self power', 40000);
INSERT INTO OPTIONS VALUES (3, 'Motion Balance', 50000);
INSERT INTO OPTIONS VALUES (4, 'Custom look', 60000);
SELECT * FROM OPTIONS;
/*===================================================*/
CREATE TABLE SALESPERSON
(
Salesperson_id INT NOT NULL,
SName VARCHAR(20) NOT NULL,
Phone VARCHAR(20) NOT NULL,
PRIMARY KEY (Salesperson_id)
);
INSERT INTO SALESPERSON VALUES (111, 'Jameco Electronics', '0252354565');
INSERT INTO SALESPERSON VALUES (222,'RobotShop', '0231236455');
INSERT INTO SALESPERSON VALUES (333,'RoboRealm', '0287678790');
SELECT * FROM SALESPERSON ;
/*===================================================*/​
CREATE TABLE SALE
(
Salesperson_id INT NOT NULL,
Serial_no INT NOT NULL,
MyDate DATE NOT NULL,
Sale_Price INT NOT NULL,
PRIMARY KEY (Salesperson_id, Serial_no),
FOREIGN KEY (Salesperson_id) REFERENCES SALESPERSON (Salesperson_id),
FOREIGN KEY (Serial_no) REFERENCES ROBOT(Serial_no)
);
INSERT INTO SALE VALUES (111, 1, DATE'2018-9-23', 22000);
INSERT INTO SALE VALUES (222, 1, DATE'2019-9-22', 21400);
INSERT INTO SALE VALUES (111, 4, DATE'2017-7-21', 37000);
INSERT INTO SALE VALUES (333, 3, DATE'2020-6-14', 470);
SELECT * FROM SALE ;


Q1: Write a query to display all serial numbers of robots that don’t have sales using complex queries

Q2: Write a query that displays the sales price and dynamically assign a deal category to it as follows:
- If the sales price less than or equal 10,000 à accepted-deal price
- If the sales price ranges between 20,000 and 25,000 à average-deal price
- If the sales price greater than 50,000 à rejected-deal price


In: Computer Science

Using matlab Set ASIZE to 5. Write a program that creates an array of ASIZE numeric...

Using matlab

  1. Set ASIZE to 5. Write a program that creates an array of ASIZE numeric elements. Prompt the User for ASIZE numbers and store them in the array. After storing the values, calculate the sum of all the values in the array and display the sum.
  2. Modify the program you wrote for Problem 5 such that it calculates the product of all the values instead of the sum.
  3. Modify the program you wrote in Problem 6 such that it changes the value of each element of the array by multiplying each element of the array by 2, and then displays each element of the array.

                                                                                                              

In: Computer Science

Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist...

Grocery Store using Java Arraylist Requirements:

1. Need Product Class and Stock Class

2. Use arraylist to store/ add product in stock

3. Product must have name, code number and quantity in stock

4. Print list of the products and their stock quantity

5. Search products based on their name

6. Remove product based on their code number

7. Sell product and deduct quantity from stock

8. Stock Class contains methods of search product, add product and check quantity of the product

9. Product Class contains method of get product details

In: Computer Science