Questions
The following code has some syntax error. Please fixed the error. Besides, I want the output...

The following code has some syntax error. Please fixed the error. Besides, I want the output in ASCII characters. Please give me the corrected code along with the screenshot of the output.

def cbc_dec(ys):

int xs = []

int iv = ("0XAA", 16) #in decimal

int key = ("0X08", 16)

int x0 = chr(((163 * (int (ys[0], 16) - key)) % 256) ^ iv)

xs.append(x0)

for i in range (1, len(ys)):

int xi = chr((( 163 * (int (ys[i], 16) - key)) %256) ^ int (ys[i-1], 16))

xs.append(xi)

return xs

def main():

cipher_cbc = ["0XA0", "0XCC", "0X1F","0XE3','0XE0','0X59']

ps_cbc = cbc_dec(cipher_cbc)

print("\nCBC decryption", ps_cbc)

main()

In: Computer Science

def is_one_player_game(game_type)-> bool: """The parameter represents the type of game being played: human, human-human, or human-computer....

def is_one_player_game(game_type)-> bool:
"""The parameter represents the type of game being played: human, human-human,
or human-computer. The function should return True if and only
if this is a one-player game.
  
"""

In: Computer Science

write a simple program to demonstrate the use of static type of variables in c++... use...

write a simple program to demonstrate the use of static type of variables in c++...
use comments to explain plz

In: Computer Science

2. The Fibonacci sequence is defined as f(n) = f(n - 1) + f(n - 2)...

2. The Fibonacci sequence is defined as
f(n) = f(n - 1) + f(n - 2)
with f(0) = 0 and f(1) = 1.
Find f(54) by a program or maually. Note that this number must be positive
and f(53) = 53.......73 (starting with 53 and ending with 73). I must admit that
my three machines including a desktop are unable to find f(54) and they
quit during computation.
The answer is f(54) = 86267571272
*/
The Java code:
public class FibonacciTest2 {
​public static long BinaryFibonacci(int k) { // This is long type rather than int here
​​if (k == 1 || k==0)
​​ return k;
​​else
​​ return BinaryFibonacci(k - 1) + BinaryFibonacci(k -2 );
​}
​public static void main (String args[]) {
​​System.out.println(BinaryFibonacci(53));
​}
}
My new computer is able to find
f(53) = 53316291173 and
f(52) = 32951280099.
Therefore,
f(54) = f(53) + f(52) = 86267571272.
Note that if your computer is only able to find f(52), then you need do more calculation.
4. Analyze this code and run it, if there are any issues note them and fix them, if not give the output and Big O notation runtime:
public class PrintBits {
public static void printBits(int a) {
try {
String str = Integer.toBinaryString((Integer) a);
for(int i = 0; i < str.length(); i++){
System.out.print (str.charAt(i));
}
}
catch (ClassCastException e) {
throw new RuntimeException ("Argument is not an Integer");
}
}
public static void main (String[] args){
printBits (-17);
System.out.println();
printBits (17);
System.out.println( );
}
}

In: Computer Science

Implement the minimum priority queue UnsortedMPQ (using vector) that is a child class of the provided...

Implement the minimum priority queue UnsortedMPQ (using vector) that is a child class of the provided MPQ class. The functions from MPQ that are virtual function (remove min(), is empty(), min(), and insert()) must be implemented in the child classes. The functions remove min() and min() should throw an exception if the minimum priority queue is empty.

For the UnsortedMPQ class, you will use a vector to implement the minimum priority queue functions. The insert() function should be O(1) and the remove min() function should be O(n).

Below I will attach the parent class (MPQ.h), child class (unsortedMPQ.h - needs implementation), and unsortedMPQ-main.cpp - for testing and does not need to be implemented.

Please Code in C++.

MPQ.h

#ifndef MPQ_H
#define MPQ_H

//Abstract Minimum Priority Queue Class
template
class MPQ{
public:
virtual T remove_min() = 0;
virtual T min() = 0;
virtual bool is_empty() = 0;
virtual void insert(const T& data) = 0;
};
#endif

unsortedMPQ.h

#ifndef UNSORTEDMPQ_H
#define UNSORTEDMPQ_H

#include
#include
#include "MPQ.h"

/*
* Minimum Priority Queue based on a vector
*/
template
class UnsortedMPQ: MPQ {

};

#endif

unsortedMPQ-main.cpp (for testing)

#include "UnsortedMPQ.h"
#include

using namespace std;

int main() {
{
UnsortedMPQ mpq;
cout << "Inserting 1 - 5" << endl;
mpq.insert(1);
mpq.insert(2);
mpq.insert(3);
mpq.insert(4);
mpq.insert(5);
cout << "Remove min five times" << endl;
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << endl << endl;
}
{
UnsortedMPQ mpq;
cout << "Inserting 5 - 1" << endl;
mpq.insert(5);
mpq.insert(4);
mpq.insert(3);
mpq.insert(2);
mpq.insert(1);
cout << "Remove min five times" << endl;
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << endl << endl;
}
{
UnsortedMPQ mpq;
cout << "Inserting mixed order 1-5" << endl;
mpq.insert(5);
mpq.insert(2);
mpq.insert(4);
mpq.insert(3);
mpq.insert(1);
cout << "Remove min five times" << endl;
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << endl << endl;
}
{
UnsortedMPQ mpq;
cout << "Testing exception" << endl;
try {
mpq.remove_min();
}
catch (exception& e) {
cout << e.what() << endl;
}
cout << endl;
}
{
UnsortedMPQ mpq;
cout << "Inserting mixed order 1-5" << endl;
mpq.insert(5);
mpq.insert(2);
mpq.insert(4);
mpq.insert(3);
mpq.insert(1);
cout << "Remove min five times" << endl;
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << endl;
cout << "Inserting mixed order 11-15" << endl;
mpq.insert(15);
mpq.insert(12);
mpq.insert(14);
mpq.insert(13);
mpq.insert(11);
cout << "Remove min five times" << endl;
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << ", ";
cout << mpq.remove_min() << endl;
cout << "Testing exception" << endl;
try {
mpq.remove_min();
}
catch (exception& e) {
cout << e.what() << endl;
}
}
return 0;
}

In: Computer Science

Binary Search Tree (Part 1): Note: This is the first part of a 2-part lab. Only...

Binary Search Tree (Part 1):

Note: This is the first part of a 2-part lab. Only this part is due on Oct 29. But please get it working or you will struggle with the second part.

For the second part, the data type will be changing. For now, it is a string.

Contents

Explanation: 2

BST.cpp: 2

Code you must write: 2

bool insert(string s) (7): 2

TNode *find(string s) (4): 2

void printTreeIO(Tnode *n)(3): 2

void printTreePre(Tnode *n) (3): 2

void printTreePost(Tnode *n) (3): 3

TNode *remove(string s)(8) 3

TNode *removeNoKids(TNode *tmp)(5): 3

TNode *removeOneKid(TNode *tmp, bool leftFlag)(7): 3

void setHeight(TNode *n)(10): 3

10 pts for getting everything to work together 3

Methods in CPP I’m Giving You: 3

BST::BST() 3

BST::BST(string s) 3

void BST::clearTree 3

void BST::clearTree(TNode *tmp) 3

void BST::printTreeIO 4

void BST::printTreePre() 4

void BST::printTreePost() 4

BST.HPP (Giving You): 4

/*Phrase.hpp*/ 5

/*Phrase.cpp*/ 5

/*TNode.hpp*/ 6

/*TNode.cpp*/ 6

/*bstmain.cpp*/ 7

Output: 8

Explanation:

For this lab you will be writing the basic methods for a binary search tree. The data in the binary search tree is of type Phrase (a class I am giving to you), and, while this lab is due in 1 week, be aware that many of the methods in this lab will be re-used in the lab that follows it.

To visualize the binary search tree as you are working on it, you can draw it, or you can use numerous on-line visualizers, including this one:

https://www.cs.usfca.edu/~galles/visualization/BST.html

At the end of this document I have included the output from my lab.

The code I am giving you is:

  • Phrase.hpp and Phrase.cpp
  • TNode.hpp and TNode.cpp
  • bstmain.cpp
  • BST.hpp

You must write the methods in BST.cpp that are specified (below):

BST.cpp:

Code you must write:

The code you must write: BST.cpp (i.e., the methods associated with BST.hpp, right below this section, although I am giving you some of the methods in there as well)

/*BST.cpp: You must write the BST.cpp and complete the following methods:*/

bool insert(string s) (7): this method takes as an input parameter a string (which will go into the phrase field of the data when a node is created to be inserted) and returns true if the data is inserted successfully, false otherwise.

Be aware: when you insert a new node into the binary search tree, this method should call the setHeights method to adjust the heights

TNode *find(string s) (4):finds whether s is in the phrase part of the data in the tree,and, if it is, returns the node holding s. Otherwise it returns NULL.

void printTreeIO(Tnode *n)(3): recursive function that prints out the data in the tree in order

void printTreePre(Tnode *n) (3): a recursive function that prints out the datain the tree in pre-order

void printTreePost(Tnode *n) (3): a recursive function that prints out the data in the tree in post-order

TNode *remove(string s)(8) – this method removes a node from the tree, and returns that node. There are 3 cases when you remove a node: either the node being removed has no children (left or right), in which case this method calls the method removeNoKids, the node you are removing has only one child, in which case the method calls removeOneKid (with a Boolean flag set to true if there is a left child, and false if there is a right child), or the node being removed has both a left and a right child, in which you replace the node being removed with the appropriate replacement child, and then remove the node used as a replacement by calling either removeNoKids or removeOneKid, depending on which is appropriate.

NOTE: I used the rightmost of the left child as a replacement. To get my output, you must do the same.

TNode *removeNoKids(TNode *tmp)(5): for removing a node with no children

TNode *removeOneKid(TNode *tmp, bool leftFlag)(7): for removing a node with one child, with the leftFlag indicating whether the node’s child is either the left child or the right child.

void setHeight(TNode *n)(10): This method sets the heights of the nodes in a tree. Once a node is inserted, only the node’s ancestors can have their height changed. Thus you should set the height of the node being inserted (to 1) and then adjust the heights of the node’s parent, grandparent, etc. up until either the height of the node doesn’t change or you hit the root.

20 pts for getting everything to work together

Methods in CPP I’m Giving You:

BST::BST() {

root = NULL;

}

BST::BST(string s) {

root = new TNode(s);

}

void BST::clearTree() {

if (root == NULL) {

cout << "Tree already empty" << endl;

}

else {

cout << endl << "Clearing Tree:" << endl;

clearTree(root);

root = NULL;

}

}

void BST::clearTree(TNode *tmp) {

if (tmp == NULL) {

return;

}

else {

clearTree(tmp->left);

clearTree(tmp->right);

tmp->printNode();

delete(tmp);

}

}

/*Note: the following three functions’ sole job is to call printTreeIO(TNode *t),printTreePre(TNode *t), and printTreePost(TNode *t) while printint out which

Function is being called.

YOU MUST STILL WRITE THE RECURSIVE VERSION OF THESE FUNCTIONS!!!*/

void BST::printTreeIO() { // Just the start – you must write the recursive version

if (root == NULL ) {

cout << "Empty Tree" << endl;

}

else {

cout << endl<<"Printing In Order:" <<endl;

printTreeIO(root);

}

}

void BST::printTreePre() {

if (root == NULL ) {

cout << "Empty Tree" << endl;

}

else {

cout << endl<<"Printing PreOrder:" <<endl;

printTreePre(root);

}

}

void BST::printTreePost() {

if (root == NULL ) {

cout << "Empty Tree" << endl;

}

else {

cout << endl<<"Printing PostOrder:" <<endl;

printTreePost(root);

}

}

BST.HPP (Giving You):

Here is the accompanying BST.hpp code:

#ifndef BST_HPP_

#define BST_HPP_

#include "TNode.hpp"

class BST {

TNode *root;

public:

BST();

BST(string s);

bool insert(string s);

TNode *find(string s);

void printTreeIO();

void printTreeIO(TNode *n);

void printTreePre();

void printTreePre(TNode *n);

void printTreePost();

void printTreePost(TNode *n);

void clearTree();

void clearTree(TNode *tmp);

TNode *remove(string s);

TNode *removeNoKids(TNode *tmp);

TNode *removeOneKid(TNode *tmp, bool leftFlag);

void setHeight(TNode *n);

};

#endif /* BST_HPP_ */

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

/*Phrase.hpp*/

#ifndef PHRASE_HPP_

#define PHRASE_HPP_

#include <iostream>

using namespace std;

class Phrase{

friend class TNode;

friend class BST;

string phrase;

public:

Phrase(string s);

Phrase();

};

#endif /* PHRASE_HPP_ */

/*Phrase.cpp*/

#include <iostream>

#include <string>

#include "Phrase.hpp"

using namespace std;

Phrase::Phrase(string s) {

phrase = s;

}

Phrase::Phrase() {

phrase = "";

}

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

/*TNode.hpp*/

#ifndef TNODE_HPP_

#define TNODE_HPP_

#include <iostream>

#include "Phrase.hpp"

using namespace std;

class TNode{

friend class BST;

TNode *left;

TNode *right;

TNode *parent;

Phrase *data;

int height;

public:

TNode(string s);

TNode();

~TNode();

void printNode();

};

#endif /* TNODE_HPP_ */

/*TNode.cpp*/

#include <iostream>

#include <string>

#include "TNode.hpp"

using namespace std;

TNode::TNode(string s) {

left = NULL;

right = NULL;

parent = NULL;

height = 1;

data = new Phrase(s);

}

TNode::TNode() {

left = NULL;

right = NULL;

parent = NULL;

height = 1;

data = new Phrase();

}

TNode::~TNode(){

cout <<"Deleting "<<data->phrase<<endl;

}

void TNode::printNode() {

cout << data->phrase<<","<<height<<endl;

}

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

/*bstmain.cpp*/

#include "BST.hpp"

#include <iostream>

using namespace std;

int main() {

string arr[] = {"e","g","f","a","c","d","b"};

BST *tree = new BST();

for (int i = 0; i < 7; i++) {

cout << arr[i]<<", ";

tree->insert(arr[i]);

}

cout << endl;

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

tree->clearTree();

cout <<"************************************" << endl;

string arr3[] = {"i","was","contemplating","the","immortal","words","of","socrates","who","said,","i","drank","what"};

for (int i = 0; i < 13; i++) {

cout << arr3[i]<<", ";

tree->insert(arr3[i]);

}

cout << endl;

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

cout << endl<<"REMOVING DRANK" << endl;

tree->remove("drank");

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

cout << endl<<"REMOVING IMMORTAL" << endl;

tree->remove("immortal");

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

cout << endl<<"REMOVING WAS" << endl;

tree->remove("was");

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

cout << endl<<"REMOVING I" << endl;

tree->remove("i");

tree->printTreePre();

tree->printTreeIO();

tree->printTreePost();

tree->clearTree();

return 0;

}

In: Computer Science

Alice is going to create a notebook including the profile of all her friends. For each...

Alice is going to create a notebook including the profile of all her friends. For each of her friends, she would like to keep first-name, last-name, cell number, and birthdate (month and day). At the beginning, she doesn’t know how many spaces she should reserve for recording her friends, so she gradually inputs her friends’ information into it. Please help her by first creating a Java class, called Person, with the required information from description above, along with any required setter/getter methods. Then create, a Java class, called FriendsList, that keeps the list of some persons as someone’s friends, using the Person class above, and performs the required operations, such as add new friends, delete/ modify an existing one, return the list of her friends sorted by last-names, report the number of her friends, report the list of her friends who born in a given month sorted by their day of birth, and report the list of her friends who born in a given day of a month, sorted by their last-names. She also needs to get the cell number of a friend by giving her/his first-name and last-name. Create a tester class, called MyFriends, to test the FriendList class by creating a new object of this class, adding some friends, modifying and deleting some existing friends, retrieving and printing all friends, retrieving and printing the list of friends who born in a given month, retrieving and printing the list of friends who born in a given day of a month, and finding the cell number of an existing friend by giving her/his first-name and last-name. Also, create a separate copy of the FriendList object you have already created, and remove all friends with first-name “Shane” from the new object.

Create a subclass of Person, called Employee, such that it can keep extra information of a person including year of hiring, annual salary, vacation days, and unused vacation days. Provide required setter/getter methods for this class. Create a subclass of Employee, called Manager, which also has monthly bonus, and the list of all her/his employees. Provide required setter/getter methods for this class. Create a class, called Company, with the following information: name of the company, starting year, and the list of all its employees/managers. Provide required setter/getter methods for this class. Create a tester class, called MyCompany, in which you should test all the above classes by creating a company, adding some employees/managers into it. Bonus: Provide two listings of the company’s employees/managers, one sorted by last-names, and one sorted by each manager and then her/his employees.

In: Computer Science

USING PYTHON. Thank you in advance Write a program that allows the user to enter a...

USING PYTHON. Thank you in advance

Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order.

Sample interaction:

Enter string: My

Enter string: name

Enter string: is

Enter string: Sue

Enter string: done

The palindrome is: My name is Sue Sue is name My

In: Computer Science

Write a program to allow a user to play the game Hangman. DO NOT USE AN...

Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY

The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess.

Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the 42nd you need. Here is how you will do this:

String word:

for (int k=0; k<41; k++)

{word=scnr.nextLine();

}//end loop and now pick up the word you want

word=scnr.nextLine() //this is the one you want

The user will be allowed to guess a letter as many times as it takes - but 10 wrong guesses and they lose!!

Eventually either they won or lost. In case they lost print out the answer.

Code language: Java using JGrasp or NetBeans

In: Computer Science

Step 3: Edit MultiSplit.java Download the MultiSplit.java file, and open it in jGrasp (or a text...

Step 3: Edit MultiSplit.java

Download the MultiSplit.java file, and open it in jGrasp (or a text editor of your choice). You will need to write a method that will take an array of Strings (String[]) along with a regular expression, and will call split() on each one of those Strings with the given regular expression. The result of this method should be a two-dimensional array of String (String[][]).

You will also need to write a method to print out this two-dimensional array of Strings.

The main method will call both methods, using “,” as the regular expression. Example output is shown below, which corresponds to the command-line arguments "one,two,three" " alpha,beta,gamma" "delta" "first,second":

0: one two three
1: alpha beta gamma
2: delta
3: first second

The output above shows that the 0th element ("one,two,three") produced the values one, two, and three when a split with “,” was performed. Each subsequent line follows the same general pattern for all the subsequent indices in the command-line argument array

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

public class MultiSplit {
    // TODO - write your code below this comment.
    // You will need to write two methods:
    //
    // 1.) A method named multiSplit which will take an
    //     array of strings, as well as a String specifying
    //     the regular expression to split on.
    //     The method returns a two-dimensional array, where each
    //     element in the outer dimension corresponds to one
    //     of the input Strings.  For example:
    //
    //     multiSplit(new String[]{"one,two", "three,four,five"}, ",")
    //
    //     ....returns...
    //
    //     { { "one", "two" }, { "three", "four", "five" } }
    //
    // 2.) A method named printSplits which will take the sort
    //     of splits produced by multiSplit, and print them out.
    //     Given the example above, this should produce the following
    //     output:
    //
    //     0: one two
    //     1: three four five
    //
    //     Each line is permitted (but not required) to have a trailing
    //     space (" "), which may make your implementation simpler.
    //
    
    // DO NOT MODIFY main!
    public static void main(String[] args) {
        String[][] splits = multiSplit(args, ",");
        printSplits(splits);
    }
}

In: Computer Science

A) Is it important to have a break after every case in the switch statement?) b)...

  1. A) Is it important to have a break after every case in the switch statement?)

b) Explain lain your answer by writing an example of a switch statement and showing the effect of including and excluding the break.

                                                                                                                                                              10 points

  1. A) String Name = KB.NextLine();

      Write a java statement to convert Name to upper case.

B) char Letter =KB.next().charAt(0);

          Write a java statement to convert Letter to lower case.

                                                                                                                                                       5 points

c) Write a while loop which allows the user to enter numbers between 1 and 15, the loops keep iterating as long as the total of the entered numbers is less than 1000.

                                                                                                                                                      15 points  

                                                                                                                                                                    

  1. Write an example of a trailing else, and explain the importance of using the trailing else statement.

5 points

  1. A) Write an example of an if-else and an example of a simple if statements.B) Write an example of nested if statement

15 points

THIS IS FOR JAVA PROGRAMMING. PLEASE ANSWER ASAP. THANK YOU

In: Computer Science

You need to combine some small pieces of chocolate (1 ounce) and some large pieces of...

You need to combine some small pieces of chocolate (1 ounce) and some large pieces of chocolate (5 ounces) to make a goal. Assuming you always use as many large pieces as possible, complete the function "makeChocolate" which returns the number of small pieces that you will use. Return -1 if it is not possible. Be sure to carefully test your code before submitting it. Make sure to answer in python coding for full credit.
For example, makeChocolate(4,1,9) returns 4 because you use 1 large piece and 4 small pieces to get 9 ounces.
makeChocolate(4,1,10) returns -1 because 1 large and 4 small pieces are only 9 ounces, not enough to make 10 ounces.
makeChocolate(3,2,10) returns 0 because you would use 2 large pieces and 0 small pieces to make 10 ounces.

In: Computer Science

Latest version of CSS. What is the browser requirement to view the latest version of CSS...

  1. Latest version of CSS.
  2. What is the browser requirement to view the latest version of CSS implemented web pages? Name 1 or 2 web browser types and versions that support the latest CSS.
  3. How do web designers design a web page with the latest CSS version?

In: Computer Science

CSC 466 Spring 2017 Assignment:: A6 Basic Type System --------------------------------------------------------------- Your assignment: Build the basic type...

CSC 466 Spring 2017
Assignment:: A6
Basic Type System
---------------------------------------------------------------

Your assignment: Build the basic type system
- type set at declaration
- consult sym-tab on var usage
- build type of expression based on parts
- LHS = RHS types should match
** Also make sure vars are declared of course


Note:: we started this in class
-- start with the project you already have from
/tmp/466T/ic0315.tar.gz
that we worked on in class on Wed 3/15

*************************************************************
Kinds of changes you may need to make.....
- scanner for new symbols/keywords
-- regular expressions
- parser for expression operators, ...
-- grammar rules
- symbol table entries
-- calling functions
- type table for new types
-- calling functions
- symbol & type table look-up
-- the code

*************************************************************

Additions: (make these enhancements to the language/project)

floating point literals
** must have . and exactly 2 digits to right
-- such as: 7.23 123.45

Error message for double-declared variables

type system rules
assignment operator:
may only assign
int into int
bool into bool

may assign
float into float
int into float

math operators:
int + int -> int
float + float -> float
float + int -> float
int + float -> float
same for *
Add - with same rules
Add / but result of
any division using int and/or float is float

Add ( ) to expressions

Submission: In your CS directory by
8:00am on Tuesday 3/28

* create Type2Lastname as the directory
containing your solution
- clearly, replace "Lastname" by your name
* be sure your makefile works
* create a README file explaining
- how to run your solution
- sample programs to illustrate correctness
- clean programs; program with errors; ...
* clean the generated files
* tar your solution
% tar -cf type2lastname.tar Type2Lastname
* make sure your tar file is in your home directory
and not some other subdirectory
- don't make me look for it

Here is the makefile:

go: lex.yy.c w.tab.c
gcc w.tab.c lex.yy.c -lfl -ly -o go

lex.yy.c: w.l
flex w.l

w.tab.c: w.y
bison -dv w.y

clean:
rm -f lex.yy.c
rm -f w.output
rm -f w.tab.h
rm -f w.tab.c
rm -f go

Here is the lex code:

%{

typedef struct
{
char thestr[25];
int ival;
int ttype;
}tstruct ;

#define YYSTYPE tstruct

#include "w.tab.h"

%}

DIGIT [0-9]
UC [A-Z]
LC [a-z]
L [A-Za-z]

%%

START { return tstart;}
FINISH { return tfinish;}
BEGIN { return tbegin;}
END { return tend;}
INT { return tint;}
FLOAT { return tfloat;}
BOOL { return tbool;}
PRINT { return tprint;}
PRINTLN { return tprintln;}
IF { return tif;}
WHILE { return twhile;}
LT { return tlt;}
GT { return tgt;}
EQ { return teq;}
":(" { return tfalse;}
":)" { return ttrue;}
":=" { return tassign;}

\"([^"]*)\" { return tstrlit;}
{L}+ { return tid; }
{DIGIT}+ { return tnum; }


@@.*\n {} /* comments */


[ \t] /* ignore whitespace */

\n {}

<<EOF>> yyterminate(); /* signal end of dialogue */

. return yytext[0];

%%

Here is the yacc code:

%{

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef struct
{
char thestr[25];
int ival;
int ttype;
}tstruct ;

#define YYSTYPE tstruct

int yylex();
void yyerror( char *s );


#include "symtab.c"

%}

%token tstart
%token tfinish
%token tbegin
%token tend
%token tint
%token tfloat
%token tbool
%token tprint
%token tprintln
%token tif
%token twhile
%token tlt
%token tgt
%token teq
%token tfalse
%token ttrue
%token tassign
%token tstrlit
%token tid
%token tnum

%%

p : prog ;

prog : tstart tfinish
| tstart DL SL tfinish {printf("Prog\n");}
;

DL : DL D {printf("declst\n");}
| D {printf("declst\n");}
;


D : tid Dtail { addtab($1.thestr);
addtype($1.thestr, $2.ttype);
}
;

Dtail : ',' tid Dtail { addtab($2.thestr);
addtype($2.thestr, $3.ttype);
$$.ttype = $3.ttype;
}
| ':' type ';' {$$.ttype = $2.ttype;}
;

type: tint {$$.ttype = 10;} | tfloat {$$.ttype = 20;} | tbool {$$.ttype = 30;} ;

SL : SL S {printf("stmtlst\n");}
| S {printf("stmtlst\n");}
;

S : tprint tstrlit ';' {printf("print lit\n"); }
| tprint tid ';'
{
printf("print id\n");
if ( intab($2.thestr) )
printf("%s is declared %d\n", $2.thestr, @2.first_line);
else
printf("UNDECLARED:: %s \n", $2.thestr);
}
| tprintln ';'
| tid tassign expr ';'
{
printf("assign\n");
if ( intab($1.thestr) )
printf("%s is declared\n", $1.thestr);
else
printf("UNDECLARED:: %s \n", $1.thestr);

$1.ttype = gettype($1.thestr);
if ($1.ttype > 0 )
{
if ($1.ttype == $3.ttype)
;
else
{
printf("Incompatible ASSIGN types %d %d\n", $1.ttype, $3.ttype);
}
}
else
yyerror("Type Error :::");


}
| error ';' {printf("error in statement\n");}
;

expr : expr '+' term
{
if ($1.ttype == 10 && $3.ttype == 10) $$.ttype = 10;
else if ($1.ttype == 20 && $3.ttype == 20) $$.ttype = 20;
else $$.ttype = -1;
}
| term { $$.ttype = $1.ttype; }
;

term : term '*' factor
{
if ($1.ttype == 10 && $3.ttype == 10) $$.ttype = 10;
else if ($1.ttype == 20 && $3.ttype == 20) $$.ttype = 20;
else $$.ttype = -1;
}
| factor { $$.ttype = $1.ttype; }
;

factor : tid
{
if ( intab($1.thestr) )
printf("%s is declared\n", $1.thestr);
else
printf("UNDECLARED:: %s \n", $1.thestr);
$$.ttype = gettype($1.thestr);
if ($$.ttype > 0 )
;
else
yyerror("Type Error :::");
}
| tnum {$$.ttype = 10;}
| ttrue {$$.ttype = 30;}
| tfalse {$$.ttype = 30;}
;

%%


int main()
{
yyparse ();
printf("---------------------\n");
showtab();
}

void yyerror(char *s) /* Called by yyparse on error */
{
printf ("\terror: %s\n", s);
printf ("ERROR: %s at line %d\n", s, 123);
}

Here is the sym.c code

struct stelem
{
char sname[25];
int stype;
};
typedef struct stelem entry;


entry symtab[100];
int nsym;


void addtab( char *s)
{
nsym++;
strcpy( symtab[nsym].sname, s);
symtab[nsym].stype = -1;
}

void showtab()
{
int i;
for (i = 1; i <= nsym; ++i)
printf("%d: %s %d\n", i, symtab[i].sname, symtab[i].stype);
}

int intab( char *s)
{
int i;
for ( i = 1; i <= nsym; ++i)
{
if ( strcmp(symtab[i].sname, s) == 0)
return 1;
}
return 0;

}

int addtype( char *s, int t)
{
int i, loc = -1;
for ( i = 1; i <= nsym; ++i)
{
if ( strcmp(symtab[i].sname, s) == 0)
loc = i;
}
if (loc > 0)
{
printf("Set type %s to %d\n", s, t);
symtab[loc].stype = t;
}
else
{
printf("Unable to set type %s to %d\n", s, t);
}
}


int gettype( char *s)
{
int t = -1;
int i, loc = -1;
for ( i = 1; i <= nsym; ++i)
{
if ( strcmp(symtab[i].sname, s) == 0)
loc = i;
}
if (loc > 0)
{
t = symtab[loc].stype;
printf("Get type for %s to %d\n", s, t);
}
if (loc <= 0)
printf("gettype var %s not found\n", s);
else if (t < 0)
printf("gettype var %s has bad type %d\n", s, t);
else
printf("gettype var %s has type %d\n", s, t);

return t;
}

In: Computer Science

This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This...

This is Python programming

Focus
1. Classes and Objects

2. Creating objects

3. Manipulating objects

This lab maps to learning the following objectives: Write a working program that creates a Class, Instances of Objects from that Class, and Functions that use Objects as parameters.

For this portion of the lab, you will create a new program for your Professor. Create a class named Student that holds the following data about a student:

1. Name

2. Student ID number

3. GPA

4. Expected grade in this course

5. Full time or part time

Create five student objects from this class and pass data to fill in the class data above. Besides creating the objects, you will write a menu-driven program that performs the following tasks:
1. Look up and print the student GPA

2. Add a new student to the class

3. Change the GPA of a student

4. Change the expected grade of a student

5. Print the data of all the students in a tabular format

6. Quit the program Save all the files that you create in this program with appropriate file names.

In: Computer Science