In: Computer Science
Using C++ : What am I doing wrong!?!?
Problem Instructions: Implement a program that repeatedly outputs an I of a size entered by the user. Prompt the user for a size. If -1 is entered, quit the program. If an even number or a number smaller than 3 is entered, prompt the user again. Then output a shape of # characters that represent an I. Repeat the program until -1 is entered.
What I have so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num;
cout << endl;
cout << " Please enter an ODD number greater than 2: " << endl;
cin >> num;
if (num!= -1)
{
while (num >= 3 && num % 2 == 1)
{
do //Runs if num is invalid
{
if (num %2 == 0)
{
//header
for (int i = 1; i <= num; i++)
{
cout << "#";
}
//middle
for (int i = 1; i <= num; i++)
{
cout << endl;
for (int i = 1; i <= num / 2; i++)
{
cout << " ";
}
cout << "#";
}
cout << endl;
//footer
for (int i = 1; i <= num; i++)
{
cout << "#";
}
}
} while (num >= 3 && num % 2 == 1);
}
}
return 0;
}
In: Computer Science
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator.
Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %.
Output Requirements: Make your output easy to understand, both in the prompts and when printing the result.
Input Validation. The program should validate all input from the user and print an error message if the input is not valid. The integer values must be between -30,000 and + 30,000 and the operators must be one of these: + - * / %. If the input is not valid, the program should exit without printing a result.
In: Computer Science
Write a program that asks the user for a number of seconds and
tells them how
many hours, minutes and seconds it is. Make sure your program works
correctly
for values smaller than the whole hour or whole minute. Here’s what
the sample
output from several runs of your program would look like:
Please enter the number of seconds: 2
2 seconds
>>>
Please enter the number of seconds: 500
8 minutes 20 seconds
>>>
Please enter the number of seconds: 20000
5 hours 33 minutes 20 seconds
Hint: you may find mod and div operations helpful here. You will
need to use
branching statements (ifs) in this program.
use python
In: Computer Science
In: Computer Science
Show step-by-step how Java will evaluate the following expression:
8 % 3 + 3 % 2 – 9 % 2.0 * 5
15/15 % 7 *2 – 11. /4 * 5
In: Computer Science
Internet Service provider Part 1 (Java Program)
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.
Write a program that calculates a customer’s monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total charges.
Part 2
Modify the program you wrote for Part 1 so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, the amount of money Package B customers would save if they purchased Package A or Package C, and the amount of money Package C customers would save if they purchased Package A or Package B . If there would be no savings, no message should be printed.
In: Computer Science
Write a MIPS Assembly Language program to perform the following operations:
Request and read two integers from the console (Dn and Up),
Call a recursive function to compute the result
int RecurseFunc( int Dn, int Up )
{
if( Dn < 1 ) return 0;
else return Dn * Up + RecurseFunc( Dn - 1, Up + 1 );
}
Print out the results
Submit your code and report here.
In: Computer Science
The following is a structure template:
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
a. Write a function that has a reference to a box structure as its formal argument
and displays the value of each member.
b. Write a function that has a reference to a box structure as its formal argument
and sets the volume member to the product of the other three dimensions.
In: Computer Science
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).
In: Computer Science
JAVA
the task is to implement the missing methods in the LinkedIntSet class. Each method you must write has comments describing how it should behave. You may not add any new fields to the LinkedIntSet class and you may only add new code inside the bodies of the 5 methods you are asked to write. You may also write new private helper methods. However, you may not change any method headers, you may not change any code outside of the 5 methods, and you may not add any new data fields to the class.
public class LinkedIntSet {
private static class Node {
private int data;
private Node next;
public Node(int data, Node next)
{
this.data =
data;
this.next =
next;
}
}
private Node first;
public LinkedIntSet() {
first = null;
}
public int size() {
int counter = 0;
for (Node current = first; current
!= null; current = current.next)
counter++;
return counter;
}
public boolean contains(int i) {
for (Node current = first; current
!= null; current = current.next) {
if (current.data
== i)
return true;
}
return false;
}
// Ignore this equals method. Write the code for
the other equals method.
public boolean equals(Object otherObject) {
LinkedIntSet other = (LinkedIntSet)
otherObject;
return this.equals(other);
}
/***************************** NEW METHODS ************************************/
/**
* Adds <code>element</code> to this set if
it is not already present and
* returns <code>true</code>. If
<code>element</code> is already present, the
* set is unchanged and <code>false</code>
is returned.
*
* @param element the element to be added
* @return <code>true</code> if the element
was added and <code>false</code>
* otherwise.
*/
public boolean addElement(int element) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Removes an element from the set.
*
* @param element the element to be removed
* @return <code>ture</code> if the element
was removed and <code>false</code>
* otherwise.
*/
public boolean removeElement(int element) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Changes the set so that it is equal the union of
itself and
* <code>other</code>.
*
* @param other the set to union with
*/
public void union(LinkedIntSet other) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
/**
* Changes the set so that is equal the intersection of
itself and
* <code>other</code>.
*
* @param other the set to intersect with
*/
public void intersect(LinkedIntSet other) {
// Replace the line below with your
answer
throw new RuntimeException("Not
implemented");
}
}
In: Computer Science
Dynamic Programming (DP) is an algorithmic technique for solving an optimization problem by breaking it down into simpler subproblems and utilizing the fact that the optimal solution to the overall problem depends upon the optimal solution to its subproblems. When the technique is applicable, this condition can be extended incrementally without having to alter previously computed optimal solutions to subproblems. Eventually the condition applies to all of the data and, if the formulation is correct, this together with the fact that nothing remains untreated gives the desired answer to the complete problem.
What would be 4 examples that describe Dynamic Programming?
In: Computer Science
In: Computer Science
Write a program to print random numbers and whether they were
even or odd. Ask the user to enter a positive number to indicate
how many random numbers to pull (verify number is positive). Zero
is positive.
Declare two variables and initialized to zero.
int evens = 0, odds = 0;
Use them to count how many evens and how many odds were
pulled.
Enter how many random numbers to pull : 3
41
odd
18467 odd
6334 even
1 even and 2 odd random numbers were generated.
In: Computer Science