Question

In: Computer Science

program runs but does not compute the average. Here is what I have. Thank you #include...

program runs but does not compute the average. Here is what I have. Thank you

#include <iostream>
#include<iomanip>
#include"Average.h"
using namespace std;


int main() {
   cout<<"Enter 3 integers, seperated by spaces, on a single line: ";
   int number1, number2, number3;
   cin>>number1>>number2>>number3;
   int average;
   double avg;
//   average = computeAverage(number1, number2, number3);
   cout<<"Average of "<<number1<<" and "<<number2 <<" and "<<number3 <<" is "
   <<average<<endl;
  
  
   cout<<"Enter 2 integers, seperated by a space, on a single line: ";
//   int number1, number2;
   cin>>number1>>number2;
  
   cout<<"Average of "<<number1<<" and "<<number2<<" is "
   <<average<<endl;
  
   cout<<"Enter 3 doubles, seperated by a space, on a single line: ";
   double num1, num2, num3;
   cin>>num1>>num2>>num3;
  
   cout<<"Average of " <<num1<<" and "<<num2<<" and "<<num3<<" is "
   <<average<<endl;
  
   cout<<"Enter 2 doubles, seperated by a space, on a single line: ";
//   double num1, num2;
   cin>>num1>>num2;
  
   cout<<"Average of "<<num1<<" and "<<num2<<" is "
   <<average<<endl;
}

#include<iostream>
#include<iomanip>

class Average{
   private:
       int number1;
       int number2;
       int number3;
       int average;
       double num1;
       double num2;
       double num3;
       double avg;
      
int computeAverage(int x, int y, int z){
   int averageValue = (x + y + z)/3;
  
   return averageValue;
}
   int computeAverage(int x, int y){
       int averageValue = (x + y)/2;
  
   return averageValue;
}
   double computeAverage(double x, double y, double z){
       double averageValue = (x + y + z)/3;
  
   return averageValue;
}
   double computeAverage(double x, double y){
       double averageValue = (x + y)/2;
  
   return averageValue;
}
};

Solutions

Expert Solution

#include <iostream>
#include<iomanip>
using namespace std;


class Average{
   private:
       int number1;
       int number2;
       int number3;
       int average;
       double num1;
       double num2;
       double num3;
       double avg;
public:
int computeAverage(int x, int y, int z){
   int averageValue = (x + y + z)/3;
   return averageValue;
}
   int computeAverage(int x, int y){
       int averageValue = (x + y)/2;
  
   return averageValue;
}
   double computeAverage(double x, double y, double z){
       double averageValue = (x + y + z)/3;
  
   return averageValue;
}
   double computeAverage(double x, double y){
       double averageValue = (x + y)/2;
  
   return averageValue;
}
};
int main() {
   cout<<"Enter 3 integers, seperated by spaces, on a single line: ";
   int number1, number2, number3;
   cin>>number1>>number2>>number3;
  Average a;
   int average = a.computeAverage(number1,number2,number3);
   double avg;
//   average = computeAverage(number1, number2, number3);
   cout<<"Average of "<<number1<<" and "<<number2 <<" and "<<number3 <<" is "
   <<average<<endl;
  
  
   cout<<"Enter 2 integers, seperated by a space, on a single line: ";
//   int number1, number2;
   cin>>number1>>number2;
  average = a.computeAverage(number1,number2);
   cout<<"Average of "<<number1<<" and "<<number2<<" is "
   <<average<<endl;
  
   cout<<"Enter 3 doubles, seperated by a space, on a single line: ";
   double num1, num2, num3;
   cin>>num1>>num2>>num3;
  average = a.computeAverage(number1,number2,number3);
   cout<<"Average of " <<num1<<" and "<<num2<<" and "<<num3<<" is "
   <<average<<endl;
  
   cout<<"Enter 2 doubles, seperated by a space, on a single line: ";
//   double num1, num2;
   cin>>num1>>num2;
  average = a.computeAverage(number1,number2);
   cout<<"Average of "<<num1<<" and "<<num2<<" is "
   <<average<<endl;
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class DivSales { private:    int quarterSales[4];    static double totalSales; public:    void add(int, int, int, int);    int sales(int);    static double getValue()    {        return totalSales;    };    void DivSales::add(int s1, int s2, int s3, int s4)    {        quarterSales[0] = s1;        quarterSales[1] = s2;        quarterSales[2] = s3;        quarterSales[3] = s4;...
I think I have this figured out, but need a double check... Thank you Here is...
I think I have this figured out, but need a double check... Thank you Here is the question: Regional distributors are currently using continuous review inventory policy. Compute and describe their inventory management policy and associated cost. Ignore inbound and outbound transportation cost. Provide answers and calculations for order quantity, demand during lead time, safety stock, average inventory level, inventory holding cost per week, ordering cost per week, and total cost per week. The service level is 90% and the...
PLEASE COMMENT THE FOLLOWING LEXICAL ANALYSER PROGRAM. Thank you. #include #include #include #include #include using namespace...
PLEASE COMMENT THE FOLLOWING LEXICAL ANALYSER PROGRAM. Thank you. #include #include #include #include #include using namespace std; int isKeyword(char buffer[]){ char keywords[32][10] = {"auto","break","case","char","const","continue","default", "do","double","else","enum","extern","float","for","goto", "if","int","long","register","return","short","signed", "sizeof","static","struct","switch","typedef","union", "unsigned","void","volatile","while"}; int i, flag = 0; for(i = 0; i < 32; ++i){ if(strcmp(keywords[i], buffer) == 0){ flag = 1; break; } } return flag; } int main(){ char ch, buffer[15], operators[] = "+-*/%="; ifstream fin("Text.txt"); int i,j=0; if(!fin.is_open()){ cout<<"error while opening the file\n"; exit(0); } while(!fin.eof()){ ch = fin.get();    for(i =...
Please in C++ thank you! Please also include the screenshot of the output. I have included...
Please in C++ thank you! Please also include the screenshot of the output. I have included everything that's needed for this. Pls and thank you! Write a simple class and use it in a vector. Begin by writing a Student class. The public section has the following methods: Student::Student() Constructor. Initializes all data elements: name to empty string(s), numeric variables to 0. bool Student::ReadData(istream& in) Data input. The istream should already be open. Reads the following data, in this order:...
I need to update this program to follow the these requirements please and thank you :...
I need to update this program to follow the these requirements please and thank you : Do not use packages Every class but the main routine class must have a toString method . The toString method for Quadrilateral should display its fields: 4 Points. All instance variables should be declared explicitly private . Area incorrect : enter points no: 1 1 3 enter points no: 2 6 3 enter points no: 3 0 0 enter points no: 4 5 0...
I have a code and it works and runs as it supposed too. What is the...
I have a code and it works and runs as it supposed too. What is the UML for it? Any help will be awesome. Thanks. import java.util.Scanner; public class StringToMorseCode { public static void main(String[] args){ Scanner input = new Scanner(System.in);    char[] letters = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6',...
I need a scholarship essay for my nursing program. please and thank you.
I need a scholarship essay for my nursing program. please and thank you.
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
Shown here is the sort.c program which takes data.txt and sorts it. If I have found...
Shown here is the sort.c program which takes data.txt and sorts it. If I have found the addresses for system(), exit(), and “/bin/sh”, how would I do the following by ONLY changing the contents of data.txt?: 1) open the shell code 2) exit cleanly fron the shell code all while 3) not receiving a seg fault. I beleive the correct answer is to have about 18-19 rows of aaaaaaaa followed by the three addresses so that when the stack starts...
What are the recommendations on the topic you have? I will like all your answers! Here...
What are the recommendations on the topic you have? I will like all your answers! Here is the detail of the requirements. Chinese Luxury Tourism in Hawaii Please do not talk about the importance of Chinese Tourism to Hawaii, we have already covered that, your paper should be a new idea to prepare for Chinese Luxury Tourism to Hawaii. For example- the best paper I saw last semester was on implementing a Hawaii dim sum with local taro and coconut...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT