[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Beginner - Class help, code example included.

Asked by bjohnsoncoder in C++ Programming Language

I asked a previous questions concerning this program.  I have most of the code (i hope).  The problem is I am a beginner and to tell you the truth the following code is elementary and I just dont know that much about classes, so go easy on me :).

This program takes input (5 numbers) from the user and they are inserted into an array.  Then the array is sorted.  Then input is taken from an input file containing sets of numbers:

numbers1.txt:
1 2 4 6 3
21 43 56 34 45
23 34 3 45 5

A set (of 5 numbers, or one line) is taken in, inserted into a second array, sorted, and then compared to the numbers inserted by the user.  If they match, increment a counter.  Then take in another line of numbers, sort, compare, etc and so on till end of file.  

Well here is the code, (think of it as kind of a lottery program).

-------------------
LOTTERY.H
-------------------

#ifndef LOTTERY_H
#define LOTTERY_H

class Lottery
{
 public:
  Lottery();
  void addNumber(int arr[], int number);
  void SortList(int arr[]);
  bool CompareLists(winList[], numList[]);

 private:
  int count;
  int winner;
  int winnersList[5];
  int numbersList[5];
};

#endif

-----------------
LOTTERY.CPP
-----------------

#include "lottery.h"

Lottery::Lottery()
{
  count=0;
  winner=1;
}

void Lottery::AddNumber(int arr[], int number)
{
  arr[count++]=number;
  return 0;
}

void Lottery::SortList(int arr[])
{
  for (int i = 1, j; i<5; i++)
    {
      int tmp = array[i];
      for (j = i-1; j>=0 && array[j]>tmp; j--)
        {
          array[j+1] = array[j];
        }
      array[j+1] = tmp;
    }
}

bool Lottery::CompareLists(winList[], numList[])
{
  for(int position=0; position<5; i++)
    {
      if(winList[position]!=numList[position])
     {
       winner=0;
     }
    }
  return winner;
}

-----------------
LOTTERYCHECK.CPP
-----------------
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "lottery.h"
#include "lottery.cpp"

int main()
{
  int winPosition=0;
  int numPosition=0;
  Lottery list1, list2;
  int winnersList[5], winNum, number;
  int numbersList[5];

  cout << "Enter the winning numbers: ";
  while(winPosition<5)
    {
      cin >> winNum;
      list1.AddNumber(winnersList[], winNum);
    }

  list1.SortList(winnersList[]);

  ifstream fileInput;
  string inData;

  cout << "input file: ";
  cin >> inData;

  fileInput.open(inData.c_str());
  string lineOfNumbers;

  while(getline(fileInput, lineOfNumbers))
    {
      istringstream input(lineOfNumbers);
      while(input >> number)
     {
       list2.AddNumber(numbersList[], number);
     }

      list2.SortList(numbersList[])

     // right here i want to compare the two lists using the
     // compare method but am not sure how
     // if two lists match increment a counter

    }


  return 0;
}


Thanks for your help :(

Ben
 
Related Solutions
Keywords: Beginner - Class help, code example…
 
Loading Advertisement...
 
[+][-]03/07/03 06:44 AM, ID: 8088553Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/03 10:14 AM, ID: 8094517Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/09/03 07:02 PM, ID: 8100289Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Sign Up Now!
Solution Provided By: killer455
Participating Experts: 2
Solution Grade: C
 
 
Loading Advertisement...
20091021-EE-VQP-81