Question

In: Computer Science

Complete the Vec class to make it similar to the vector. sample code here. #include #include...

Complete the Vec class to make it similar to the vector.

sample code here.

#include

#include

#include

#include

#include

using namespace std;

int get_mode( vector vec )

{

int numbers[101] = {0};

for ( int e : vec ) numbers[e]++;

int greatest = 0, n = 0;

for ( int i = 0; i <= 100; i++ )

{

if ( numbers[i] > greatest )

{

greatest = numbers[i];

n = i;

}

}

return n;

}

const double g = 9.81;

const double k = 0.24;

double v( double m, double t )

{

return sqrt(m * g / k) * tanh( sqrt(k * g / m) * t );

}

double d( double m, double t )

{

return m / k * log( cosh(sqrt(k * g / m) * t) );

}

int main()

{

cout << "Please enter the skydiver mass: ";

double m;

cin >> m;

cout << "k = 0.24kg/m, m = 95.0kg, g = 9.81m/s^2" << endl;

cout << endl;

cout << "| Time | Velocity | Distance |" << endl;

for ( int t = 1; t <= 8; t++ )

{

cout << "| " << setw(4) << t << " | ";

cout << setw(8) << fixed << setprecision(2) << v(m, t) << " | ";

cout << setw(8) << fixed << setprecision(2) << d(m, t) << " |" << endl;

}






return 0;

}

Solutions

Expert Solution

The complete source code using the Vec class is given below:

#include <iostream>
#include<vector>
#include<math.h>
#include<iomanip>

using namespace std;

class Vec
{
//data member declaration
const double g = 9.81;
const double k = 0.24;
  
public:
  
//method to get the mode
int get_mode(vector<float> vec)
{
int numbers[101] = {0};
for ( int e : vec ) numbers[e]++;
int greatest = 0, n = 0;
for ( int i = 0; i <= 100; i++ )
{
if ( numbers[i] > greatest )
{
greatest = numbers[i];
n = i;
}
}
return n;
}

//method to get the velocity
double v( double m, double t )
{
return sqrt(m * g / k) * tanh( sqrt(k * g / m) * t );
}
  
//method to get the distnce
double d( double m, double t )
{
return m / k * log( cosh(sqrt(k * g / m) * t) );
}
};

int main()
{
//create object of class Vec
Vec v1;
  
//get user input
cout << "Please enter the skydiver mass: ";
double m;
cin >> m;
  
//display the k, m, and g
cout << "k = 0.24kg/m, m = 95.0kg, g = 9.81m/s^2" << endl;
cout << endl;
  
//display the table
cout << "| Time | Velocity | Distance |" << endl;
for ( int t = 1; t <= 8; t++ )
{
cout << "| " << setw(4) << t << " | ";
cout << setw(8) << fixed << setprecision(2) << v1.v(m, t) << " | ";
cout << setw(8) << fixed << setprecision(2) << v1.d(m, t) << " |" << endl;
}
return 0;
}

OUTPUT:


Related Solutions

Complete the code to make the following main work public class Time { **put the solution...
Complete the code to make the following main work public class Time { **put the solution here** public static void main(String[] args){ Time a = new Time(15,10,30); Time b = new Time(); // default to 15:00:00(the start time of our class!) System.out.println(a); // should print out: 15:10:30 System.out.println(b); // should print out: System.out.println(a.dist(b)); // print the difference in seconds between the two timestamps } }
make a tree for the Chordates – include changes here too
make a tree for the Chordates – include changes here too
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a,...
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a, b, c) Most of these function bodies can be written in only a few lines. Error checking is not required. Test your class using the test.h file. The triple.cpp file is the code unit tested on submission. main.cpp #include #include #include #include "triple.h" #include "test.h" using namespace std; int main() { myTest(); return 0; } triple.h #ifndef TRIPLE_H #define TRIPLE_H #include #include using namespace...
Here is the R code for running a t-test: t.test( numeric vector of data values, another...
Here is the R code for running a t-test: t.test( numeric vector of data values, another optional numeric vector of data values,        alternative = c("two.sided", "less", "greater"),        mu = Ho, paired = c(TRUE, FALSE), var.equal = c(TRUE,FALSE),conf.level =1-) 1.) Suppose 30 students are all taking the same Math 115 and English 101 classes at CSUN. You want to know in which class students tend to do better. The data below represents the class averages of the students in both classes....
Here is the R code for running a t-test: t.test( numeric vector of data values, another...
Here is the R code for running a t-test: t.test( numeric vector of data values, another optional numeric vector of data values,        alternative = c("two.sided", "less", "greater"),        mu = Ho, paired = c(TRUE, FALSE), var.equal = c(TRUE,FALSE),conf.level =1-) 2) You want to determine if the average height of men in California is greater than the average height of men in Nebraska. You take a random sample of 30 men in California and 30 men in Nebraska. The data below represents...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell {...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell { int val; Cell *next; }; int main() { int MAX = 10; Cell *c = NULL; Cell *HEAD = NULL; srand (time(NULL)); for (int i=0; i<MAX; i++) { // Use dynamic memory allocation to create a new Cell then initialize the // cell value (val) to rand(). Set the next pointer to the HEAD and // then update HEAD. } print_cells(HEAD); }
Here is an outline for some code I need to write. This class used Intro to...
Here is an outline for some code I need to write. This class used Intro to Java Edition 11, and we only got to Chapter 9. There is no set right way that this program has to be done. Feel free to interpret this in a way that you wish. Mrs. Quackenbush is back! She now has bought a beverage establishment, The Green Dragon Inn, and needs to have a way to insure the consistency of the drinks her employees...
1. Modify the HeapIntPriorityQueue class written in this chapter to make it configurable in ways similar...
1. Modify the HeapIntPriorityQueue class written in this chapter to make it configurable in ways similar to Java's PriorityQueue class. Make it possible for the heap to be a min-heap or max-heap. (If you create a heap of objects, you could also modify it to accept a Comparator parameter to its constructor.) (add Comparator sort to provided Heap data structure Class) 2. Change to HeapPriorityQueue with CalendarDate which implements the Comparator interface 3. Modify HeapPriorityQueue to accept a different Comparator,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT