Questions
Letters are pushed on a stack in order: R A N D O M O P...

Letters are pushed on a stack in order: R A N D O M O P S. Specify where to insert pop operations (shown by ‘*’) among the pushes of the given letters, in order to produce the output: ADONOMSPR . You can only do this process once. That is, you cannot take the output produced and then pass it again through the stack.

In: Computer Science

CS 400 Assignment 4 Stack application: postfix expression evaluation. Description: - The stack data structure can...

CS 400 Assignment 4
Stack application: postfix expression evaluation.

Description:
- The stack data structure can be used to evaluate postfix expressions. Please refer to the first 14 pages of this tutorial for postfix expression evaluation: http://www.cs.nthu.edu.tw/~wkhon/ds/ds10/tutorial/tutorial2.pdf

Requirement:
- deal with single digit positive integers only. Operands and operators are fully separated by space. 
- learn and use STL stack: http://www.cplusplus.com/reference/stack/stack/
- learn and use isdigit(): http://www.cplusplus.com/reference/cctype/isdigit/  
- take in a postfix arithmetic expression from cin, and evaluate its value. 
- supported operators: +, -, *, /
- for invalid postfix expression, print out an error message and end the program. 
- output the evaluated value of valid expressions. 

Example1: 
- (valid expr) 4 3 - 5 * 
-- push 4 into stack 
-- push 3 into stack 
-- minus operator (-) detected: pop 3 out of stack, as operand_2
-- pop 4 out of stack, as operand_1
-- perform operand_1 minus operand_2, then push the result (1) into stack. 
-- push 5 into stack 
-- multiply operator (*) detected: pop 5 out of stack, as operand_2
-- pop 1 out of stack, as operand_1
-- perform operand_1 times operand_2, then push the result (5) into stack. 
-- input done. check stack value... output final answer: 5

Example2: 
- (invalid expr) 4 4 3 - 5 * is invalid since the stack will have two numbers inside it. 
- (invalid expr) 4 5 5 - / is invalid due to the divide-by-zero error. 

Grading:
- compilable and meaningful attemps: 20 points. 
- correct usage of STL stack: 20 points, including object creation, push(), top() and pop().
- correct postfix expression evaluation: 30 points.
- error handling: 20 points, including divide-by-zero error and invalid expression error
- comments, file_name and indentation: 10 points. 

File_name: 
postfix_eval.cpp

In: Computer Science

C++ write a function called divideBy that takes two integers as its input and returns the...

C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.

In: Computer Science

1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’...

1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’ and a single output-line ’Z’. An output of 1 is to be produced coincident with the pattern 1101 and an output of ‘ 0’ is to be produced for all the other sequences and simulate it.

In: Computer Science

Design and implement a function with two input parameters, A and B. The functions then calculates...

Design and implement a function with two input parameters, A and B. The functions then calculates the result of the floor division of A over B (A//B). You are not allowed to use the floor division operator. Look at here: https://simple.wikipedia.org/wiki/Division_(mathematics) - For instance the function for 20 and 6 will return 3.

In: Computer Science

C++ using vectors. in the following code, if a user adds duplicate names the votes should...

C++ using vectors.

in the following code, if a user adds duplicate names the votes should be added to only one of the names:

example

display "Enter candidate name: "

input john

display "Enter candidate vote:"

input 10

display "Enter candidate name: "

input john

display "Enter candidate vote:"

input 10

so the output has to be

john with 20 votes.

#include<iostream>

#include<iterator>

#include<string>

#include<algorithm>

#include<array>

#include<ctime>

#include <vector>

#include<bits/stdc++.h>

using namespace std;

int max_element(const vector<int>&stuff)

{

int max_index =0;

for (int i=1; i<stuff.size();++i)

if (stuff[i]>stuff[max_index])

max_index=i;

return max_index;

}

template <typename type>

void show(const vector<type>&stuff)

{

for (int i=0; i<stuff.size(); i++)

cout <<stuff[i]<<' ';

}

int main()

{

vector<string> names;

vector<int> votes;

string name;

int vote;

int size=5;

for (int i=0; i<size;++i)

{

cout<<"enter candidates "<< i+1<<" name: ";

getline(cin, name,'\n');

cout<<"Enter "<<name<< "'s votes ";

cin>>vote;

cin.get();

names.push_back(name);

votes.push_back(vote);

}

  

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

{

sort(names.begin(),names.end());

if (names[k-1]==names[k]){

return votes[k];

cout<<"votes "<<votes[k]<<endl;

}

}

int max_index= max_element(votes);

for (int j=0;j<size;++j){

if (votes[j]==votes[max_index])

cout<<"The winners list is bellow "<< names[j]<<endl;

}

return 0;

}

In: Computer Science

1 Purpose This is another program for reading from files. In this program we will read...

1 Purpose
This is another program for reading from files. In this program we will read blocks of data from a (well-formatted) file that you will be given and make some computations on that data.
The input file will be formatted as described later in this document. It will be similar the “block” data from Lecture 10.
2 Procedure
You will create one source code program, Prog07.cpp. This program will
1. Prompt the user for an input filename. Store the filename as a string object. See Lectures 10 and 11. Then prompt the user for an output filename. Store it the same way.
2. Open the input filename for reading. Open the output filename for writing with append. If you cannot open either of the filenames the user supplied, prompt the user for two more. Repeat this until you can open the both user’s files. I found that if you want to use just the plain file name, the file should be placed the directory where Visual Studio puts the “.vcxproj” file and the “.cpp” file. Otherwise you have to give the FULL path to the file. If you put the file on the Desktop, the filename will be something like
C:\users\your_user_name\Desktop\your_real_file_name
3. Once the files are open, read in blocks of data until one of two things happens:
• You reach the end of the file. • The block you read in has an ID number of 0.
1
4. The data you are provided will be stored in files using a structure that is defined like this:
struct employee { int id; char department[25]; float hours; };
5. For each block of data (unless its ID number is 0) add the number of hours to compute a total hours.
6. Count the number of employees. Every block with an ID number greater than 0 is another employee. Do not worry about duplicates.
7. Once you are through reading, the program will write three lines of output to the output file (the last line is just blank) like
Filename.info: 76 employees Total hours: 192.8, Average per employee: 19.7278 hours.
That should be the actual filename you used NOT “Filename.info.” See the end of this document for some example runs of the program.
8. Make sure that you close both the files before exiting.
9. If you have done this correctly, you can reuse the output filename and see the output of all the tests in it.
10. Upload your solution to the WyoCourses site, Program 07 assignment.
11. Your solution should consist of exactly 3 files:
(a) A C++ source code file, Prog07.cpp which contains all of the code for the main program as well as the code for all the functions. (b) A text file, Prog07Test.txt which contains the results of the tests of your program using all four of the data files. Remember to test that if you supply incorrect input filenames, the program prompts again for new filenames. If you give it the “wrong” output filename, the program will just create a new file. (c) A text file, Prog07Output.txt which contains the actual program output of the the four tests. (d) I am not going to require a pseudocode file this time.
2
Program 07 Tests.
Example results from a completed version of “Prog07.cpp” using only the “data1.info” and “data2.info” files. Note that “type” is a command line command that ’dumps’ text files to the terminal. You could just open the output file in any text editor (I would not use notepad, but notepad++ works well).
buckner ~...prog07/solution> Prog07.exe
Please enter an input filename: data1.info Please enter an output filename: output.txt
buckner ~...prog07/solution> Prog07.exe
Please enter an input filename: data2.info Please enter an output filename: output.txt
buckner ~...prog07/solution> type output.txt
data1.info: 25 employees. total hours: 1221.92, Average per employee: 48.8769 hours.
data2.info: 15 employees. total hours: 907.893, Average per employee: 60.5262 hours.
buckner ~...prog07/solution>

what ive got so far....

// Prog07.cpp
// Nick Hill
// COSC1030 lab section 12
// program 07

#include<iostream>
#include<fstream>
#include<string>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::ofstream;
using std::ifstream;
using std::string;
using std::getline;

struct employee
{
   int id;
   char department[25];
   float hours;
}emp;

int main()
{
   ofstream write;
   ifstream read;
   string inFile,
       outFile;
   bool open = 0;
   while (!open)
   {
       cout << "Enter an input filename: ";
       getline(cin, inFile);
       cout << "Enter an output filename: ";
       getline(cin, outFile);

       read.open(inFile);
       write.open(outFile, std::ofstream::app);
       if (read.is_open() && write.is_open())
       {
           open = 1;
       }
   }
   read.eof();
   if(!read.eof())
   {

   }


i cant figure out where to go from here

In: Computer Science

Can you fix to me this code plz I just want to print this method as...

Can you fix to me this code plz

I just want to print this method as the reverse. the problem is not printing reverse.

public void printBackward() {
      
       Node curr = head;
       Node prev = null;
       Node next = null;
      
       System.out.print("\nthe backward of the linkedlist is: ");
      
       while(curr != null) {

           next = curr.next;
           curr.next = prev;
           prev = curr;
           curr = next;
          
           System.out.print(" " + prev.data);
          
       }

In: Computer Science

Q8.1 Describe the need for switching and define a switch. Q8.2 List the three traditional switching...

Q8.1 Describe the need for switching and define a switch.

Q8.2 List the three traditional switching methods. Which are the most common today?

Q8.4 Compare and contrast a circuit switched network and a packet-switched network. (How are they alike and how are they different)

Q8-8 What is TSI and what is its role in time-division switches.

Q8-10 List four major components of a packet switch and their functions.

In: Computer Science

Create a derived class that allows you to reset the number of sides on a die....

  1. Create a derived class that allows you to reset the number of sides on a die. (Hint: You will need to make one change in diceType.) -- Completed in Part 1
  2. Overload the << and >> operators. -- Completed in Part 1
  3. Overload the +, -, and ==, <, > operators for your derived class.
  4. Overload the = operator.

I need help with 3 and 4 of the question. I've already completed step 1 and 2

Note: You should test each step in a client program.

//diceType.h

#ifndef H_diceType
#define H_diceType

class diceType
{
public:
diceType();
// Default constructor
// Sets numSides to 6 with a random numRolled from 1 - 6

diceType(int);
// Constructor to set the number of sides of the dice

int roll();
// Function to roll a dice.
// Randomly generates a number between 1 and numSides
// and stores the number in the instance variable numRolled
// and returns the number.

int getNum() const;
// Function to return the number on the top face of the dice.
// Returns the value of the instance variable numRolled.

protected:
int numSides;
int numRolled;
};
#endif // H_diceType

===================================

//diceTypeImp.cpp

//Implementation File for the class diceType

#include
#include
#include
#include "diceType.h"

using namespace std;

diceType::diceType()
{
srand(time(nullptr));
numSides = 6;
numRolled = (rand() % 6) + 1;
}

diceType::diceType(int sides)
{
srand(time(0));
numSides = sides;
numRolled = (rand() % numSides) + 1;
}

int diceType::roll()
{
numRolled = (rand() % numSides) + 1;

return numRolled;
}

int diceType::getNum() const
{
return numRolled;
}

=========================================

//diceTypeDerived.h

#ifndef diceTypeDerived_H
#define diceTypeDerived_H

#include "diceType.h"
#include
#include


class diceTypeDerived : public diceType
{
friend std::ostream& operator<<(std::ostream&, const diceTypeDerived &);
friend std::istream& operator>>(std::istream&, diceTypeDerived &);

public:
diceTypeDerived(int = 6);

void SetSides(int);
};

#endif // diceTypeDerived_H

===================================

//diceTypeDerived.cpp (Implementation file)

#include "diceTypeDerived.h"

diceTypeDerived::diceTypeDerived(int sides) : diceType(sides) { }

std::ostream& operator << (std::ostream& osObject, const diceTypeDerived& dice) {

osObject << dice.numRolled;

return osObject;
}

std::istream& operator >> (std::istream& isObject, diceTypeDerived& dice) {
int tempNum;

isObject >> tempNum;

if (tempNum < dice.numSides)
dice.numRolled = tempNum;
else
dice.numRolled = dice.numSides;

return isObject;
}

void diceTypeDerived::SetSides(int newSides){
numSides = newSides;
}

==========================================

//test.cpp

#include "diceTypeDerived.h"
#include

using namespace std;

int main() {
diceTypeDerived dice1, dice2;

dice1.roll();
dice1.SetSides(12);
dice1.roll();

cout << "Set value rolled for dice2: ";
cin >> dice2;

cout << "dice1: " << dice1 << " dice2: " << dice2 << endl;

return 0;
}

In: Computer Science

In three complete and well composed paragraphs, describe PDF files and HTML. Explain the difference between...

In three complete and well composed paragraphs, describe PDF files and HTML. Explain the difference between presenting information in both formats. In what instances would a PDF file be preferable? In what instances would HTML be a preferred format?

In: Computer Science

What were the benefits of implementing an EDW at Isle? Can you think of other potential...

What were the benefits of implementing an EDW at Isle? Can you think of other potential benefits that were not listed in the case?

What are ROLAP, MOLAP, and HOLAP? How do they differ from OLAP?

In: Computer Science

Many people criticize what we’ve covered so far as not being true artificial intelligence. This criticism...

  1. Many people criticize what we’ve covered so far as not being true artificial intelligence. This criticism is often targeted at expert systems specifically but also at the idea of search itself as Artificial intelligence. Briefly answer the following in your own words (2-4 sentences)

(These will be graded both on the quality of your argument and your demonstration of understanding of what Expert systems are and what the Turing test is.)

Credit will only be given for typed answers.

  1. Do you believe expert systems can be defined as intelligence? Support your answer.
  2. Do you think Turing’s test is a good evaluation for whether or not an expert system is intelligent? Support your answer.

In: Computer Science

Create a Python program that includes each feature specified below. Comments with a detailed description of...

Create a Python program that includes each feature specified below.

  • Comments with a detailed description of what the program is designed to do in a comment at the beginning of your program.
  • Comments to explain what is happening at each step as well as one in the beginning of your code that has your name and the date the code was created and/or last modified.
  • The use of at least one compound data type (a list, a tuple, or a dictionary).
  • Use of at least one method with your compound data type.
  • Use of at least one Python built-in function with your compound data type.
  • An if statement with at least two elif statements and an else statement.
  • A nested if statement.
  • At least one value input by the user during the program execution.
  • At least one result reported to the user, that varies based on the value(s) that they input.

In: Computer Science

Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an...

  1. Programming assignment (75 pts):

The Lab 1 development assignment was largely an exercise in completing an already started implementation. The Lab 2 development assignment will call on you to implement a program from scratch. It’s an exercise in learning more about Java basics, core Java Classes and Class/ method-level modularity.

Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented.

  • NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric values do not need to be ordered (although you’ll need to display these values sorted ascendingly).

NOTE: Don’t prompt the user for input – this is an exercise passing values to your program via the command line!

  • Error checking: if the user fails to pass in parameters, the program will display an error message (of your choice) and exit early.
  • The main() method’s String [] args argument values must be converted and assigned to a numeric/integer array.
  • Your program will display the following information about the numbers provided by the user:
    1. This list of numbers provided by the user sorted ascendingly.
    2. The size of number list (the number of numbers!)
    3. The average or mean value.
    4. The median - the middle value of the set of numbers sorted. (Simple Algorithm: index = the length of the array divided by 2).
    5. The min value.
    6. The max value.
    7. The sum
    8. The range: the difference between the max and min
    9. Variance: Subtract the mean from each value in the list. This gives you a measure of the distance of each value from the mean. Square each of these distances (and they’ll all be positive values), add all of the squares together, and divide that sum by the number of values (that is, take the average of these squared values) .
    10. Standard Deviation: is simply the square root of the variance.

Development guidelines:

  • The output should be neat, formatted and well organized – should be easy on the eyes!
  • Your code should adhere to naming conventions as discussed in class.
  • Your main() method’s actions should be limited to:
    • gathering command line arguments
    • displaying error messages
    • creating an instance of NumericAnalyzer and invoking its top level method (e.g., “calculate()”, “display()” )
  • The “real work” should be performed by instance methods. That is, your implementation should embrace modularity:
    • Each mathematical calculation should probably be implemented by a separate method.
    • Yet another method should be responsible for displaying a sorted list of the numbers provided, and displaying all derived values above.

NOTE: Deriving calculations and displaying output to a Console are separate threads of responsibility, and should therefore be implemented independently of each other.

  • Your implementation should embrace using core Java modules:
    • Use the java.lang.Math Class methods to calculate square roots and perform power-to values.

So your main() method will include a sequence of instructions similar to this:

// main() method code fragment example
if(args.length == 0 ) {

// Display some error message … (System.err. )

System.exit(1);

}

NumericAnalyzer analyzer = new NumericAnalyzer(args);

analyzer.calculate();

analyzer.display();

System.exit(0);

Your ‘test cases’ should include testing for (see sample output below –PASTE YOUR Console OUTPUT ON PAGE 5 below):

  1. No input parameters – error condition.
  2. 1 value
  3. Multiple values – at least 6+ …

SAMPLE OUTPUT FOR TEST CASES 1, 2,   & 3

  1. Pass in 1 or more positive integer number values.

(2)

256

Count:                             1

Min:                             256

Max:                             256

Range:                             0

Sum:                             256

Mean:                            256

Median:                          256

Variance:                          0

Standard Deviation:                0

(3)

2    4    8    16   32   64   128 256 512

Count:                             9

Min:                               2

Max:                             512

Range:                           510

Sum:                           1,022

Mean:                            113

Median:                           32

Variance:                     25,941

Standard Deviation:              161

PASTE YOUR OUTPUT HERE

0 args

1 arg

multiple args (at least 6)

Sample output

2       4       8       16      32     64   128     256     512   

Size:                              9

Min:                               2

Max:                             512

Range:                           510

Sum:                           1,022

Mean:                            113

Median:                           32

Variance:                     25,941

Standard Deviation:              161

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

Lab 1 java code (if needed)

public class JulianCalendar {

         

        static private final int MAX_DAY = 31;
         

        static private final String[] MONTH_NAMES = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",

        "Nov", "Dec" };

         

        static private final int[] MONTH_SIZES = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 

        static private void displayDayHeading() {

                System.out.printf("%6s", "Day");

        }
         

        static private void displayHeading() {

                displayDayHeading();

                for (int i = 0; i < MONTH_NAMES.length; ++i) {

                        System.out.printf("%5s", MONTH_NAMES[i]);

                }

                displayDayHeading();

        }

        static public void display() {

                displayHeading(); 

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

                        System.out.printf("\n%6d", i + 1);

                        for (int j = 0; j < MONTH_NAMES.length; j++) {

                                int sum = 0;

                                for (int k = 0; k < j; k++) {

                                        sum += MONTH_SIZES[k];

                                }

                                if (sum + MONTH_SIZES[j] >= sum + i + 1)

                                        System.out.printf(" %03d", sum + i + 1);

                                else

                                        System.out.printf(" %03d", 0);

                        }

                        System.out.printf("%6d", i + 1);

                }

                System.out.println();

        }



        public static void main(String[] args) {

                 

                display();

        }

}

In: Computer Science