Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm practicing with classes and I'm given the task of creating employee management system. I'm given two .txt files. One (details.txt) has details of each employee with the following info: ID, name, DOB, SSN, department, and position. A sample of the file looks like such:
5 ali 6/24/1988 126-42-6989 support assistant
13 tim 2/10/1981 131-12-1034 logistics manager
The other .txt (timelog.txt) will contain a daily log of when employees clock in and clock out. The following format for this file is: ID, date, clock in time, and clock out time. Sample:
5 3/11 0800 1800
13 3/11 0830 1830
Firstly, I am to allow users to search up an employee by ID, name, department or position. Doing so will display all of the employees info (multiple employees if they have the same name, position or are from the same department) as well as show the total number of hours they have worked in the company.
Secondly, users are to be given another option to look up employee time logs by ID number. This will display the entire clock in/ clock out history of that employee as well as total hours worked each day.
I'm planning to read in the info from .txt files via ifstream and store them as an array of objects. I'm just wondering how many classes I should create. I'm thinking 2 classes- one for employee info (from details.txt) and one for time logs(timelogs.txt). Is there any other class I should create or should those 2 suffice?
Short answer: At least two.
Long answer: It depends on many things. Especially what part of code you can identify as potentially reusable.
If you asked for the highest possible amount of classes that could accomplish your task, I would think about a single class for:
Employee
EmployeeManager (Factory, Holder etc.) – creates, holds and deletes the Employee objects, provides search feature
DayWork – a row from timelog.txt, can calculate the amount of hours/minutes spent in work that day
WorkLog – a list of DayWork objects for one employee, can calculate the whole spent time
TextLineParser – encapsulation of std::ifstream
The right answer is most likely somewhere between. Keep in mind that C++ is a multi-paradigm language and you can perform some operations without having a class for them. Instead, they can be performed in a function or a set of functions in a C-like unit. That’s especially useful for one-time operations where the functions don’t share common data (potential properties).
Related
I have already programmed a football manager game some years ago with a lot functionality (Sent it to Gamestar for free publishing but was rejected because of copyrights).
I have one section in the game on that I am not really satisfied because I have no clue what would be the best fit to model it.
I have a vector of pairs for all days of one calendar year:
std::vector<std::pair<Competition*, TDate>> year_plan;
E.g. there can be following entries inside pointing to a Competion class instance and a date:
CHAMPIONS_LEAGUE_DRAW, 12.03.2022
CHAMPIONS_LEAGUE, 15.03.2022
FIRST_LEAGUE, 19.03.2022
SECOND_LEAGUE, 19.03.2022
--> As you can see, there can be several competitions at the same day!
The program logic is just processing the year_plan date by date and takes the action required on the specific competition on simulating results or simulating the draws. This perfectly works, but somehow it does not feel right this way.
For that reason I have two questions on that:
Would it not make more sense to have a one year Calendar class and instances for every Competion occurence in it? (One instance per day is not enough because of having soemtimes more than one competitions per day). This would also allow to store additional information in the instance like counter for the matchday, round etc.
The Competitions I currently have are LeagueCompetions, CupCompetitions, Draws. All these three competitions types have some parts in common but need also special class members and methods. Draw competitions need much less information to be stored. As I need to store the Competition in the Calendar vector / class, I need somehow one class forr all three competition types. Should I use here inheritance approach even I need a specialization of the classes in addition to the common parts?
Thanks in advance for any suggestions
Mauro
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I want to read orders from order.txt which is;
Chocolate Chip Cookies 1 2
Orange Jelly Candy 2 7
Chocolate ice cream 3 11
Cake Mix Cookies 1 10
And decide if there is enough product from stock.txt which is;
Name Type ItemCount Price
Chocolate Chip Cookies 1 4 600
Orange Jelly Candy 2 5 150
Cake Mix Cookies 1 12 180
Peanut Butter Chocolate Chip Cookies 1 3 120
Chocolate ice cream 3 2 240
Gummi bears 2 15 300
Raspberry Ripple 3 12 250
Alignment is given like that. What is the best way to do it? Is there anything to read from a file which I can store in a way like product name/ number/ price?
Thank you.
I don't understand what the second and third column signify, I assume one of them is order size.
There are many ways to do this and my method might not be the best in all cases but at least it should work in yours:
Read the stock.txt file, you can look at this example but it doesn't really matter what method you use. The important thing is to get the information as a variable into the program. Hopefully your text files uses a tab to separate the fields (this information is lost in the question).
Put the information you get into a std::map, call it orders, use the name as key and the ItemCount as value.
Now read the information in order.txt, use the key to look up the value in your orders.
Check that ItemCount is at least a large as the order size.
In a real world application you would use a Database to store the data of your stock and would write a class order which gets its values from the databas. However i dont think you want to have that much effort so here's a esier way:
Your stock data gets saved in a simple excel table and the order is a textfile
Order.txt:
Beer 1|Paint 5|Oil 3|.....
Use the | as markers to create substrings of the individual products in the order
Bsp. ProductName quantity id|ProductName2 quantity id2|....
As for the excel table you have to to a little research yourself but editing files with a filereader isn't that hard though.
Hope i can help
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to create a structure that contains fields for account numbers, balances, and interest rates and I am supposed to use an array to do so.
I need the output to display like this:
Account number X has a balance of X and an interest rate of X.
The end user is supposed to be able to enter their account number (and if it's already in the system an error message should occur) their balance and their interest rate.
I'm stuck! I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know).
____UPDATE___
First of all- I'm 4 weeks into my first programming class ever- The text asks me to complete the tasks I will share below. We have not learned about std:... & vectors yet. This chapter covered parallel arrays and structure objects. But the only thing I've learned about structure objects is this:
struct Part
{
int partNum;
double partPrice;
};
The rest of the above code just shows me how to enter in info as a programmer and not how to allow the user to enter in code.
You are developing a BankAccount structure for Parkville Bank. The structure contains
fields for the account number, the account balance, and the annual interest rate earned on
the account. Write a main()function in which you create an array of five BankAccount
objects. Prompt the user for values for all the fields in the five BankAccounts. Do not
allow two or more accounts to have the same account number. After all the objects have
been entered:
» Display all the data for all five accounts.
» Display the total balance in all five accounts and the average balance.
» After displaying the statistics, prompt the user for an account number and display the
data for the requested account, or display an appropriate message if no such account
number exists. Continue to prompt the user for account numbers until an appropriate
sentinel value is entered.
Based on this: "I don't know if I should create some sort of parallel array or some sort of dimensional array (two-dimensional, three-dimensional, I don't know)" it seems like you are completely confused about how this kind of data can be grouped. One of the many possible ways is:
struct Account {
std::string number;
double balance;
double interestRate;
};
representing a single element that can be used in some container holding accounts, e.g. :
std::vector<Account> accounts;
but since you mentioned the constraint: "I am supposed to use an array to do so", then unfortunately you'll have to use a C-style array:
Account accounts[N];
or in case you have no VLA support:
Account* accounts = new Account[N];
...
delete[] accounts;
Now get some good book and spend some time reading it before you continue writing codes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I've noticed twitter people search can come up with some weird results. Searching for match in screen_name twitter_name and bio is obvious, but they also do something different. I guess it has something to do with Triadic Closure but find its usage for search (instead of suggestions) weird. Wanted to hear your thoughts about this issue.
I think your question might be a little nonspecific, but here are my thoughts:
Suppose your search query was "Miley Cyrus", for instance. Now the top results will for sure include her real account, then fake ones, but then the results will get a little distorted.
I expect it ranks each account / person X in this manner (or something similar):
If person X follows accounts that has the search query in its bio / name, it has a higher rank than if that person didn't.
In our search, "Rock Mafia" is a good example; it doesn't have the term "Miley Cyrus" in its bio nor its name, but if you look at the people "Rock Mafia" is following, you'll find a lot of "similar" names / bios. Another ranking criteria would be this:
If person X has tweets that contains the search query in its content, it would also have a higher rank
A good example is the result "AnythingDisney" (#adljupdated), you can see that the 4th most recent tweet contains "Miley".
So basically the search prioritization looks like this:
Look in name / bio.
Need more results? Rank each person X by his followers and the people he follows, and by tweets that contain the query.
Need even more results? Look at "deeper" levels, rank each person X by the people being followed by the people X is following.
An so on, recursively.
I hope this helped in any manner!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a set of training data consisting of 20 multiple choice questions (A/B/C/D) answered by a hundred respondents. The answers are purely categorical and cannot be scaled to numerical values. 50 of these respondents were selected for free product trial. The selection process is not known. What interesting knowledge can be mined from this information?
The following is a list of what I have come up with so far-
A study of percentages (Example - Percentage of people who answered B on Qs.5 and got selected for free product trial)
Conditional probabilities (Example - What is the probability that a person will get selected for free product trial given that he answered B on Qs.5)
Naive Bayesian classifier (This can be used to predict whether a person will be selected or not for a given set of values for any subset of questions).
Can you think of any other interesting analysis or data-mining activities that can be performed?
The usual suspects like correlation can be eliminated as the response is not quantifiable/scoreable.
Is my approach correct?
It is kind of reverse engineering.
For each respondent, you have 20 answers and one label, which indicates whether this respondent gets the product trial or not.
You want to know which of the 20 questions are critical to give trial or not decision. I'd suggest you first build a decision tree model on the training data. And study the tree carefully to get some insights, e.g. the low level decision nodes contain most discriminant questions.
The answers can be made numeric for analysis purposes, example:
RespondentID IsSelected Q1AnsA Q1AnsB Q1AnsC Q1AnsD Q2AnsA...
12345 1 0 0 1 0 0
Use association analysis to see if there are patterns in the answers.
Q3AnsC + Q8AnsB -> IsSelected
Use classification (such as logistic regression or a decision tree) to model how users are selected.
Use clustering. Are there distinct groups of respondents? In what ways are they different? Use the "elbow" or scree method to determine the number of clusters.
Do you have other info about the respondents, such as demographics? Pivot table would be good in that case.
Is there missing data? Are there patterns in the way that people skipped questions?