I need my code output values edited to be formatted to two decimal places (i believe using setprecision), i will need you to edit my code toformat each menu option to 2 decimal places: provided is my code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double radius;
double base;
double height;
double length;
double width;
double Area;
const double PI = 3.14159;
int choice;
// display menu
cout << "Geometry Calculator" << endl
<< endl;
cout << " 1. Calculate the Area of a Circle"
<< endl;
cout << " 2. Calculate the Area of a Rectangle"
<< endl;
cout << " 3. Calculate the Area of a Triangle"
<< endl;
cout << " 4. Quit" << endl <<
endl;
cout << "Enter your choice (1-4):" <<
endl;
cin >> choice;
//validate and process the menu
switch(choice)
{
case 1:
cout <<
"\n";
cout <<
"Enter the radius of the circle: ";
cin >>
radius;
if (radius
> 0)
{
Area = PI * radius * radius;
cout << "\n";
cout << "Area of Circle is: " <<
Area << setprecision(2) << endl;
}
else
{
cout << "The radius can not be less than
zero. Only enter positive values for your radius.";
}
break;
case 2:
cout <<
"\n";
cout <<
"Enter the length of the rectangle: ";
cin >>
length;
cout <<
"Enter the width of the rectangle: ";
cin >>
width;
if (length
> 0 && width > 0)
{
Area = length * width;
cout << "\n";
cout << "Area of Rectangle is: " <<
Area << endl;
}
else
{
cout << "\nOnly enter positive values for
length and width.";
}
break;
case 3:
cout <<
"\n";
cout <<
"Enter the base of the Triangle: ";
cin >>
base;
cout <<
"Enter the height of the Triangle: ";
cin >>
height;
if (base >
0 && height > 0)
{
Area = 0.5 * base * height;
cout << "\n";
cout << "Area of the Triangle is: "
<< Area << endl;
}
else
{
cout << "\nOnly enter positive values for
base and height.";
}
break;
case 4:
cout <<
"Exiting Geometry Calculator\nGoodbye!\n";
break;
default: cout << "Sorry,
that was an invalid entry!\nPlease re-run the program and "
<< "enter
a valid menu choice.\n";
}
return 0;
}
In: Computer Science
(a) Provide a detailed explanation of the (signed) integer overflow. (b) Write C++ program that displays the table of function 2n . This is an integer value that you must compute using multiplication, and the use of power function pow(2.,n ) is not permitted. Display lines that contain n and 2n for n=0,1,2,3,… and show all lines that contain correct values. Stop displaying before the occurrence of the integer overflow. Your program must work on any computer and for any size of integers; so, do not try to assume some specific word size. You have to detect the overflow and prevent that it creates wrong results.
In: Computer Science
I am running this code using C to count the words in char array, but somehow it keeps counting the total characters + 1.
Any solution to fix this problem?
#include <stdio.h>
int main()
{
char input[1001];
int count =0;
fgets(input, 1001, stdin);
char *array = input;
while(*array != '\0')
{
if(*array == ' '){
array++;
}
else{
count++;
array++;
}
}
printf("this character's length is %d.", count);
printf("this characterarray : %s", input);
return 0;
}
In: Computer Science
Active directory (AD) is arguably the most critical component of Windows Server 2008, certainly for larger organizations. It enables corporations to manage and secure their resources from a single directory service and with a common interface—a very powerful tool. Because it is so powerful and offers so many features and capabilities, it sometimes can be complex to those looking at it for the first time. This week, we are going to learn about AD in detail, starting with the fundamentals. As we progress during the week, you will begin to see it's not that intimidating after all. First, though, let's get the fundamentals down. What exactly is a directory service, and what are some examples in industry? Next, let's get the definition of active directory down—what exactly is it, and what benefits does it provide? After this, we'll look at the details on how it is implemented in the business environment.
What is a directory service?
What are some examples of a directory service?
What is the definition of AD?
What are the benefits of AD?
How is AD implemented in a business environment?
In: Computer Science
Overview: You will write a program that reads up to 100 numbers
from a file. As you read the
numbers, insert them into an array in ascending order.
Specifics:
1A. Write a function called insertIntoSortedArray .
i. It should take three arguments -
a. myArray[ ] : sorted array that should be able to hold at most
100 integers.
b. numEntries : the number of elements inserted so far.
c. newValue : the incoming value to be inserted into the sorted
array (i.e.
myArray[]).
ii. The insertIntoSortedArray function should return a count of the
elements inserted so
far (i.e. the current size of the array)
This function is defined as follows:
int insertIntoSortedArray ( int myArray[], int numEntries, int
newValue);
In: Computer Science
write me a java progrm that does this:
y=x^3 +1
drivative of y=3X^2+0
y=mx+b
m is slope for x=2 put 2 back to equation y=3(2)^2=12
now we have 12 and y=9 so
9=2(12)+b and we find b=-15
now we write new equation that with these information
y=12x-15 we solve for 12x-15=0, we solve for x and x=15/12=1.25
now we do the same thing above we put at the drivative equation y=3(1.25)^2+0=4.6875
now we put this to 2.943125=(4.6875)*3+b
we solve for b=-2.90625
y=4.6875x-2.90625 and 4.6875x-2.90625=0 we solve for x and =0.62 now we use this as we did above to find another new equation and this go in a loop to do the same thing over and over to find new point and equation
In: Computer Science
using java
For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to choose a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or no answer. For example: Is your number evenly divisible by 3? (Yes or No).The user will enter “Yes” or “No” to each question. When the program is sure it knows the user’s number it outputs the number. For example, Your number is 9.
Your program must always guess the user’s number in less than five questions.
In: Computer Science
Briefly explain what are the chief differences between queues, dequeues and priority queue? How can you determine when it is appropriate to use a queue, a dequeue, or a priority queue? Write a simple example program using any of the 3.
In: Computer Science
Add comments to the following code:
PeopleQueue.java
import java.util.*;
public class PeopleQueue {
public static void main(String[] args)
{
PriorityQueue<Person> peopleQueue = new
PriorityQueue<>();
Scanner s = new
Scanner(System.in);
String
firstNameIn;
String lastNameIn;
int ageIn = 0;
int count = 1;
boolean done =
false;
System.out.println("Enter the first name, last name and age of 5
people.");
while(peopleQueue.size()
< 5) {
System.out.println("Enter a person");
System.out.print("First Name: ");
firstNameIn = s.nextLine();
System.out.print("Last Name: ");
lastNameIn = s.nextLine();
System.out.print("Age: ");
while(!done) {
try {
ageIn = Integer.parseInt(s.nextLine());
done = true;
} catch (NumberFormatException e) {
System.out.println("Error: Please enter a number for age");
System.out.print("Age: ");
}
}
Person person = new Person(firstNameIn, lastNameIn, ageIn);
peopleQueue.add(person);
System.out.println("Added to queue: " + firstNameIn + " " +
lastNameIn + ", Age: " + ageIn + "\n");
done = false;
}
NameCompare
nameCompare = new NameCompare();
List<Person>
people = new ArrayList(peopleQueue);
Collections.sort(people,
nameCompare);
System.out.println("Sorted by Last Name\n");
for (int i = 0; i <
people.size(); i++) {
System.out.println("Name: " + people.get(i).getFirstName() + "
"
+ people.get(i).getLastName() + ", Age: "
+ people.get(i).getAge());
}
System.out.println("\nSorted by Age and removed from
queue\n");
while
(!peopleQueue.isEmpty()) {
System.out.println("Removed Person " + count + " -" +
peopleQueue.remove());
count++;
}
}
}
Person.java
public class Person implements Comparable<Person> {
private int age;
private String firstName;
private String lastName;
public Person(String first, String last, int
theirAge) {
this.firstName =
first;
this.lastName =
last;
this.age =
theirAge;
}
public String getFirstName() {
return
this.firstName;
}
public String getLastName() {
return
this.lastName;
}
public void setLastName(String last) {
this.lastName =
last;
}
public int getAge() {
return this.age;
}
@Override
public int compareTo(Person person) {
if(this.equals(person))
return 0;
else if(getAge() <
person.getAge())
return 1;
else
return -1;
}
public String toString() {
return " Name: " +
getFirstName() + " " + getLastName() + ", Age: " + getAge();
}
}
NameCompare.java
import java.util.Comparator;
public class NameCompare implements Comparator<Person> {
public int compare(Person p1, Person p2)
{
int i =
p1.getLastName().compareTo(p2.getLastName());
if(i != 0) return
-i;
return i;
}
}
In: Computer Science
In: Computer Science
Computer/Network Security
How do you implement write access through web server?
In: Computer Science
Based on what you have learned on the WAN technologies, there are three different types of environments that need your help. The three types of environments include a small business, a medium corporate, and a large enterprise environment. What type of technology would you recommend for these different types of companies? Justify your answer.
What network optimization tools, methods, or techniques do you think will be most important to you as you manage your organization's network? Explain why?
In: Computer Science
PRELAB - Week of September 16
You’ve created a general-purpose function for allocating an array with elements of any data type:
array = createArray(numElems, elemSize);
and which supports the following function for obtaining its number of elements:
size = getArraySize(array);
and that’s all you’ll need for this pre-lab. All you’re asked to do for next week is to be able to:
1. Open a file
2. Read an integer giving the number of employee records in the file
3. Allocate an array of employee records (structs) to hold the records in the file
4. Read the records into the allocated array where an employee record is declared as:
typedef struct {
intempID, ssn, position;
float salary;}
Record;
To get comfortable with structs you’ll probably want to loop through the array and print the four members of each record–but you’d probably do that anyway just to verify that you get the results you expect from your test file!
In: Computer Science
Java assignment, abstract class, inheritance, and polymorphism.
these are the following following classes:
Animal (abstract)
o Example output: Tom says meow.
Mouse
o Example output: Jerry is chewing on cheese.
Cat
o Example output: Tom is chasing Jerry.
TomAndJerry
Sample run:
Jerry says squeak.
Tom says meow.
Jerry is chewing on cheese.
Tom is chasing Jerry.
In: Computer Science
What chmod command would you use to impose the following
permissions?
1. on a directory(called dir1) and all its subdirectories such
that: the owner would have read, write, and execute; the group
would have read and execute; and others would have read(write the
command in two ways: using rwx and using numeric value)
2. on file (called file1)such that: the owner would have read and
write; the group would have no permissions; and others would have
write
(write the command in two ways: using rwx and using numeric value)
3. set the special permission SGID and sticky bit for dir1.(you don't need to change the defined permission in 1)
Starting from the Linux default permissions for file and
directories, what umask command would you use to ensure that for
all new:
4. directories, the owner would have read, write, and execute;
members of the group would have read and execute; and others would
have read
5. files, the owner would have read and execute; the group would
have read, write, and execute; and others would have execute
In: Computer Science