1 Replies - 634 Views - Last Post: 01 August 2014 - 06:27 AM Rate Topic: -----

#1 Gamme40   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 16-October 11

Arrays and Math

Posted 01 August 2014 - 06:22 AM

Good evening gents,

I am a beginner C++ programmer and i'm experiencing some difficulty with a task i have...

This is my code so far. I am working with functions and i can't seem to form the main.cpp file to work in conjunction wth the rms.cpp file. I am receiving the errors that are connected with the MATRIX_ROWS and MATRIX_COLUMNS being out of scope, even though they have been pre-declared in the rms.h file...

Here is what I have so far. The object of this program is that the rootMeanSquare accepts an array of type float, and an int indicating the number of elements in the array. It has to return the square root of the mean of the squares of the elements in this array.

The matrixRMS will accept two arguments, a 2D array of floats and a 1D array of floats... This function writes values to the second parameter (the 1D array)... the value it writes to the array is determined by taking the row of each matrix and using it in conjuction with the RMS of the sum total and storing it there.

This is rms.cpp
#ifndef RMS_H
#define RMS_H
#include "rms.h"
#include "math.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;

float rootMeanSquare(const float array[], int count)
	float squareRt;
	int x;
	double sumOfSquare = 0;
	for(x = 0; x < sizeof(array); x++)
		sumOfSquare += pow(array[x], 2);
	squareRt = sqrt(sumOfSquare/count);
	return squareRt;

void matrixRMS(const float matrix[][5], float rowRMS[])
	int row;
	int col;
	float sumOfRow = 0;
	for(row = 0; row < matrix[row][col];row++)
		for(col = 0; col < matrix[row][col]; col++)
			sumOfRow += matrix[row][col];
		rowRMS[row] = sumOfRow;
		sumOfRow = 0;
	rootMeanSquare(rowRMS, col);

this is rms.h we are not allowed to modify this at all:
#ifndef RMS_H
#define RMS_H

float rootMeanSquare(const float array[], int count);

const int MATRIX_ROWS = 3;
const int MATRIX_COLUMNS = 5;

void matrixRMS(const float matrix[][MATRIX_COLUMNS], float rowRMS[]);


Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Arrays and Math

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6216
  • View blog
  • Posts: 21,454
  • Joined: 05-May 12

Re: Arrays and Math

Posted 01 August 2014 - 06:27 AM

It's because you put header guards within your .cpp file. Why do you have lines 1, 2, and 46 in your .cpp file?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1