Sunday, May 31, 2015

Parallel Array in C++

In this article I would like to share with you a program that I wrote a long time ago in C++ to demonstrate the concepts of parallel array. According to Wikipedia.org, a group of parallel arrays is a data structure for representing arrays of records. It keeps a separate, homogeneous array for each field of the record, each having the same number of elements. Then, objects located at the same index in each array are implicitly the fields of a single record. Pointers from one object to another are replaced by array indices. This contrasts with the normal approach of storing all fields of each record together in memory.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.  People here in the Philippines who wish to contact me can reach me thru my mobile number 09173084360.

Thank you and Happy Programming.



Sample Program Output

Program Listing

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
 char str[][20] = {"Wally"," Skeeter"," Corky"," Jessie", "Sadie"}; 


    int val1[] = {18, 22, 12, 17, 15}; 
    int val2[] = {20 ,25 ,16 ,18 ,17 };

    cout << "\n\n";    
    cout << "\t Parallel Array in C++";
    cout << "\n\nCreated By: Mr. Jake R. Pomperada, MAED-IT";
    cout << "\n\n";    
    cout << setw(10) << "Name " << setw(12) << "Score 1" 
        << setw(10) << "Score 2";
    cout << "\n\n";    
    for(int index = 0; index < 5; index++)
{
     cout<<setw(10)<<str[index]
            <<setw(10)<<val1[index]
            <<setw(10)<<val2[index]<<endl;
}
    cout << "\n\n";    
    system("PAUSE");
    return EXIT_SUCCESS;

}


No comments:

Post a Comment