Im a noob programmer currently making a small family database using cpp but i have trouble deleting a family from the the list...
My list looks something like this
start-of-family 1
jim
joe
bob
sam
end-of-family 1
start-of-family 2
rob
max
end-of-family 2
start-of-family 3
sue
tom
kim
end-of-family 3
If i wanted to delete family 1, I would locate start-of-family 1 and end-of-family 1. Then run a loop but how do i locate it if the user only inputs an int to represent a family number. Also how do i make the succeeding family numbers deduct by 1 so that family 2 will be 1 and family 3 will be 2.
thanks a lot
If I were doing this problem I would start by making each family into a vector of names. Then, I would create a vector containing those family vectors.
The result would look something like:
{
<(jim), (joe), (bob), (sam) >
<(rob), (max) >
<(sue), (tom), (kim) >
}
Then, if the user wants to delete one of the families, you can use vector.remove(n) where n is the index of the family to be removed.
This sounds like a school or text book assignment. Have you gotten to vectors yet? Where are the names coming from? Are you hard coding them into the list? Or reading them from a .txt file? What kind of list structure are you storing them in right now?
i realized that clearing the db and updating it with what ive got is way easier than modifying the db and updating my program
Related
I am learning to code and found interesting task, but i do not know where to start in solving it. So i have a file with some titles and comments which need to be placed under the right title. So the first line of the input contains a number N which determines the quantity of the titles. Each row starts with a unique article id (integer), followed by the title in quotation marks. After there is no more titles, comments are given. At the beginning there is Title ID and comment (one word), but comments may recur for the same ID. so here is a structure of a file:
<N>
<ID1> "<Title1>"
...
<IDN> "<TitleN>"
<ID1> <Comment1>
...
<IDK> <CommentK>
Now in the output file each Title has two lines - first for the title and second one for comments. Titles must be in ascending order. And comments should be in reverse order (newest comments in the beginning) Structure of output file:
<Title1>
<Comment11> ... < CommentK1>
...
<TitleN>
<Comment1N> ... < CommentLN>
Example:
input:
3
1 "This is some title"
3 "Another title"
2 "And one more"
1 COmment
1 Another
3 Great
2 Awesome
3 Lucky
2 Stanley
output
This is some title
Another COmment
And one more
Stanley Awesome
Another Title
Lucky Great
I do not now where to begin with.. Should I use arrays to save the data in memory and then try to sort it in the right pattern?Or is it better to load the text file into a data structure; in this case a linked list? Maybe someone can guide me in the right direction how to accomplish this task. (I do not ask to code it for me, just guide me or give some algorithm, it would be highly appreciated). Thanks!
I assume you know how to read a file in C++, if not, please look at it, for example on this tutorial.
For the sorting part, you could use a STL container
to store the ids. I would recommend a map with the id as key and the string as value.
The advantage of the map, is that it's already sorted (ascending order).
If you use another container, you should look at the sorting algorithms if you want to understand how they work. For instance bubble sort, selection sort, quick sort or merge sort for the main ones.
However if you want to sort without any implementation, have a look at this.
This doesn't provide you a specific answer for your problem, but it can help you start.
[UPDATE]
I didn't read correctly and I haven't seen that multiple lines could have the same ID. A map would not necessarily be the most suitable container.
I'm facing this problem in programming it says that if jack knows john and john know mark, then jack should know mark
the input is like this
1 - 3
3 - 4
1 - 4
1 knows 3 and 3 knows 4 so 1 knows 4, the answer is yes otherwise if the third line isn't there the answer is false because there's no connection between these three persons.
How can I implement this in c++ to make a connection between these three (on large inputs).
It is pretty simple if you know c++;
you just have to make a friend List of every person, then you can make a function
bool isFriend(person1,person2)
Which will return true if person1 and person2 knows each other, then you can make relationship of 3rd person if he knows any of them he'll know both of them as your requirement.
To make friend list you can use jagged array data structure and adjacency list with link list;
Ok, I just added a new feature to my student manager program (a console program written in c++) , it is a console application and my program print dates on which particular student is absent in a list format
by saying list format i mean 1 date on 1 line
this is how output looks like for student who is absent 5 times
1. 04/05/2016,Monday
2. 05/05/2016/Tuesday
3. 06/05/2016/Wednesday
(Assume dates are correct)
now since these are only 3 records that are printed on the screen, a user would not require scrolling down,
but in a case of 300 dates , it prints all dates but when i scroll up I'm not able to reach back to 1st date, for example, I'm only able to see last 147 Records only
and I'm not able to scroll my console window to 1st record.
I know many other ways to solve this problem (like displaying 10 records or 100 records at a time) but I want to know how can i solve this particular problem
please give answer considering me as a beginner. :)
Thank You.
(as far as code is concerned, i can assure you its nothing special, just a while loop that keeps on printing dates until certain terminating condition is met )
I am running a NetLogo model in BehaviorSpace each time varying number of runs. I have turtle-breed pigs, and they accumulate a table with patch-types as keys and number of visits to each patch-type as values.
In the end I calculate a list of mean number of visits from all pigs. The list has the same length as long as the original table has the same number of keys (number of patch-types). I would like to export this mean number of visits to each patch-type with BehaviorSpace.
Perhaps I could write a separate csv file (tried - creates many files, so lots of work later on putting them together). But I would rather have everything in the same file output after a run.
I could make a global variable for each patch-type but this seems crude and wrong. Especially if I upload a different patch configuration.
I tried just exporting the list, but then in Excel I see it with brackets e.g. [49 0 31.5 76 7 0].
So my question Q1: is there a proper way to export a list of values so that in BehaviorSpace table output csv there is a column for each value?
Q2: Or perhaps there is an example of how to output a single csv that looks exactly as I want it from BehaviorSpace?
PS: In my case the patch types are costs. And I might change those in the future and rerun everything. Ideally I would like to have as output: a graph of costs vs frequency of visits.
Thanks
If the lists are a fixed length that doesn't vary from run to run, you can get the items into separate columns by using one metric for each item. So in your BehaviorSpace experiment definition, instead of putting mylist, put item 0 mylist and item 1 mylist and so on.
If the lists aren't always the same length, you're out of luck. BehaviorSpace isn't flexible that way. You would have to write a separate program (in the programming language of your choice, perhaps NetLogo itself, perhaps an Excel macro, perhaps something else) to postprocess the BehaviorSpace output and make it look how you want.
I have a sheet that has become complex, it has a lot of filters and I need to populate a table with data. I am counting how many times a month we run a product. If we run it once a day, or more, I want to only count that as one.
Date Product Grizzly
1/1 2.5 open
1/1 1.5 closed
1/1 2.5 closed
1/1 2.5 open
Something a little more elaborate than this, but what I need is to count this as one day of 2.5 grizzly closed, instead of two.
Any help? I feel like there is something simple I am missing but cant put my thumb on it and I have spent well over 15 hours working on this.
As found on the following link:
Link to Answer
Try using the DCOUNTA function within Excel.
Although I'm also sure that you could use a pivot chart to provide the same outcome.
EDIT:
I am assuming you are starting with data like the following:
I then created the following table which you can extend to comply with you total data value. For example, you can add extra dates and products.:
The table is populated using a COUNTIFS function.
=COUNTIFS("DateRange",DateCriteria, "ProductRange", ProductCriteria, "GrizzlyRange", GrizzlyCriteria)
So in my table the formula looks like this but the cell references will obviously changes according to your spreadsheet (I used absolute references to make it easier to use the fill handle to copy the formula down:
=COUNTIFS($A:$A,$E4,$B:$B,$F$3,$C:$C,$F$2)
I next nestled this formula in to an IF statement and applied a conditional formatting to end up with the following:
So the formula for each of the cells is now:
=IF("OriginalFormula),"Yes","No")
Example of my 01/01/2015, 1.5 open value:
=IF(COUNTIFS($A:$A,$E4,$B:$B,$F$3,$C:$C,$F$2),"Yes","No")
BUT - You can change the "Yes" and "No" to "1" and "0" if you want to stick with numerical values.