Click here to Skip to main content
15,915,019 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Read PST file structure using VC++ Pin
Hamid_RT4-May-06 21:14
Hamid_RT4-May-06 21:14 
GeneralRe: Read PST file structure using VC++ Pin
K. narasimharao4-May-06 22:58
K. narasimharao4-May-06 22:58 
QuestionMore Class Work. Pin
JarethAshaer4-May-06 20:31
JarethAshaer4-May-06 20:31 
AnswerRe: More Class Work. Pin
Cedric Moonen4-May-06 20:40
Cedric Moonen4-May-06 20:40 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 21:19
JarethAshaer4-May-06 21:19 
GeneralRe: More Class Work. Pin
Cedric Moonen4-May-06 21:24
Cedric Moonen4-May-06 21:24 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 21:27
JarethAshaer4-May-06 21:27 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 21:35
JarethAshaer4-May-06 21:35 
Revised code is as follows then
Header File :
#include <iostream>
using namespace std;
int i;
class Array
{
private:
int element;
int *array;
bool extend();
bool contract();
public:
int *temp;
int *temp2;
Array( );
Array(int array);
Array(int array, int elem);
~Array() {}
bool append();
bool chop();
bool print();
bool success;
};

/* Default Constructor
-Pre none
-Post *array set to 0
*/
Array :: Array ( )
{
int *array = 0;
}

/* Secondary Constructor
Initializes Dynamic Array
-Pre int elem set to a value
-Post *array set to dynamic array
*/
Array::Array (int elem)
{
element = elem;
array = new int[element];
for (i=0; i<element; i++)
{
cout << "Please enter element "<< i << " : " << endl;
cin >> array[i];
}
}
bool Array :: append()
{
success = false;
success = extend();
if (success = true)
return (true);
else
return (false);
}
bool Array:: extend()
{
element += 1;
temp = new int[element];
for (i=0; i<element; i++){
temp[i] = array[i];
}
cout << "Enter new element value : " << endl;
cin >> temp[element-1];
delete [] array;
array = new int[element];
for (i=0; i<element; i++){
array[i] = temp[i];
}
delete [] temp;
*temp = NULL;
return (true);
}
bool Array :: chop()
{
success = false;
success = contract();
if (success = true)
return (true);
else
return (false);
}
bool Array :: contract()
{
element -= 1;
temp2 = new int[element];
for (i=0; i<element; i++){
temp2[i] = array[i];
}
delete [] array;
array = new int[element];
for (i=0; i<element; i++){
array[i] = temp2[i];
}
delete [] temp2;
*temp2 = NULL;
return (true);
}
bool Array :: print()
{
for (i = 0; i < element; i++)
{
cout << "The value of element " << i << " is " << array[i] << endl;
}
return (true);
}
Main
#include <iostream>
#include "class.h"
using namespace std;
void main()
{
int n;
int elem;
bool completion = false;
cout << "Enter desired array size : " << endl;
cin >> elem;
Array ar1(elem);
completion = ar1.append();
if (completion == true)
{
cout << "Append successful!" << endl;
}
else
{
cout << "Append Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.chop();
if (completion == true)
{
cout << "Chop successful!" << endl;
}
else
{
cout << "Chop Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.print();
if (completion == true)
{
cout << "Print successful!" << endl;
}
else
{
cout << "Print Unsuccessful!!" << endl;
}
completion = false;
system ("pause");
}
I unfortunately get an access violation error, but if I force the debugger to continue, the program works. Which, is nice to know, but I still need to fix it Wink | ;)
GeneralRe: More Class Work. Pin
Cedric Moonen4-May-06 21:39
Cedric Moonen4-May-06 21:39 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 21:52
JarethAshaer4-May-06 21:52 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 22:06
JarethAshaer4-May-06 22:06 
GeneralRe: More Class Work. Pin
Cedric Moonen4-May-06 22:07
Cedric Moonen4-May-06 22:07 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 22:15
JarethAshaer4-May-06 22:15 
AnswerRe: More Class Work. Pin
Stephen Hewitt4-May-06 21:23
Stephen Hewitt4-May-06 21:23 
GeneralRe: More Class Work. Pin
JarethAshaer4-May-06 21:24
JarethAshaer4-May-06 21:24 
GeneralRe: More Class Work. Pin
Cedric Moonen4-May-06 21:28
Cedric Moonen4-May-06 21:28 
QuestionCurrent Folder path Pin
Rinu_Raj4-May-06 20:12
Rinu_Raj4-May-06 20:12 
AnswerRe: Current Folder path Pin
Nibu babu thomas4-May-06 20:17
Nibu babu thomas4-May-06 20:17 
AnswerRe: Current Folder path Pin
Aryan S4-May-06 21:04
Aryan S4-May-06 21:04 
AnswerRe: Current Folder path Pin
Aryan S4-May-06 21:06
Aryan S4-May-06 21:06 
GeneralRe: Current Folder path Pin
Rinu_Raj4-May-06 21:08
Rinu_Raj4-May-06 21:08 
Questionsocket programming Pin
code664-May-06 19:11
code664-May-06 19:11 
AnswerRe: socket programming Pin
Ganesh_T4-May-06 19:40
Ganesh_T4-May-06 19:40 
QuestionUSB Communication in VC++?? Pin
raghuji.rao4-May-06 19:01
raghuji.rao4-May-06 19:01 
AnswerRe: USB Communication in VC++?? Pin
Hamid_RT4-May-06 19:20
Hamid_RT4-May-06 19:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.