MPD78
09-21-2009, 07:12 AM
Hello all,
I am having trouble deleting the contents of a 1D array.
Below is my program. This program doesn't do anything other than read in the user input values until 100% volume is reach and then prints the array contents out to the screen. If the user exceeds 100% volume, the array contents are to be deleted and the user has to start entering in values from the begining again.
#include "K:\Engineering Program Header Files\nr3.h"
Int sfnum[20]; // array for the shell side fluid component I.D. numbers
Doub pv[20]; // array for the primary fluid volumes
Doub volumearray[20]; // array for the shell side fluid gas component volumes
string sfarray[20]; // array for the shell side fluid gas component names
Doub total; // used to check for bad input of volume greater than 100 percent
Doub vol; // volume
Int count,j,y,i,s,v; // generic counter variables used for looping
Int compnum; // gas component I.D. number
Int pause; // dummy variable to keep the input screen visible
char szInput[256]; // char input variable to help obtain correct user input
void print_std_gases(Int compnum)
{
cout << "Below are the Standard Gases" << endl;
cout << endl;
cout << "1. N2" << setw(10) << "8. AIR" << setw(10) << "14. CH4" << setw(10) << "19. HCL" << endl;
cout << "2. O2" << setw(9) << "9. H2" << setw(12) << "15. C2H6" << setw(9) << "20. H2S" << endl;
cout << "3. CO2" << setw(8) << "10. CO" << setw(12) << "16. C3H8" << setw(9) << "" << endl;
cout << "4. H2O" << setw(8) << "11. NO" << setw(13) << "17. C4H10" << setw(8) << "" <<endl;
cout << "5. SO2" << setw(9) << "12. NO2" << setw(12) << "18. C5H12" << setw(8) << "" << endl;
cout << "6. SO3" << setw(9) << "13. NH3" << setw(12) << "" << setw(8) << "" << endl;
cout << "7. CL2" << setw(9) << "" << setw(12) << "" << setw(8) << "" << endl;
}
string compname(Doub compnum){
if (compnum==00) exit(1);
if (compnum==1)return("N2 ");
if (compnum==2)return("O2 ");
if (compnum==3)return("CO2 ");
if (compnum==4)return("H2O ");
if (compnum==5)return("SO2 ");
if (compnum==6)return("SO3 ");
if (compnum==7)return("CL2 ");
if (compnum==8)return("AIR ");
if (compnum==9)return("H2 ");
if (compnum==10)return("CO ");
if (compnum==11)return("NO ");
if (compnum==12)return("NO2 ");
if (compnum==13)return("NH3 ");
if (compnum==14)return("CH4 ");
if (compnum==15)return("C2H6 ");
if (compnum==16)return("C3H8 ");
if (compnum==17)return("C4H10 ");
if (compnum==18)return("C5H12 ");
if (compnum==19)return("HCL ");
if (compnum==20)return("H2S ");
}
int main()
{
// Enter the primary fluid
cout << endl;
cout << "PRIMARY FLUID COMPOSITION" << endl;
cout << "=============================================" << endl;
print_std_gases(compnum); // Print the standard gases.
count = j = 0; // Initialize counters and array index to zero
do {
do
{
cout << endl;
printf("Select gas component ");
gets(szInput);
compnum = atoi(szInput);
if (compnum==00) exit(1);
if (compnum < 1 || compnum > 20)
{
cout << "Gas not available " << endl;
}
}while(compnum < 1 || compnum > 20);
cout << endl << compname(compnum) << endl;
printf("Enter the volume percent ");
gets(szInput);
vol = atof(szInput);
vol = vol/100; // Convert volume to a percent
total += vol;
// Logic to reset the counters and delete the current array contents
// if the user goes above 100% volume.
if (total > 1){
cout << "Total volume > 100% You must re-enter your values" << endl;
total = count = j = 0; // Re-set the counter and total to zero
// How do I delete the array contents?
}
// End of logic for use trying to enter a volume percent greater than 100.
cout << "Total volume " << (total*100) << endl;
volumearray[j]=vol; // Send volume to array
sfarray[j]=compname(compnum); // Convert component ID # to component name and send to array
sfnum[j]=compnum; // Send component ID # to array
j++;
count++;
}while (total < 1 && total >= 0);
// Print out the array contents
cout << endl;
cout << "===========================================" << endl << endl;
cout << "PRIMARY FLUID COMPOSITION" << endl;
cout << "===========================================" << endl;
for(Int j=0;j<count;j++){
cout << " " << fixed << sfarray[j] << fixed << " Volume % " << volumearray[j]*100 << endl;
}
cin >> pause; // Dummy variable to keep the output screen visible
return 0;
}
However, I can't seem to delete the array contents. I have looked in some reference material and that instructs me to use pointers and the delete [] command but I am not sure how to proceed.
Here is the output.
===========================================
PRIMARY FLUID COMPOSITION
===========================================
N2 Volume % 101.000000
N2 Volume % 100.000000
Any help with this would be great.
Thanks
Matt
I am having trouble deleting the contents of a 1D array.
Below is my program. This program doesn't do anything other than read in the user input values until 100% volume is reach and then prints the array contents out to the screen. If the user exceeds 100% volume, the array contents are to be deleted and the user has to start entering in values from the begining again.
#include "K:\Engineering Program Header Files\nr3.h"
Int sfnum[20]; // array for the shell side fluid component I.D. numbers
Doub pv[20]; // array for the primary fluid volumes
Doub volumearray[20]; // array for the shell side fluid gas component volumes
string sfarray[20]; // array for the shell side fluid gas component names
Doub total; // used to check for bad input of volume greater than 100 percent
Doub vol; // volume
Int count,j,y,i,s,v; // generic counter variables used for looping
Int compnum; // gas component I.D. number
Int pause; // dummy variable to keep the input screen visible
char szInput[256]; // char input variable to help obtain correct user input
void print_std_gases(Int compnum)
{
cout << "Below are the Standard Gases" << endl;
cout << endl;
cout << "1. N2" << setw(10) << "8. AIR" << setw(10) << "14. CH4" << setw(10) << "19. HCL" << endl;
cout << "2. O2" << setw(9) << "9. H2" << setw(12) << "15. C2H6" << setw(9) << "20. H2S" << endl;
cout << "3. CO2" << setw(8) << "10. CO" << setw(12) << "16. C3H8" << setw(9) << "" << endl;
cout << "4. H2O" << setw(8) << "11. NO" << setw(13) << "17. C4H10" << setw(8) << "" <<endl;
cout << "5. SO2" << setw(9) << "12. NO2" << setw(12) << "18. C5H12" << setw(8) << "" << endl;
cout << "6. SO3" << setw(9) << "13. NH3" << setw(12) << "" << setw(8) << "" << endl;
cout << "7. CL2" << setw(9) << "" << setw(12) << "" << setw(8) << "" << endl;
}
string compname(Doub compnum){
if (compnum==00) exit(1);
if (compnum==1)return("N2 ");
if (compnum==2)return("O2 ");
if (compnum==3)return("CO2 ");
if (compnum==4)return("H2O ");
if (compnum==5)return("SO2 ");
if (compnum==6)return("SO3 ");
if (compnum==7)return("CL2 ");
if (compnum==8)return("AIR ");
if (compnum==9)return("H2 ");
if (compnum==10)return("CO ");
if (compnum==11)return("NO ");
if (compnum==12)return("NO2 ");
if (compnum==13)return("NH3 ");
if (compnum==14)return("CH4 ");
if (compnum==15)return("C2H6 ");
if (compnum==16)return("C3H8 ");
if (compnum==17)return("C4H10 ");
if (compnum==18)return("C5H12 ");
if (compnum==19)return("HCL ");
if (compnum==20)return("H2S ");
}
int main()
{
// Enter the primary fluid
cout << endl;
cout << "PRIMARY FLUID COMPOSITION" << endl;
cout << "=============================================" << endl;
print_std_gases(compnum); // Print the standard gases.
count = j = 0; // Initialize counters and array index to zero
do {
do
{
cout << endl;
printf("Select gas component ");
gets(szInput);
compnum = atoi(szInput);
if (compnum==00) exit(1);
if (compnum < 1 || compnum > 20)
{
cout << "Gas not available " << endl;
}
}while(compnum < 1 || compnum > 20);
cout << endl << compname(compnum) << endl;
printf("Enter the volume percent ");
gets(szInput);
vol = atof(szInput);
vol = vol/100; // Convert volume to a percent
total += vol;
// Logic to reset the counters and delete the current array contents
// if the user goes above 100% volume.
if (total > 1){
cout << "Total volume > 100% You must re-enter your values" << endl;
total = count = j = 0; // Re-set the counter and total to zero
// How do I delete the array contents?
}
// End of logic for use trying to enter a volume percent greater than 100.
cout << "Total volume " << (total*100) << endl;
volumearray[j]=vol; // Send volume to array
sfarray[j]=compname(compnum); // Convert component ID # to component name and send to array
sfnum[j]=compnum; // Send component ID # to array
j++;
count++;
}while (total < 1 && total >= 0);
// Print out the array contents
cout << endl;
cout << "===========================================" << endl << endl;
cout << "PRIMARY FLUID COMPOSITION" << endl;
cout << "===========================================" << endl;
for(Int j=0;j<count;j++){
cout << " " << fixed << sfarray[j] << fixed << " Volume % " << volumearray[j]*100 << endl;
}
cin >> pause; // Dummy variable to keep the output screen visible
return 0;
}
However, I can't seem to delete the array contents. I have looked in some reference material and that instructs me to use pointers and the delete [] command but I am not sure how to proceed.
Here is the output.
===========================================
PRIMARY FLUID COMPOSITION
===========================================
N2 Volume % 101.000000
N2 Volume % 100.000000
Any help with this would be great.
Thanks
Matt