Please, write code in c++. Using iostream and cstring library
Use pointers!
You given a text.Your task is to write a function that will find
the longest sequence of digits inside.
Note that the output have to be presened just like in sample.
Note. The program have to use pointer.
Input:
First line contains one line that is not longer than 1000.
Output:
The longest sequence of numbers.All numbers are positive and
integers.
Samples:
№ | INPUT | OUTPUT |
1 | This is the longest - 10001 number | 10 001 |
2 | 101 fdvnjfkv njfkvn fjkvn jffdvfdvfd2010 | 2 010 |
2 | 1a11 | 11 |
In: Computer Science
IP address: 158.234.28.72 Subnet Mask: 255.248.0.0 Find Network Address and Broadcast address. Provide all necessary steps.
In: Computer Science
Write a C program that runs on ocelot for a mini calculator
using only the command line options. You must use getopt to parse
the command line.
Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-e]
value
• The variable value is the starting value.
• Value should be validated to be an integer between 1 and 99.
Error message and usage shown if not.
• -a adds num to value.
• -d divides value by num.
• -m multiplies value by num.
• -s subtracts num from value.
• -e squares value. (Note: no num is needed.)
• Output should have exactly 2 decimal places no matter what the
starting values are.
• If –e is included, it is executed first.
• Use standard order of operations for all operations.
Code should be nicely indented and commented. Create a simple
Makefile to compile your program into an executable called
minicalc.The Makefile should be called Makefile with no extension.
I should be able to type make at the command line to compile your
program.
In: Computer Science
Working with Files in C++.
Create the following program called payroll.cpp. Note that the file you read must be created before you run this program. The output file will be created automatically by the program. You can save the input file in the same directory as your payroll.cpp file by using Add New Item, Text File.
// File: Payroll.cpp
// Purpose: Read data from a file and write out a payroll
// Programmer: (your name and section)
#include <cstdlib> // for the definition of EXIT_FAILURE
#include <fstream> // required for external file streams
#include <iostream> // required for cin cout
using namespace std;
int main ()
{
ifstream ins; // associates ins as an input stream
ofstream outs; // associates outs as an output stream
int id; // id for employee
double hours, rate; // hours and rate worked
double pay; // pay calculated
double total_pay; // grand total of pay
// Open input and output file, exit on any error
ins.open ("em_in.txt"); // ins connects to file "em_in.txt"
if (ins.fail ())
{
cout << "*** ERROR: Cannot open input file. " << endl;
getchar(); // hold the screen
return EXIT_FAILURE;
} // end if
outs.open ("em_out.txt"); // outs connects to file "em_out.txt"
if (outs.fail ())
{
cout << "*** ERROR: Cannot open output file." << endl;
getchar();
return EXIT_FAILURE;
} // end if
// Set total_pay to 0
total_pay = 0;
ins >> id; // get first id from file
// Do the payroll while the id number is not the sentinel value
while (id != 0)
{
ins >> hours >> rate;
pay = hours * rate;
total_pay += pay;
outs << "For employee " << id << endl;
outs << "The pay is " << pay << " for " << hours
<< " hours worked at " << rate << " rate of pay" << endl << endl;
ins >> id;
} // end while
// Display a message on the screen
cout << "Employee processing finished" << endl;
cout << "Grand total paid out is " << total_pay << endl;
ins.close(); // close input file stream
outs.close(); // close output file stream
return 0;
}
Create the input file:
Inside C++ go to File Add New Item and then Text to create a text file.
Type in the data below
In the same directory as your .cpp file for Payroll.cpp click Files and Save As em_in.txt
1234
35 10.5
3456
40 20.5
0
solution should show :
-the output file
-the input file
-the screen output
-the source program
In: Computer Science
For this problem, complete the function stub to simulate the following random variable: Suppose we have a (possibly) unfair coin where the probability of Head is ? and we flip this coin ? times. Let X = "the number of heads showing."
Demonstrate your solution by generating 105 random variates for the parameters shown and displaying them using show_distribution(...).
STARTER CODE:
# First, create a function which simulates the coin, where
# you return 1 with probability p and 0 with probability 1-p.
N = 10
p = 0.25
num_trials = 10**5
def coinFlip(p):
return 0 # Just to get it to compile
def coinFlips(N,p):
return 0 # Just to get it to compile
print("Demonstration:")
seed(0)
In: Computer Science
-----xxxxx-------Could you please use java language. thank you. :::::: XXXX:::::::::::
Implement a recursive reverse sorting algorithm. The following requirements should meet:
a The program shall graphically prompt the user for a file.
bThe program shall read the selected file which will contain 1 integer per line.
c. The program shall sort the values it reads from the file from largest to smallest.
d.The program shall write the values to an output file from largest to smallest in the same directory as the input file.
eThe program shall write 1 integer per line in the output file.
f.The program shall use a recursive algorithm to sort the values
This assignment should be based on:
i) Functionality - Does the program meet the requirements?
ii) Style - Do you have comments and well-written code?
iii) Design - Were good design principles used in the construction of the program?
iv) Additional Elements - Error handling, unit tests, input checking, etc.
In: Computer Science
Requirements: You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following:
Data:
Constructors:
throw new IllegalArgumentException(<”your meaningful String here”>);
If it is OK, the it should initialize the data (of the new instance being created) to be the same as the Point that was received.
Methods:
public class Point implements PointInterface
When your Point.java compiles, Java will expect all methods in the interface to be implemented and will give a compiler error if they are missing. The compiler error will read “class Point is not abstract and does not implement method ”.
You can actually copy the PointInterface methods definitions into your Point class so it will have the comments and the method headers. If you do this, be sure to take out the ; in the method headers or you will get a “missing method body” syntax error when compiling…
public interface PointInterface
{
// toString
// returns a String representing this instance in the form (x,y)
(WITHOUT a space after the ,)
public String toString();
// distanceTo
// throws a new IllegalArgumentException(
if null is received
// returns the distance from this Point to the Point that was
received
// NOTE: there is a static method in the Math class called hypot
can be useful for this method
public double distanceTo(Point otherPoint);
//equals - returns true if it is equal to what is received (as an Object)
public boolean equals(Object obj);
// inQuadrant
// returns true if this Point is in the quadrant specified
// throws a new IllegalArgumentException if the quadrant is
out of range (not 1-4)
public boolean inQuadrant(int quadrant);
// translate
// changes this Point's x and y value by the what is received (thus
"translating" it)
// returns nothing
public void translate(int xMove, int yMove);
// onXAxis
// returns true if this Point is on the x-axis
public boolean onXAxis();
// onYAxis
// returns true if this Point is to the on the y-axis
public boolean onYAxis();
//=============================================
// The method definitions below are commented out and
// do NOT have to be implemented
// //===========================================
// halfwayTo
// throws a new IllegalArgumentException(
if null is received
// returns a new Point which is halfway to the Point that is
received
//public Point halfwayTo(Point another);
// slopeTo
// throws a new IllegalArgumentException(
if null is received
// returns the slope between this Point and the one that is
received.
// since the slope is (changeInY/changeInX), then first check to see if
changeInX is 0
// if so, then return Double.POSITIVE_INFINITY; (since the
denominator is 0)
//public double slopeTo(Point anotherPoint)
}
In: Computer Science
Q1: Constraint:
Use concept of dynamic allocation for implementation
Statement:
In a class there are N students. All of them have appeared for the
test. The teacher evaluated
the test and noted marks according to their roll numbers. Marks of
each students has to be incremented
by 5. Print list of marks of students before and after
increment.
In: Computer Science
Design a finite state machine that accepts binary strings divisible by 5. Input is fed to the FSM one bit at a time, from the most significant bit to the least significant bit (left to right). For example, 1010 should be accepted, but 1100 should be rejected. Clearly explain how you designed your state transitions. Showing the FSM alone is worth minimal credit!
In: Computer Science
In: Computer Science
In: Computer Science
Implement function (in C programming) that calculates and returns the total size of items in a directory given by name.
int dir_size(const char *name);
In: Computer Science
li $t1, 10 # [$t1] <- 10
finish the following calculation using MIPS assembly code.
$t2 = $t1 + $t1
$t3 = $t1 << 2 (shift to left by 2 bits)
$t4 = $t1 & 0x0000ffff (bitwise AND)
$t5 = $t1 | 0x0000fffff (bitwise OR)
$t6 = $t2 + $t3 + $t4 + $t5
Write MIPS assembly code to finish the above calculation and print out the result, value of $t6.
In: Computer Science
BankAccount:
You will create 3 files: The .h (specification file), .cpp
(implementation file) and main file. You will practice writing
class constants, using data files. You will add methods public and
private to your BankAccount class, as well as helper methods in
your main class. You will create an array of objects and practice
passing objects to and return objects from functions. String
functions practice has also been included.
BankAccount |
-string accountName // First and Last name of Account holder -int accountId // secret social security number -int accountNumber // integer -double accountBalance // current balance amount |
+ BankAccount() //default constructor that sets name to “”, account number to 0 and balance to 0 +BankAccount(string accountName,int id, int accountNumber, double accountBalance) // regular constructor +getAccountBalance(): double // returns the balance +getAccountName: string // returns name +getAccountNumber: int +setAccountBalance(double amount) : void +equals(BankAccount other) : BankAccount // returns BankAccount object ** -getId():int ** +withdraw(double amount) : bool //deducts from balance and returns true if resulting balance is less than minimum balance +deposit(double amount): void //adds amount to balance. If amount is greater than rewards amount, calls // addReward method -addReward(double amount) void // adds rewards rate * amount to balance +toString(): String // return the account information as a string with three lines. “Account Name: “ name “Account Number:” number “Account Balance:” balance |
The order in the file is first name, last name, id, account number, balance. Note that account name consists of both first and last name
In: Computer Science
MATLAB
Write a code that takes the initial velocity and angle as an input and outputs the maximum height of the projectile and its air time.
Follow the pseudo code below. This will not be provided in as much detail in the future so you’ll have to provide pseudocode or a flowchart to showcase your logic. For this first assignment though, the logic is laid out below with some indented more detailed instructions.
PROGRAM Trajectory:
Establish the User Interface (Typically referred to as the UI);
INPUT INPUT
Solve Solve Print
Start with an explanation of activity
Ask the user for the initial velocity;
Ask the user for the initial angle;
Include descriptive requests for inputs so the user knows what information is required.
for the maximum height the ball reaches;
for the length of time the ball is in the air;
the answers for the user;
Include a description with that return so the user understands what the data is
Plot height versus time; Plot height versus distance;
Do not overwrite your previous figure! This is a new plot but you still want the old one.
Make it clear what the plots are. Label the plot axes with units, include a title, and use a marker for the plot points.
END
In: Computer Science