Hi,
Can anyone help with a project I'm working on I'm new to classes
and I got really confused while trying to convert a simple console application in to a class file. I would appreciate some help if anyone willing to.
Following is the code I am trying to convert

#include <iostream.h>
const int MAX = 15;
void get_values(int []);
void print_values (int []);
void sort_values (int [], int);
void search_values (int []);
int main()
{
   int values[MAX];
   get_values(values);
   sort_values(values, MAX); 
   print_values(values);  //This will allow user to see the sorted order of the values entered if enabled.
   search_values(values);
   return 0;
}
void get_values(int value[])
{
 
 for (int i=0; i < MAX; i++)
 {
  cout << "Please enter value #" << i+1 <<" : ";
  cin >> value[i];
 }
}
 
void print_values (int value[])
{
 cout<<endl;
 for (int i=0; i<MAX; i++)
 {
  cout << value [i] << endl;
 }
 cout<<endl;
}
void sort_values (int value[], int maxval)
{
   int i, j, temp, flag;
   for(i=maxval-1; i>0; i--)
   {
     flag = 1;
     for(j=0; i>j; j++)
     {
       if(value[j]>value[j+1])
       {
         flag = 0;
         temp = value[j];
         value[j] = value[j+1];
         value[j+1] = temp;
       }
     }
     if(flag)
     break;
   }
}
void search_values (int value[])
{
 int check;
    cout << endl <<"Please enter the value you want to search for: ";
 cin >> check;
    for (int i=0; i<MAX; i++)
 {
  if (value[i] == check)
  {
   cout << "The value you searched for found in position #" << i+1 << endl;
  }
 }
}

I come up with the following code while working on this project but I couldn't figure out what I did wrong.

#include <iostream.h>
#include "p6.h"
project::project()
{
value[15];
}
int project::get_value()
{
return value[15];
}
void project::sort_values(int value[])
{
int i, j, temp, flag;
int maxval = 15;
for(i=maxval-1; i>0; i--)
{
flag = 1;
for(j=0; i>j; j++)
{
if(value[j]>value[j+1])
{
flag = 0;
temp = value[j];
value[j] = value[j+1];
value[j+1] = temp;
}
}
if(flag)
break;
}
}
void project::search_values(int value[])
{
int check;
cout << "Please enter the value you want to search for: ";
cin >> check;
for (int i=0; i<15; i++)
{
if (value[i] == check)
{
cout << "The value you searched for found in position #" << i+1 << endl;
}
}
}
******************************************
#ifndef P6_h
#define P6_h
class project
{
public:
project();
int get_value();
void sort_values(int value[]);
void search_values(int value[]);
private:
int value[15]; 
};
#endif
******************************************
 
#include <iostream.h>
#include "p6.h"
void get_values (int []);
void print_values (int []);
 
int main()
{ 
project myProject;
int count = 15;
int value[15]; 
get_values(value[]);
return 0;
}
void get_values(int values[])
{
for (int i=0; i<15; i++)
{
project.get_value (values[i]);
cout <<"Enter Values: ";
cin >> values[i];
}
}

I really appreciate if someone can point me a way out.

The declatrion of class is good.

class project
{
public:
   project();
   int get_value();
   void sort_values(int value[]);
   void search_values(int value[]);
private:
   int value[15]; 
};

So, why did declare "int value[15]" again in function main.

And what is this :

project::project()
{
value[15];
}

what does that do ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.