Using C++:
The root mean square is a specific kind of average which is used for various purposes. This means that a sequence of values is squared and summed, then divided by the count of the values; the entire calculation is then square-rooted. Ask the user for input; stop when the user enters -1. Be sure to use the square and squareRoot functions:
float squareRoot (float s) {
float xn;
if (s == 0.0) {
return 0.0;
}
xn = s/2.0;
int counter = 1;
while (counter <= 10) {
xn = (xn + (s/xn))/2.0;
counter = counter + 1;
}
return xn;
}
and
int square (int what) {
int answer = what * what;
return answer;
}
#include <iostream>
using namespace std;
float squareRoot (float s) {
float xn;
if (s == 0.0) {
return 0.0;
}
xn = s/2.0;
int counter = 1;
while (counter <= 10) {
xn = (xn + (s/xn))/2.0;
counter = counter + 1;
}
return xn;
}
int square (int what) {
int answer = what * what;
return answer;
}
int main()
{
//declare variables
bool flag=true;
int value=0;
float sum=0;
int cnt=0;
//prompt the user until -1 is entered
do
{
//prompt user for
value
cout<<"Enter a
value: ";
cin>>value;
//check if user is
-1,exit
if(value==-1)
flag=false;
else
{
//increment no of numbers
cnt++;
//find square root of nos and add to sum
sum+=square(value);
}
}while(flag);
//divide sum by total no of numbers
inputted
sum=sum/cnt;
//find square root of sum value
sum=squareRoot(sum);
//display RSM
cout << "Root Mean Square Root of "
<<value<<" is "<<sum<< endl;
return 0;
}
Sample output:
Enter a value: 2
Enter a value: 5
Enter a value: 8
Enter a value: 9
Enter a value: 4
Enter a value: -1
Root Mean Square Root of -1 is 6.16
Using C++: The root mean square is a specific kind of average which is used for...
The output should be "The distance is 0" (The expected). ==================== YOUR OUTPUT ===================== 0001: Enter~the~x~coordinate~for~point~1:~0 0002: Enter~the~y~coordinate~for~point~1:~0 0003: Enter~the~x~coordinate~for~point~2:~0 0004: Enter~the~y~coordinate~for~point~2:~0 0005: The~distance~is~-nan =================== MISMATCH FOUND ON LINE 0005: =================== ACTUAL : The~distance~is~-nan EXPECTED: The~distance~is~0 ====================================================== #include <iostream> #include <iomanip> #include <string> using namespace std; float squareRoot(float s) { float xn; xn = s / 2.0; int counter = 1; while (counter <= 10) { xn = (xn + (s/xn))/2.0; counter = counter + 1; } return xn; } int...
Write three functions that compute the square root of an argument using three different methods. The methods are increasingly sophisticated, and increasingly efficient. The square root of a real number is the values such that x . For us, the values will be double precision variables and so may not be perfectly accurate. Also, for us, assume that is in the range 0.0 to 100.0 You program should have a main() that asks the user for x and an accuracy...
int short real float Question 11 The square brackets [] are commonly used in C for... attaching multiple lines of code declaring and accessing arrays commenting code setting precedence in arithmetic calculations Question 12 + → XCO D Question 13 4 pts #include<stdio.h> void change(int "b, int n): int maino inti, al = 12.4,6,8, 10): changea, 5): for(i=0; i< =4; i++) printf("%d.". a[i]): return 0; void change(int *b, int n) int i; for(i=0; i<n; i++) "b+1) = "(+1)+5: 246810 2.15,...
Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std; /* * Calculate the square of a number */ float square (float x) { return x*x; } /* * Calculate the average from a list of floating point numbers */ float average(vector<float>& values) { float sum = 0.0f; float average; for (float x : values) sum += x; average = sum / values.size(); return average; } /** Calculate the standard deviation from a vector...
I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n): lst = [] for i in range(1,n+1): val = float(input('Enter float '+str(i)+': ')) lst.append(val) return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...
Question 1 Which pre-written C function can be used to determine if two strings are the same? A) equals B) strcmp C) strlen D) strcpy E) None of the Above Question 2 The function below is most like which existing string function? int f(char a[ ]) { int count = 0; while (a[count] != ‘\0’) count++; return count; } A) strcat B) strcmp C) strcpy D) strlen E) None of the Above Question 3 The function...
"you will write a program in C++ which will read a list of up to 100 integers from the user, and print them back to the screen in sorted order. The user can indicate that they are done entering numbers by entering any negative value. Your program will store the entered numbers into an array. It will then sort the array, using the selection sort algorithm. After each iteration of the sorting algorithm, it will print the current state of...
Kindly solve this using C PROGRAMMING ONLY.
4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...
In C++ and use functions that are asked for, thanks! Implement the BinarySearchTree ADT in a file BinarySearchTree.h exactly as shown below. // BinarySearchTree.h // after Mark A. Weiss, Chapter 4, Dr. Kerstin Voigt #ifndef BINARY_SEARCH_TREE_H #define BINARY_SEARCH_TREE_H #include <cassert> #include <iostream> using namespace std; template <typename C> class BinarySearchTree { public: BinarySearchTree( ) : root{ nullptr } { } ~BinarySearchTree( ) { makeEmpty(); } const C & findMin( ) const { assert(!isEmpty()); return findMin( root )->element; } const C...
Question 31 In C, what is the computational result of 8/5*2.5? Question 32 Examine the for statement given below. What is the most correct answer given below? for(degrees==0.0; degrees<=360.0; degrees+=20.0) ( ) Degrees must be in radians. ( ) Degrees must be capitalized. ( ) Cannot use double equal signs for assigning values to variables. ( ) Degrees cannot be incremented in the manner shown. Question 33 In a C program the formal and actual parameters that are used between...