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

C++ How to make this code take a class object instead of int for the vector...
C++ How to make this code take a class object instead of int for the vector queue and be able to enqueue and dequeue the object? #include <iostream> #include <float.h> #include <bits/stdc++.h> using namespace std; void print_queue(queue<int> Q) //This function is used to print queue { while (!Q.empty()) { cout<< Q.front() << " "; Q.pop(); } } int main() { int n = 10; vector< queue<int> > array_queues(n); //Create vector of queues of size 10, each entry has a queue...
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 } }
Complete the class code below and include a method named partition which takes an integer array...
Complete the class code below and include a method named partition which takes an integer array and a partition integer as parameters and then partitions the original array into two new arrays where elements of the first array are all less than or equal to the partition integer and the second array are all greater than the partition integer. The method should print the original array, followed by the lower partition and finally the upper partition. Nothing should be returned...
make a tree for the Chordates – include changes here too
make a tree for the Chordates – include changes here too
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT