int __fastcall MinIntValue(const int * Data, const int Data_Size);
The MinIntValue() function calculates the minimum value of an array of integers. The Data argument of the function is the name of the array. The second argument,
Data_Size is the number-1 of members of the array.
To get the minimum value of a group of integers, declare an integral array of numbers. You can initialize the variable or request the values of its members from the user. The value of the
Data_Size argument must be 1 less than the total number of members.
Here is an example that uses the MaxIntValue() function:
|
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int Numbers[] = { 15, 408, 72, 995, 32 };
int Size = (sizeof(Numbers)/sizeof(double)) - 1;
double MinInteger = MinIntValue(Numbers, Size);
Edit1->Text = MinInteger;
}
//---------------------------------------------------------------------------
The Minimum Value of a Series |
|
double __fastcall MinValue(const double * Data, const int Data_Size);
The MinValue() function gets a numeric value that represents the minimum value of the items of an array. This function takes two arguments. The first argument, Data, represents an array of integers or double-precision numbers. The second argument is the number-1 of the items of the array; for example, if the considered array has 4 members, the
Data_Size argument would be 3.
To use the MinValue() function, declare an array that involves the necessary numbers. You can initialize such a variable or request the values from the user. To calculate the minimum value of a range, supply the array and its size. If you do not know the dimension of the array, you can use the
sizeof operator to find it out. Here is an example that uses the MinValue() function:
|
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double Values[] = { 12.55, 10.15, 980.22, 50.50, 280.12 };
int Size = (sizeof(Values)/sizeof(double)) - 1;
double Minimum = MinValue(Values,Size);
Edit1->Text = Minimum;
}
//---------------------------------------------------------------------------
The Sum of Values of a Series |
|
Extended __fastcall Sum(const double * Data, const int Data_Size);
The Sum() function is used to calculate the sum value of a group of numbers. The first argument of this function, Data, is the name of an array that holds the numbers considered. The
Data_Size argument is the dimension of the array minus 1.
To get the sum of a group of numbers, declare an array to hold the necessary numbers. The numbers can be integers or double precision values. You can initialize the array with these numbers or request their values from the user.
Here is an example of calculating a total number of grades of a student:
|
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Double Grades[] = { 12.50, 14.00, 16.00, 15.50,
12.00, 10.50, 14.50, 17.50 };
int Size = (sizeof(Grades)/sizeof(double)) - 1;
Double Total = Sum(Grades, Size);
Edit1->Text = FloatToStr(Total);
}
//---------------------------------------------------------------------------
The Sum of Integers of a Series |
|
int __fastcall SumInt(const int * Data, const int Data_Size);
The SumInt() function is used to calculate the total of a group of integral numbers. This function takes two arguments. The first, Data, is the name of the array that holds the numbers. The numbers must be integers. If you want to calculate a total of floating-point numbers, use the Sum() function. The second argument,
Data_Size is the size of the array minus one.
Here is an example that simulates a company inventory to count business assets:
|
//---------------------------------------------------------------------------
#include <iostream.h>
#include <math.hpp>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
int Tables, Chairs, BookShelves, TrashCans,
Desktops, Laptops, Printers, FaxMachines,
Books, Pens, Pencils, Others;
cout << "Company Inventory\nType the number of items of each category\n";
cout << "Desktops: "; cin >> Desktops;
cout << "Laptops: "; cin >> Laptops;
cout << "Printers: "; cin >> Printers;
cout << "Fax Machines: "; cin >> FaxMachines;
cout << "Chairs: "; cin >> Chairs;
cout << "Tables: "; cin >> Tables;
cout << "Book Shelves: "; cin >> BookShelves;
cout << "Books: "; cin >> Books;
cout << "Trash Cans: "; cin >> TrashCans;
cout << "Pens: "; cin >> Pens;
cout << "Pencils: "; cin >> Pencils;
cout << "Others: "; cin >> Others;
int Assets[] = { Tables, Chairs, BookShelves, TrashCans,
Desktops, Laptops, Printers, FaxMachines,
Books, Pens, Pencils, Others };
int Items = (sizeof(Assets)/sizeof(int)) - 1;
int AllAssets = SumInt(Assets, Items);
cout << "\nTotal Number of Items: " << AllAssets;
cout << "\n\nPress Enter to send the inventory...";
getchar();
return 0;
}
//---------------------------------------------------------------------------
Company Inventory
Type the number of items of each category
Desktops: 12
Laptops: 2
Printers: 8
Fax Machines: 2
Chairs: 18
Tables: 14
Book Shelves: 10
Books: 20
Trash Cans: 15
Pens: 120
Pencils: 144
Others: 212
Total Number of Items: 577
Press Enter to send the inventory...
The Sum Of Squares of a Series |
|
Extended __fastcall SumOfSquares(const double * Data, const int Data_Size);
The SumOfSquares() function performs a double operation on an array. First it calculates the square S of each member of the array; then it calculates the total of the individual S values. The first argument of the function, Data, is the name of the array, the second argument,
Data_Size represents the dimension of the array minus 1.
To calculate the total of the squares, declare an array variable. You can initialize the array by providing the necessary list of numbers. Otherwise, request the different numbers from the user. The function will take care of the rest.
Here is example: |
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Double Grades[] = { 12.50, 14.00, 16.00, 15.50,
12.00, 10.50, 14.50, 17.50 };
int Size = (sizeof(Grades)/sizeof(double)) - 1;
Double Total = SumOfSquares(Grades, Size);
Edit1->Text = FloatToStr(Total);
}
//---------------------------------------------------------------------------
The Sums and Squares of a Series |
|
void __fastcall SumsAndSquares(const double * Data,
const int Data_Size,
Extended &Sum,
Extended &SumOfSquares);
The SumsAndSquares() function performs two operations and returns two values. Using a group of numbers, the function calculates their total, Sum. It also calculates the square S of each number then calculates the total of the S values, which produces a
SumOfSquares. The first argument, Data, is the array of the numbers considered. The
Data_Size argument is the number of items in the array minus 1. The Sum and the
SumOfSquares arguments are passed by reference, which allows the function to return these last two values.
Here is an example:
|
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Extended Total, TotalOfSquares;
int Size;
double Values[] = { 32.12, 208.45, 14.80, 95.25,
30.32, 102.55, 88.20, 100.05 };
Size = (sizeof(Values)/sizeof(double)) - 1;
SumsAndSquares(Values, Size, Total, TotalOfSquares);
Edit1->Text = FloatToStr(Total);
Edit2->Text = FloatToStr(TotalOfSquares);
}
//---------------------------------------------------------------------------
|
|