CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    May 2011
    Posts
    6

    Post Return an string array from a function C++

    I'm trying to return a string array from a function. Within this function the user will define the legnth of the array and then populate the array. I need the array return to the call so that I can send it to a print function when the time comes. I have include the code that I have, thanks for the help

    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include "windows.h"
    #include <dos.h>

    using namespace std;
    //int get_Num_Units( );
    void output(string& s1);
    void get_pressure(double p);
    void nuclear();
    void industrial();
    string *Seri_Num();
    int get_Unit_Num();
    int get_chameber_Num();

    int main()
    {

    //string unit_one,unit_two,unit_three;
    int unit_type;
    //double pressure;
    //int check=0;

    //cout << "Enter the max pressure:" << endl;
    //cin >> pressure;
    cout << " 1. Nuclear units press 1 " << endl;
    cout << " 2. Industrial nuits press 2 " << endl;
    cin >> unit_type;


    if (unit_type == 1)
    {

    nuclear();
    }
    else if (unit_type == 2)
    {
    void industrial();
    }


    //cout <<"Your name is: "<< myname << endl;

    return 0;
    }

    //
    void nuclear()
    {

    int units,chamber;
    string Seri = "";

    chamber = get_chameber_Num();
    //units = get_Unit_Num();
    Seri = Seri_Num();



    }
    //This is uesd to get the chamber number
    int get_chameber_Num()
    {
    system("CLS");
    int chamber;
    char check = 'y';
    do
    {


    cout << "Enter the chamber number: " << endl;
    cin >> chamber;

    cout << "Is this correct?? " << endl;
    cin >> check;

    }
    while( check != 'y');
    system("CLS");
    return chamber;
    }

    // This is to get the total number of units from the user
    int get_Unit_Num()
    {

    int unit_num;
    do
    {
    system("CLS");
    cout << "Enter number of units:" << endl;
    cin >> unit_num;

    if(unit_num > 3)
    {

    cout << "Enter a number no greater than 3: " << endl;

    }




    }
    while(unit_num > 3);
    system("CLS");
    return unit_num;
    }

    // this function is used to load the array and get the serial numbers from the user

    string *Seri_Num()
    {
    string serNum;
    int unit_num;
    string *unit= new string[unit_num];


    do
    {
    system("CLS");
    cout << "Enter number of units:" << endl;
    cin >> unit_num;

    if(unit_num > 3)
    {

    cout << "Enter a number no greater than 3: " << endl;

    }




    }
    while(unit_num > 3);
    system("CLS");

    for (int i=0; i< unit_num; i++) // This loads the array
    {
    cout << "Enter serial number (8 charecter max) \n";
    cin >> serNum;
    unit[i] = serNum;
    }
    return unit; // return the array


    }
    Attached Files Attached Files
    Last edited by hfbroady; July 13th, 2011 at 08:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured