Solved

# Beginner - Class help, code example included.

Posted on 2003-03-06
Medium Priority
299 Views
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 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;
}

{
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.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.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;
}

Ben
0
Question by:bjohnsoncoder
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 1

Expert Comment

ID: 8088553
Can you point out exactly what the problem with it is, and then we would love to help.
(unless you did and I missed it)

Thanks,
Cassandra.
0

Author Comment

ID: 8094517
The code/program doesnt compile correctly and I'm not sure if i am doing the coding for the class right.  Thanks

Ben
0

Accepted Solution

killer455 earned 200 total points
ID: 8100289
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
###### Suggested Courses
Course of the Month12 days, 4 hours left to enroll