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 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
In: Computer Science
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 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 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 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 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 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
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 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 benefits that were not listed in the case?
What are ROLAP, MOLAP, and HOLAP? How do they differ from OLAP?
In: Computer Science
(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.
In: Computer Science
Create a Python program that includes each feature specified below.
In: Computer Science
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.
NOTE: Don’t prompt the user for input – this is an exercise passing values to your program via the command line!
Development guidelines:
NOTE: Deriving calculations and displaying output to a Console are separate threads of responsibility, and should therefore be implemented independently of each other.
So your main() method will include a sequence of instructions similar to this:
|
// main() method code fragment example // 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):
SAMPLE OUTPUT FOR TEST CASES 1, 2, & 3
|
|
(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