C++
(1) Prompt the user to enter a string of their choosing
(Hint: you will need to call the
getline() function to read a string consisting of white
spaces.) Store the text in a string. Output the string. (1
pt)
Ex:
Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
(2) Implement a PrintMenu() function, which has a string as a
parameter, outputs a menu of user options for analyzing/editing the
string, and returns the user's entered menu option. Each option is
represented by a single character. If an invalid character is
entered, continue to prompt for a valid choice. Hint: Implement
Quit before implementing other options.
Call PrintMenu() in the main() function. Continue to call PrintMenu() until the user enters q to Quit.
More specifically, the PrintMenu() function will consist of the following steps:
Ex:
MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option:
(3) Implement the GetNumOfNonWSCharacters() function.
GetNumOfNonWSCharacters() has a constant string as a parameter and
returns the number of characters in the string, excluding all
whitespace. Call GetNumOfNonWSCharacters() in the PrintMenu()
function.
Ex:
Number of non-whitespace characters: 181
(4) Implement the GetNumOfWords() function. GetNumOfWords() has a
constant string as a parameter and returns the number of words in
the string. Hint: Words end when a space is reached except for
the last word in a sentence. Call GetNumOfWords() in the
PrintMenu() function.
Ex:
Number of words: 35
(5) Implement the FindText() function, which has two strings as
parameters. The first parameter is the text to be found in the user
provided sample text, and the second parameter is the user provided
sample text. The function returns the number of instances a word or
phrase is found in the string. In the PrintMenu() function, prompt
the user for a word or phrase to be found and then call FindText()
in the PrintMenu() function. Before the prompt, call
cin.ignore() to allow the user to input a new
string.
Ex:
Enter a word or phrase to be found: more "more" instances: 5
(6) Implement the ReplaceExclamation() function.
ReplaceExclamation() has a string parameter and updates the string
by replacing each '!' character in the string with a '.' character.
ReplaceExclamation() DOES NOT return the revised string. Call
ReplaceExclamation() in the PrintMenu() function, and then output
the edited string.
Ex.
Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue.
(7) Implement the ShortenSpace() function. ShortenSpace() has a
string parameter and updates the string by replacing all sequences
of 2 or more spaces with a single space. ShortenSpace() DOES NOT
return the revised string. Call ShortenSpace() in the PrintMenu()
function, and then output the edited string.
Ex:
Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
______________________________________________
#include <iostream>
#include <string>
using namespace std;
int main() {
/* Type your code here. */
return 0;
}
In: Computer Science
Project objective: To learn more about OS scheduling through a hands-on simulation programming experience
Implement the following 3 CPU scheduling algorithms
Multilevel Feedback Queue (absolute priority in higher queues)
Queue 1 uses RR scheduling with Tq = 5
Queue 2 uses RR scheduling with Tq = 10
Queue 3 uses FCFS
All processes enter first queue 1. If time quantum (Tq) expires before CPU burst is complete, the process is downgraded to next lower priority queue. Processes are not downgraded when preempted by a higher queue level process. Once a process has been downgraded, it will not be upgraded.
Assumptions:
Process Data:
process goes {CPU burst, I/O time, CPU burst, I/O time, CPU burst, I/O time,…….., last CPU burst}
P1 {5, 27, 3, 31, 5, 43, 4, 18, 6, 22, 4, 26, 3, 24, 4}
P2 {4, 48, 5, 44, 7, 42, 12, 37, 9, 76, 4, 41, 9, 31, 7, 43, 8}
P3 {8, 33, 12, 41, 18, 65, 14, 21, 4, 61, 15, 18, 14, 26, 5, 31, 6}
P4 {3, 35, 4, 41, 5, 45, 3, 51, 4, 61, 5, 54, 6, 82, 5, 77, 3}
P5 {16, 24, 17, 21, 5, 36, 16, 26, 7, 31, 13, 28, 11, 21, 6, 13, 3, 11, 4}
P6 {11, 22, 4, 8, 5, 10, 6, 12, 7, 14, 9, 18, 12, 24, 15, 30, 8}
P7 {14, 46, 17, 41, 11, 42, 15, 21, 4, 32, 7, 19, 16, 33, 10}
P8 {4, 14, 5, 33, 6, 51, 14, 73, 16, 87, 6}
PLEASE CODE IN C++ FOR ALL 3
In: Computer Science
IT can be described as having three waves: automate individual functions, integrate value chains, incorporate IT into product and service offerings. Give an example of each (automate, integrate, incorporate) for specific businesses and cite your sources.
In: Computer Science
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