Questions
SOLVE USING WHILE. A perfect number is a positive integer that is equal to the sum...

SOLVE USING WHILE. A perfect number is a positive integer that is equal to the sum of its positive divisors except the number itself. The first two perfect numbers are 6 and 28 since 1+2+3=6 and 1+2+ 4+7+14=28. Write a matlab computer program that finds the first n perfect number (the user must input the value of n) and show them in a vector

thanks! xo

In: Computer Science

using C program Assignment Write a computer program that converts a time provided in hours, minutes,...

using C program

Assignment

Write a computer program that converts a time provided in hours, minutes, and seconds to seconds

Functional requirements

  1. Input MUST be specified in hours, minutes, and seconds
  2. MUST produce the same output as listed below in the sample run
  3. MUST correctly compute times

Nonfunctional requirements

  1. MUST adhere to program template include below
  2. MUST compile without warnings and errors
  3. MUST follow the code template provided in this assignment
  4. MUST NOT change " int main() " function
  5. MUST only edit sections marked by " // complete this "

Sample run

4 hours, 13 minutes and 20 seconds is equal to 15200 seconds.
8 hours, 0 minutes and 0 seconds is equal to 28800 seconds.
1 hours, 30 minutes and 0 seconds is equal to 5400 seconds.

Grading

This assignment will be graded according to the programming grading rubric.

Due date

The assignment is due by the 11:59pm on September 20, 2019.

Requested files

time_to_sec.c

/*

* time_to_sec.c

*

* Created on: Jul 20, 2016

* Author: leune

*/

// appropriate #include statements

/* Convert a time interval specified in hours, minutes and seconds to

* seconds.

* Parameters:

* hours, minutes, seconds: input time elements

* Preconditions:

* 0 <= minutes < 60

* 0 <= seconds < 60

* Return:

* number of seconds in the interval

*/

unsigned int time_to_sec(unsigned int hours, unsigned int minutes,

unsigned int seconds) {

// complete this

}

/* Print a formatted representation of the calculation

* Parameters:

* hours, minutes, seconds: input time elements

* Postcondition:

* Function will write the calculation to standard output.

*/

void format_seconds(unsigned int hours, unsigned int minutes,

unsigned int seconds) {

// complete this

}

int main(void) {

format_seconds(4, 13, 20);

format_seconds(8, 0, 0);

format_seconds(1, 30, 0);

}

In: Computer Science

In Linux Can you reboot the system as a normal user? Explain your answer. Draw on...

In Linux

  • Can you reboot the system as a normal user? Explain your answer. Draw on the concepts discussed in this course to justify your answer.
  • How do you change the system run level? Changing the system run level means switching from your default run level to run level 1 and vice versa.

Your response to each should meet the following criteria:

  • It should be a minimum of 1 paragraph (five single-spaced sentences).
  • If you are using outside sources, you need to acknowledge your sources with APA citations.

please type your answer, I will rate you well.

In: Computer Science

in java Create a class City with x and y as the class variables. The constructor...

in java Create a class City with x and y as the class variables. The constructor with argument will get x and y and will initialize the city. Add a member function getDistanceFrom() to the class that gets a city as the input and finds the distance between the two cities.

In: Computer Science

1_ What is the output? private void btnMethods_Click(object sender, EventArgs e) { int arg1 = 2;...

1_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 2;

double val = ValReturnMethod(arg1, 2.00);

MessageBox.Show(val.ToString());

}

private void ValReturnMethod(int val, double val2)

{

return val1 * val2 *25.50;

}

_____________________________

2_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 4;

double val = ValReturnMethod(ref arg1);

MessageBox.Show(arg1.ToString());

}

private double ValReturnMethod(ref int val1)

{

return val1 *25.50;

}

______________________________

3_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 4;

double arg2 = 10.50;

MessageBox.Show(ValReturnMethod(arg1,arg2).ToString());

}

private double ValReturnMthod (int val1,double val2)

{

return val1 * 25.50;

}

In: Computer Science

What is the signed decimal equivalent of the following signed-magnitude binary value? 11101010.1001 What is the...

What is the signed decimal equivalent of the following signed-magnitude binary value?

11101010.1001

What is the binary equivalent (in two's complement binary representation) of the following signed decimal value? Represent the integer part of the binary value in 8 bits.

-58.1875

In: Computer Science

For each of the following situations provide the type of variable(s) that you would use to...

For each of the following situations provide the type of variable(s) that you would use to model it and give a kind of probability distribution that would be appropriate for modeling that variable.

  1. Age of students in the class
  2. Choice of color marker
  3. Whether you ride a bus given how much cash you have in your pocket.
  4. Number of ice creams I have eaten, up to 3 ice creams maximum.
  5. Cost of a crop based on the harvest size.
  6. Cities in the US
  7. Distance of a city in the US to Columbus
  8. Height of students in class based on gender

In: Computer Science

C++ Text message decoder Use getline() to get a line of user input into a string:...

C++

Text message decoder

Use getline() to get a line of user input into a string:

Enter text:  
IDK if I'll go. It's my BFF's birthday. 

Search the string using find() for common abbreviations and replace() them with their long form. In addition, use a for loop to iterate through each character of the string and replace any occurences of '.' with '!':

Enter text:
IDK if I'll go.  It's my BFF's birthday. 

I don't know if I'll go!  It's my best friend forever's birthday!

Use loops for each abbreviation to replace multiple occurrences:

Enter text:
Hi BFF.  IDK where I'm going but it's not going to be with you!  JK you know you're my BFF.  IDK why I just said that.  Anyway, TMI.  Why do I always give people TMI?  IDK.  Alright TTYL bye BFF!

Hi best friend forever!  I don't know where I'm going but it's not going to be with you!  just kidding you know you're my best friend forever!  I don't know why I just said that!  Anyway, too much information!  Why do I always give people too much information!  I don't know!  Alright talk to you later bye best friend forever!

Support these abbreviations:

  • BFF -- best friend forever
  • IDK -- I don't know
  • JK -- just kidding
  • TMI -- too much information
  • TTYL -- talk to you later

Use the predefined constants for each abbreviation BFF, IDK, etc. and each long form BFF_LONG, IDK_LONG, etc. rather than hardcoding strings inside the loop.

In: Computer Science

What is the unsigned hexadecimal equivalent of the following unsigned octal value? Do NOT include in...

What is the unsigned hexadecimal equivalent of the following unsigned octal value?

Do NOT include in your answer ANY insignificant zeros.

107655.643

What is the binary equivalent (in signed-magnitude binary representation) of the following signed decimal value? Represent the integer part of the binary value in 8 bits.

-116.6875

In: Computer Science

JAVA Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same forward...

JAVA Palindrome Detector

A palindrome is any word, phrase, or sentence that reads the same forward or backward. Here are some well-known palindromes:

Able was I, ere I saw Elba

A man, a plan, a canal, Panama

Desserts, I stressed

Kayak

Write a boolean method that users recursion to determine where a String argument is a palindrome. The method should return true if the argument reads the same forward and backward. Demonstrate the method in a program.

Include the following modifications:

  • Use JOptionPanes for all user I/O.
  • Allow the user to input test strings until they type "quit" to exit.

In: Computer Science

Using either your own C-string functions of Lab 7.1 or the ones from the standrd C++...

Using either your own C-string functions of Lab 7.1 or the ones from the standrd C++ cstring library, create a String class, which — while having minimal functionality — illustrates the use of and need for the canonical form.

Overview

Here is the .h file for the class (note the class name — String with a capital S; trying to force the use of the classname string was to much of an issue:

class String {
        friend std::ostream &operator <<(std::ostream &os, const String &s);
        
        friend String operator +(const String &s1, const String &s2);
public:
        String(const char *cs="");
        String(const String &s);
        ~String();
        String &operator =(const String &rhs);
        char &operator [](int index);
        String &operator +=(const String &s);
        
        int length() const;
        
private:
        char *cs;
};

I've also supplied a String_Exception class and an app for testing your class (it will be the test driver once I get it all into Codelab).

Implementation Notes

  • This exercise has potential name clashes with the standard C C-string library, named cstring, but originally named string.h — recall the naing conventions for the C++ wrapper libraries of standard C libraries. To avoid this, the files have been name mystring, e.g. mystring_app.cpp, mystring.h, etc. The only one that really affects you is the latter since you must #include it in your implementation file (mystring.cpp).
  • The String)const char *cs="") constructor allows one to create a String from C-string (and "..." literals, which are of type const char * – i.e., C-strings).
  • Operations on the cs buffer are performed using the C-string functions you wrote in lab 4.2.
    • Memory allocation involves making sure the cs data member (i.e., the pointer to the C-string buffer) is pointing to a sufficiently sized buffer.
      • For this implementation, we will use exact-sized buffer; i.e., enough elements in the char array to hold the characters of the C-string + the null terminator
      • This is relevant for the two constructors, the assignment operator and the += and + operators.
        • Using the String(const char *) constructor as an example:
          • when this constructor is called, the length of the argument is obtained using strlen and a buffer of the corresponding size is allocated (this can be done within the member initialization list)
          • the contents of the argument C-string is then copied to this new buffer using strcpy (this needs to be done in the body of the constructor; there is no way to work it into the member intialization list)
            String::String(const char *cs) : cs(new char[strlen(cs)+1) {    // the +1 is for the null terminator
                                                                            
        • Similar logic applies to the copy constructor, the assignment operator, and the += operator (you should be coding the + operator using the += operator as shown in class): in those three cases the source buffer (i.e., the C-string to be copied, assigned, or concatenated) will be the cs data member of another String object




          mystring.h
          #ifndef MYSTRING_H
          #define MYSTRING_H
          
          #include <iostream>
          
          
          class String {
                  friend std::ostream &operator <<(std::ostream &os, const String &s);
          //      friend bool operator ==(const String &s1, const String &s2);
                  friend String operator +(const String &s1, const String &s2);
          public:
                  String(const char *cs="");
                  String(const String &s);
                  ~String();
                  String &operator =(const String &rhs);
                  char &operator [](int index);
                  String &operator +=(const String &s);
          //      int find(char c) const;
                  int length() const;
          //      void clear();
          private:
                  char *cs;
          };
          
          #endif

mystring_app.cpp

#include <iostream>
#include <sys/sysinfo.h>
#include <cstdlib>

#include "mystring.h"

using namespace std;

int main() {
        String s = "Hello";

        cout << "s: " << s << " (" << s.length() << ")" << endl;

        cout << "s + \" world\": " << s + " world" << endl;

        cout << "s[1]: " << s[1] << endl;

        String s1 = s;          // making sure copy constructor makes deep copy
        String s2;
        s2 = s;                 // making sure assignment operator makes deep copy
        s[0] = 'j';
        cout << endl;
        cout << "s: " << s << " (" << s.length() << ")" << endl;
        cout << "s1: " << s1 << " (" << s1.length() << ")" << endl;
        cout << "s2: " << s2 << " (" << s2.length() << ")" << endl;
        cout << endl;

        for (int i = 0; i < 5; i++) {
                s += s;
                cout << "s: " << s << " (" << s.length() << ")" << endl;
        }
        cout << endl;

        for (int i = 0; i < 5; i++) 
                s += s;
        cout << "s: " << s << " (" << s.length() << ")" << endl;

        return 0;
}



mystring_exception.cpp
#ifndef MYSTRING_EXCEPTION
#define MYSTRING_EXCEPTION

#include <string>         // Note this is the C++ string class!

class String_Exception {
public:
    String_Exception(std::string what) : what(what) {}
        std::string getWhat() {return what;}
private:
    std::string what;
};

#endif

In: Computer Science

Effect on pipelining We consider the transmission of a message between 2 host A and B...

Effect on pipelining

We consider the transmission of a message between 2 host A and B via a router. We dispose of the following information :

- the distance between each host and the router is 1500m.

- the speed of propagation = 360.000 km/s(speed of light)

- the size of each message = 1500 octets.

- the speed of the link between host and router = 1Mb/s

- the delay of treatment of a message in the router = 10ms

1) What is is the total delay to send a message from A to B ?

2) If we use the Stop and Wait protocol to send a message from A to B and the message size ACK = 64 octets, what is the utilization rate ?

3) If we use the Go-back-N protocol, with a time frame of size N, what is the value of N that maximize the flow control?

In: Computer Science

Language:C++ Program:Visual basic I have errors on line 102 "expression must have a constant value line...

Language:C++

Program:Visual basic

I have errors on line 102 "expression must have a constant value

line 107,108,123,124,127,128: array type int[n] not assignable

#include<iostream>
#include <fstream>
using namespace std;
#define size 10000

// Displays the current Inventory Data
void Display(int box_nums[],int nboxes[],double ppBox[],int n) // Prints Box number , number of boxes and price per box.
{
cout<<"Box number Number of boxes in stock Price per box"<<"\n";
cout<<"-------------------------------------------------------------\n";
for(int i=0; i<n; i++)
{
cout<<box_nums[i]<<" "<<nboxes[i]<<" "<<ppBox[i]<<"\n";
}
}

// sort's the inventory data according to the price per box from low to high
void sortByPrice(int box_nums[],int nboxes[],double priceBox[],int n)
{
int i, j, min_idx , temp2;
double temp;
for (i = 0; i < n-1; i++)
{
min_idx = i; // min_idx is used to store data in ascending order
for (j = i+1; j < n; j++) // used selection sort to sort the data based on price per box
{
if (priceBox[j] < priceBox[min_idx])
min_idx = j;
}
temp = priceBox[min_idx];
priceBox[min_idx] = priceBox[i]; // temp is a variable to swap data
priceBox[i] = temp;

temp2 = nboxes[min_idx];
nboxes[min_idx] = nboxes[i]; // temp2 is a variable to swap data
nboxes[i] = temp2;

temp2 = box_nums[min_idx];
box_nums[min_idx] = box_nums[i];
box_nums[i] = temp2;
  
}   
}

// sort's the inventory data according to Box number from low to high
void sortByBoxNumber(int box_nums[],int nboxes[],double priceBox[],int n)
{
int i, j, min_idx , temp2;
double temp;
for (i = 0; i < n-1; i++)
{
min_idx = i; // min_idx is used to store data in ascending order
for (j = i+1; j < n; j++)
{
if (box_nums[j] < box_nums[min_idx]) // used selection sort to sort the data based on price per box
min_idx = j;
}

temp2 = box_nums[min_idx];
box_nums[min_idx] = box_nums[i];
box_nums[i] = temp2;

temp = priceBox[min_idx];
priceBox[min_idx] = priceBox[i];
priceBox[i] = temp;

temp2 = nboxes[min_idx];
nboxes[min_idx] = nboxes[i];
nboxes[i] = temp2;
}   
}

// Searches for the price per box of the corresponding box number entered by user.
double lookUpByBoxNumber(int boxNumber,int box_nums[],double priceBox[],int n)
{
int low =0, high = n-1;
int mid;
while(low <= high) // used binary search to search for the corresponding box number and its price-per-box
{
mid = low + (high-low)/2;

if(box_nums[mid] > boxNumber)
{
high = mid - 1;
}
else if(box_nums[mid] == boxNumber)
{
return priceBox[mid];
}
else
{
low = mid + 1;
}
  
}
return -1;
}

//Reordered the data whose number of boxes are less than 100
void reorderReport(int box_nums[],int nboxes[],int n)
{
int reorderBoxNums[n],reorderBoxes[n],k=0;
for(int i=0; i<n; i++)
{
if(nboxes[i] < 100)
{
reorderBoxNums[k] = box_nums[i];
reorderBoxes[k] = nboxes[i];
k++;
}
}
int i, j, max_idx , temp2;
for (i = 0; i < k-1; i++) // sorts the data in reordered data according to number of boxes in inventory from low to high
{
max_idx = i;
for (j = i+1; j < k; j++)
{
if (reorderBoxes[j] > reorderBoxes[max_idx])
max_idx = j;
}

temp2 = reorderBoxes[max_idx];
reorderBoxes[max_idx] = reorderBoxes[i];
reorderBoxes[i] = temp2;

temp2 = reorderBoxNums[max_idx];
reorderBoxNums[max_idx] = reorderBoxNums[i];
reorderBoxNums[i] = temp2;
}
cout<<"REORDERED REPORT IS: \n";
cout<<"The boxes in invetory whose stock are less than 100 are: \n";
cout<<"Box number Number of boxes in stock"<<"\n";
cout<<"------------------------------------------"<<"\n";
for(int i=0 ; i<k; i++)
{
cout<<reorderBoxNums[i]<<" "<<reorderBoxes[i]<<"\n";
}
}
int main()
{

std::fstream myfile("inventory.txt");
int box_number[size] , numberOfBoxes[size] ;
double pricePerBox[size],sp;
int bn ,nb,i = 0;
while(myfile >> bn >> nb >> sp) // fetch data from file inventory.txt
{
box_number[i] = bn;
numberOfBoxes[i] = nb;
pricePerBox[i] = sp;
i++;
}

int n = i, bnumber ; // n stores number of records in file , bnumber is the box number which is to be searched for price-per-box by user
double val; // val is variable used for value stored from lookup by box-number
char option;
bool exit = true; // exit variable to exit the while loop

// Menu for the user
cout<<"\nChoose a option in the Menu a/b/c/d/e/f :"<<"\n";
cout<<"a. Display the data"<<"\n";
cout<<"b. Sort data by price, low to high"<<"\n";
cout<<"c. Sort data by box number, low to high"<<"\n";
cout<<"d. Look up the Price of the box given the box number"<<"\n";
cout<<"e. Generate Reorder Report"<<"\n";
cout<<"f. Exit"<<"\n";

while(exit)
{
cout<<"Enter your choice a/b/c/d/e/f : ";
cin>>option;

switch(option)
{
case 'a':
Display(box_number,numberOfBoxes,pricePerBox,n);
break;
case 'b':
sortByPrice(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Data has been Successfully sorted by price"<<"\n";
cout<<"Please, choose option 'a' to display sorted data"<<"\n";
break;
case 'c':
sortByBoxNumber(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Data has been Successfully sorted by Box Number"<<"\n";
cout<<"Please, choose option 'a' to display sorted data"<<"\n";
break;
case 'd':
sortByBoxNumber(box_number,numberOfBoxes,pricePerBox,n);
cout<<"Enter the box number for which you want to search the price : ";
cin>>bnumber;
val = lookUpByBoxNumber(bnumber,box_number,pricePerBox,n);
if(val < 0)
{
cout<<"There is no price of the box for the box number you are searching for\n";
}
else
{
cout<<"The price-per-box of the Box-Number you searched is "<<val<<"\n";
}
break;
case 'e':
reorderReport(box_number,numberOfBoxes,n);
break;
case 'f':
exit = false;
break;
default :   
cout<<"Invalid options , enter a valid option"<<"\n";
break;

}

}
return 0;
}

In: Computer Science

Please type, I will rate you well. Thank you. In Linux: Identify three commands that use...

Please type, I will rate you well. Thank you.

In Linux:

  • Identify three commands that use SUID mode. Discuss why this is so?
  • Identify the commands that are generally causing the highest load on your system and discuss your perspectives on why they cause such a load. Discuss your perspectives on the considerations system administration must give while using these commands.

In: Computer Science

Exercise 1. Rectangle, Circle and Square Write three Python classes named Rectangle constructed by a length...

Exercise 1. Rectangle, Circle and Square Write three Python classes named Rectangle constructed by a length and width, a Circle constructed by a radius and a Square constructed by a side length. Both classes should have the methods that compute: - The area - The diagonal - The perimeter Use as much abstraction as you can. At the end of the file, use those classes to calculate the perimeter of a circle with radius the half of the diagonal of a rectangle with length 20 and width 10.

In: Computer Science