1) Specify, design and implement a class called statistician. After a statistician is initialized, it can be given a sequence of double numbers. Each number in the sequence is given to the statistician by activating a member function called next_number. For example, we can declare a statistician called s, and then give it the sequence of numbers 1.1, -2.4, 0.8 as shown here:
statistician s;
s.next_number(1.1);
s.next_number(-2.4);
s.next_number(0.8);
After a sequence has been given to a statistician, there are various member funcitons to obtain infomration about the sequence. Include member functions that will provide the length of the sequence, the last number of the sequence, the sum of all the numbers in the sequence, the arithmetic mean of the numbers(i.e the sum of the numbers divided by the length of the sequence), the smallest number inthe sequence, and the largest number in the sequence. Notice that the length and sum functions can be called at any time, even if there are no enumbers in the sequence. In this case of an "empty" sequence, both length and sum will be zero. But the other member functions all have a precondition requiring that the sequence is non-empty.
You should also provide a member funciton that erases the sequene ( so that the statistician can start afresh with a new sequenece).
Notes: Do not try to store the entire sequence(because you don't know how long this sequence will be). Instead, just store the necessary information about the sequence: What is the sequence lenghth? What is the sum of the numbers in the sequence? What are the last, smallest and largest numbers? Each of these pieces of information can be stored in a private member variable that is updated whenever next_number is activated.
2) Overload the + operator to allow YOU TO add two statisticians from the previous project. If s1 and s2 are two statistics that behaves as it it had the numbers of s1 followed by all of the numbers of s2
This is the C++ code that I have so far. I'm having problem making it work.
main.cpp
#include
using std::cout;
using std::cin;
using std::endl;
int main()
{
Statistician s;
char ch;
double number;
do
{
cout <<"Enter your choice of a next number: ";
cin >>number;
s.nextNumber(number);
cout<
cout<
cout<
cout<
cout<
cout< cin>> ch;
if(tolower(ch)== 'n')
{
cout <<"Do you want to continue to a new sequence?
(Y/N)";
cin>> ch;
if(tolower(ch)!='n')
s.deleteValues();
}
}
while (tolower(ch)!='n');
return 0;
}
STATISTICIAN.h
#include
using std::cout;
using std::cin;
using std::endl;
#ifndef STATISTICIAN_H
#define STATISTICIAN_H
class Statistician
{
public:
Statistician();
double getSequenceLength();
double getSumOfNumbers();
double getSmallest();
double getLargest();
double getLastNumber();
void arithmeticMean();
void nextNumber (double);
void deleteValues();
private:
double sequenceLength;
double sumOfNumbers;
double smallest;
double largest;
double lastNumber;
};
#endif // STATISTICIAN_H
STATISTICIAN.cpp
#include
using std::cout;
using std::cin;
using std::endl;
#include "STATISTICIAN.h"
Statistician::Statistician()
{
sequenceLength = 0;
sumOfNumbers = 0;
smallest = 999999;
largest = -0.99999;
}
double Statistician::getSequenceLength()
{
return sequenceLength;
}
double Statistician::getSumOfNumbers()
{
return sumOfNumbers;
}
double Statistician::getSmallest()
{
if (sequenceLength !=0)
return smallest;
cout < return -1;
}
double Statistician::getLargest ()
{
if (sequenceLength !=0)
return largest;
cout < return -1;
}
void Statistician::getLastNumber()
{
return lastNumber;
}
void Statistician::arithmeticMean()
{
if (sequenceLength==0)
cout< else
cout<
}
void Statistician::nextNumber(double number)
{
sequenceLength++;
sumOfNumbers += number;
lastNumber = number;
if(largest largest = number;
if(smallest>number)
smallest = number;
}
void Statistician::deleteValues()
{
sequenceLength = 0;
sumOfNumbers = 0;
smallest = 999999;
largest = -0.9999;
}
c++ code : It is self-exlanatory code very easy to read and understand.
If you like the answer please give a thumbs up it will keep me motivated to help you guys by solving more and more problems...
#include<bits/stdc++.h>
using namespace std;
class Statistician {
private:
long double length;
long double lastNumber;
long double sum;
long double mean;
long double smallestNumber;
long double largestNumber;
bool empty;
public:
Statistician() {
length = lastNumber = sum = mean = 0;
largestNumber = -999999999;
smallestNumber = 999999999;
empty = true;
}
long double getLength() {
return length;
}
long double getLastNumber() {
if (empty) {
cout << " Sequence is currently empty \n";
}
return lastNumber;
}
long double getSum() {
return sum;
}
long double getMean() {
if (empty) {
cout << " Sequence is currently empty \n";
}
return mean;
}
long double getSmallestNumber() {
if (empty) {
cout << " Sequence is currently empty \n";
}
return smallestNumber;
}
long double getLargestNumber() {
if (empty) {
cout << " Sequence is currently empty \n";
}
return largestNumber;
}
bool getEmpty() {
return empty;
}
void setLength(long double len) {
length = len;
}
void setLastNumber(long double num) {
lastNumber = num;
}
void setSum(long double s) {
sum = s;
}
void setMean(long double m) {
mean = m;
}
void setSmallestNumber(long double s) {
smallestNumber = s;
}
void setLargestNumber(long double num) {
largestNumber = num;
}
void setEmpty(bool em) {
empty = em;
}
void next_number(long double num) {
setEmpty(false);
setLength(getLength() + 1);
setLastNumber(num);
setSum(getSum() + num);
setMean(getSum() / getLength());
setSmallestNumber(min(getSmallestNumber(), num));
setLargestNumber(max(getLargestNumber(), num));
}
void eraseSequence() {
length = lastNumber = sum = mean = 0;
largestNumber = -999999999;
smallestNumber = 999999999;
empty = true;
}
Statistician operator +(Statistician &statistician1){
Statistician statistician;
statistician.setSmallestNumber(min(statistician1.getSmallestNumber(),this->smallestNumber));
statistician.setLargestNumber(max(statistician1.getLargestNumber(),this->largestNumber));
statistician.setSum(statistician1.getSum() + this->sum);
statistician.setLength(statistician1.getLength() + this->length);
statistician.setMean(statistician.getSum() / statistician.getLength());
statistician.setLastNumber(statistician1.getLastNumber());
statistician.setEmpty(false);
return statistician;
}
void printDetails(){
cout<<"Length : "<<this->length<<"\n";
cout<<"Smallest Number : "<<this->smallestNumber<<"\n";
cout<<"Largest Number : "<<this->largestNumber<<"\n";
cout<<"Sum : "<<this->sum<<"\n";
cout<<"Mean : "<<this->mean<<"\n";
cout<<"Last Number : "<<this->lastNumber<<"\n";
}
};
int main() {
Statistician s;
long double num;
do {
cout << "Enter the number - ";
cin >> num;
s.next_number(num);
cout << "1. Exit or 2.Continue\n";
cin >> num;
} while (num != 1);
Statistician tt ;
tt.next_number(4);
tt.next_number(5);
tt.next_number(6);
Statistician t = s + tt;
t.printDetails();
return 0;
}

1) Specify, design and implement a class called statistician. After a statistician is initialized, it can be...
Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
Objectives The purpose of this lab is to help you become familiar with the development environment, to reinforce the concepts covered in chapter 2, to reinforce the implementation of object oriented concepts in C++, and to reinforce the implementation of operator overloading in C++. Requirements Extend the implementation of the statistician class created in Lab 2 to overload operators +, *, and ==. The extended class definition is given in stats2.h. You need implement the three operator overloading functions in...
C++ How to find the smallest number of 5. A simple program but i am still a beginner. With the code i already have, i have found the largest. I am unaware of what to initialize smallest to because the answer comes out as 0 even when there is no 0. Code so far: #include <iostream> using namespace std; int main() { int numbers; int largest = 0; int smallest; cout << "Enter 5 numbers."; ...
In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long, medium, short, none string furColours[5]; }; void initCat (Cat&, double, double, double, string, string, const string[]); void readCat (Cat&); void printCat (const Cat&); bool isCalico (const Cat&); bool isTaller (const Cat&, const Cat&); #endif ***//Cat.cpp//*** #include "Cat.h" #include <iostream> using namespace std; void initCat (Cat& cat, double l, double h, double tL, string eC,...
Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...
c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...
SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){ int num1,num2; cout << "Enter two numbers "<< endl; cout << "First :"; cin >> num1; cout << "Second :"; cin >>num2; int result=num1+num2; cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result; ...
Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...