Search Results

Search found 14593 results on 584 pages for 'pat inside'.

Page 47/584 | < Previous Page | 43 44 45 46 47 48 49 50 51 52 53 54  | Next Page >

  • Accelerated C++, problem 5-6 (copying values from inside a vector to the front)

    - by Darel
    Hello, I'm working through the exercises in Accelerated C++ and I'm stuck on question 5-6. Here's the problem description: (somewhat abbreviated, I've removed extraneous info.) 5-6. Write the extract_fails function so that it copies the records for the passing students to the beginning of students, and then uses the resize function to remove the extra elements from the end of students. (students is a vector of student structures. student structures contain an individual student's name and grades.) More specifically, I'm having trouble getting the vector.insert function to properly copy the passing student structures to the start of the vector students. Here's the extract_fails function as I have it so far (note it doesn't resize the vector yet, as directed by the problem description; that should be trivial once I get past my current issue.) // Extract the students who failed from the "students" vector. void extract_fails(vector<Student_info>& students) { typedef vector<Student_info>::size_type str_sz; typedef vector<Student_info>::iterator iter; iter it = students.begin(); str_sz i = 0, count = 0; while (it != students.end()) { // fgrade tests wether or not the student failed if (!fgrade(*it)) { // if student passed, copy to front of vector students.insert(students.begin(), it, it); // tracks of the number of passing students(so we can properly resize the array) count++; } cout << it->name << endl; // output to verify that each student is iterated to it++; } } The code compiles and runs, but the students vector isn't adding any student structures to its front. My program's output displays that the students vector is unchanged. Here's my complete source code, followed by a sample input file (I redirect input from the console by typing " < grades" after the compiled program name at the command prompt.) #include <iostream> #include <string> #include <algorithm> // to get the declaration of `sort' #include <stdexcept> // to get the declaration of `domain_error' #include <vector> // to get the declaration of `vector' //driver program for grade partitioning examples using std::cin; using std::cout; using std::endl; using std::string; using std::domain_error; using std::sort; using std::vector; using std::max; using std::istream; struct Student_info { std::string name; double midterm, final; std::vector<double> homework; }; bool compare(const Student_info&, const Student_info&); std::istream& read(std::istream&, Student_info&); std::istream& read_hw(std::istream&, std::vector<double>&); double median(std::vector<double>); double grade(double, double, double); double grade(double, double, const std::vector<double>&); double grade(const Student_info&); bool fgrade(const Student_info&); void extract_fails(vector<Student_info>& v); int main() { vector<Student_info> vs; Student_info s; string::size_type maxlen = 0; while (read(cin, s)) { maxlen = max(maxlen, s.name.size()); vs.push_back(s); } sort(vs.begin(), vs.end(), compare); extract_fails(vs); // display the new, modified vector - it should be larger than // the input vector, due to some student structures being // added to the front of the vector. cout << "count: " << vs.size() << endl << endl; vector<Student_info>::iterator it = vs.begin(); while (it != vs.end()) cout << it++->name << endl; return 0; } // Extract the students who failed from the "students" vector. void extract_fails(vector<Student_info>& students) { typedef vector<Student_info>::size_type str_sz; typedef vector<Student_info>::iterator iter; iter it = students.begin(); str_sz i = 0, count = 0; while (it != students.end()) { // fgrade tests wether or not the student failed if (!fgrade(*it)) { // if student passed, copy to front of vector students.insert(students.begin(), it, it); // tracks of the number of passing students(so we can properly resize the array) count++; } cout << it->name << endl; // output to verify that each student is iterated to it++; } } bool compare(const Student_info& x, const Student_info& y) { return x.name < y.name; } istream& read(istream& is, Student_info& s) { // read and store the student's name and midterm and final exam grades is >> s.name >> s.midterm >> s.final; read_hw(is, s.homework); // read and store all the student's homework grades return is; } // read homework grades from an input stream into a `vector<double>' istream& read_hw(istream& in, vector<double>& hw) { if (in) { // get rid of previous contents hw.clear(); // read homework grades double x; while (in >> x) hw.push_back(x); // clear the stream so that input will work for the next student in.clear(); } return in; } // compute the median of a `vector<double>' // note that calling this function copies the entire argument `vector' double median(vector<double> vec) { typedef vector<double>::size_type vec_sz; vec_sz size = vec.size(); if (size == 0) throw domain_error("median of an empty vector"); sort(vec.begin(), vec.end()); vec_sz mid = size/2; return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid]; } // compute a student's overall grade from midterm and final exam grades and homework grade double grade(double midterm, double final, double homework) { return 0.2 * midterm + 0.4 * final + 0.4 * homework; } // compute a student's overall grade from midterm and final exam grades // and vector of homework grades. // this function does not copy its argument, because `median' does so for us. double grade(double midterm, double final, const vector<double>& hw) { if (hw.size() == 0) throw domain_error("student has done no homework"); return grade(midterm, final, median(hw)); } double grade(const Student_info& s) { return grade(s.midterm, s.final, s.homework); } // predicate to determine whether a student failed bool fgrade(const Student_info& s) { return grade(s) < 60; } Sample input file: Moo 100 100 100 100 100 100 100 100 Fail1 45 55 65 80 90 70 65 60 Moore 75 85 77 59 0 85 75 89 Norman 57 78 73 66 78 70 88 89 Olson 89 86 70 90 55 73 80 84 Peerson 47 70 82 73 50 87 73 71 Baker 67 72 73 40 0 78 55 70 Davis 77 70 82 65 70 77 83 81 Edwards 77 72 73 80 90 93 75 90 Fail2 55 55 65 50 55 60 65 60 Thanks to anyone who takes the time to look at this!

    Read the article

  • How to print a var inside a script

    - by Pollux Khafra
    Alright I'm trying to use a jplayer script to trigger the player in my template. I need to pass a value to the "mp3" option but I don't get how I get $music to print. $(document).ready(function(){ $("#jquery_jplayer_1").jPlayer({ ready: function () { $(this).jPlayer("setMedia", { var music = $(".album-playlist li").first().find("input").val(); mp3: $music, }).jPlayer(""); }, swfPath: "http://mysite.com/wp-content/themes/beta/libs", supplied: "mp3" }); });

    Read the article

  • XHTML Validation issue trying to render '&' character inside an ASP.Net control

    - by Micah
    Ok, the description is kind of funky, but here's my problem: <asp:ListItem Value="0">All Leads <i>(include Archive & Trash)</i></asp:ListItem> <asp:ListItem Value="0">All Leads <i>(include Archive &amp; Trash)</i></asp:ListItem> <asp:ListItem Value="0" Text="All Leads <i>(include Archive & Trash)</i>" /> <asp:ListItem Value="0" Text="All Leads <i>(include Archive &amp; Trash)</i>" /> All three versions render the following html All Leads <i>(include Archive & Trash)</i> This of course fails XHTML validation. It needs to render the html like this: All Leads <i>(include Archive &amp; Trash)</i> How can I fix this? Thanks.

    Read the article

  • how do I put a variable inside an attribute for an href tag

    - by Ido
    Hi I'm new to scripting Trying to change the css acording to a url variable, using jqURL plugin. for some reason this does not work for me: $(function(){ var n= $.jqURL.qs(); alert(n) $("link[rel=stylesheet]").attr({href : 'n + ".css"'}); }); the alert is there for debug, and works well, so it is a matter of how i put the var in the attribute. this, for example, works fine: if(n == 'red') { $("link[rel=stylesheet]").attr({href : "red.css"});} help please

    Read the article

  • How to make prevent public key inside jar to be saved using Java code

    - by Abhijith V R
    After signing a jar , we can retrieve the public keys from jar using Certificate[] cert = jarentry.getCertificates(); Once certificate is extracted we can save this to a new keystore as trusted cert. Once this is done , then second user can sign any jar using this certificate , isn't ? I want to distribute content as jars , contents will contain properties files for a application init. I want to make sure that an user is not capable to rebuilding the property files using the certificate he extracted from jarentry. In the code which reads the jar contents i am checking that jar is signed with my certificate only and also checking that jar is not tampered with . But the issue came to my mind that if i am able to extract the cerificate from jar then why don;t a third guy ? Can any one help me in this............

    Read the article

  • FindControl() from UserControl inside a for loop

    - by Kyle
    I'm creating a usercontrol that will have a series of LinkButtons. I've declared all of my link buttons at the top of my class LinkButton LB1 = new LinkButton(); LinkButton LB2 = new LinkButton(); //... LinkButton LB9 = new LinkButton(); now I'd like to be able to create a loop to access all of those link buttons so I don't have to write them all out every time. I tried something like this within my overridden CreateChildControls() method: for (int i = 1; i < 10; i++) { LinkButton lb = (LinkButton)FindControl("LB" + i.ToString()); lb.Text = i.ToString() + "-Button"; } I keep getting an exception saying that lb.Text... is not set to an instance of an object. I also tried giving all of my LB1, LB2 etc valid Ids. ie: LB1.ID = "LB1"; still not dice. how can I do this?

    Read the article

  • Include Jquery inside GreaseMonkey script under Google Chrome

    - by Alekc
    As maybe some of you know google chrome has put some severe limitation on greasemonkey scripts. Chromium does not support @require, @resource, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue. And without require, I can't find a way to include jquery library in Greasemonkey script under google chrome. Does anybody have some advice for the matter? Thanks in advance.

    Read the article

  • C: Cannot declare pointer inside if statement

    - by echedey lorenzo
    Hi, I have a pointer which points to a function. I would like to: if (mode == 0) { const unsigned char *packet = read_serial_packet(src, &len); } else { const unsigned char *packet = read_network_packet(fd, &len); } But I cannot do it because my compiler complains when I first use the pointer later in the code. error: 'packet' undeclared (first use in this function) This is strange. It worked without the if statement, but now I need my program to be able to get data from different sources. Isn't it possible to do this? I think so. If it isn't, is there any other simple way to get what I am trying? Thanks a lot.

    Read the article

  • Doctrine2 use of criteria inside the entity class

    - by Piotr Kowalczuk
    They try to write a method whose task would be to return only selected elements of the collection of items associated with a particular entity. /** * @ORM\OneToMany(targetEntity="PlayerStats", mappedBy="summoner") * @ORM\OrderBy({"player_stat_summary_type" = "ASC"}) */ protected $player_stats; public function getPlayerStatsBySummaryType($summary_type) { if ($this->player_stats->count() != 0) { $criteria = Criteria::create() ->where(Criteria::expr()->eq("player_stat_summary_type", $summary_type)); return $this->player_stats->matching($criteria)->first(); } return null; } but i get error: PHP Fatal error: Cannot access protected property Ranking\CoreBundle\Entity\PlayerStats::$player_stat_summary_type in /Users/piotrkowalczuk/Sites/lolranking/vendor/doctrine/common/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php on line 53 any idea how to fix this?

    Read the article

  • Using set in Python inside a loop

    - by user210481
    I have the following list in Python: [[1, 2], [3, 4], [4, 6], [2, 7], [3, 9]] I want to group them into [[1,2,7],[3,4,6,7]] My code to do this looks like this: l=[[1, 2], [3, 4], [4, 6], [2, 7], [3, 9]] lf=[] for li in l: for lfi in lf: if lfi.intersection(set(li)): lfi=lfi.union(set(li)) break else: lf.append(set(li)) lf is my final list. I do a loop over l and lf and when I find an intersection between an element from l and another from lf, I would like to merge them (union) But I can't figure out why this is not working. The first to elements of the list l are being inserted with the append command, but the union is not working. My final list lf looks like [set([1, 2]), set([3, 4])] It seems to be something pretty basic, but I'm not familiar with sets. I appreciate any help Thanks

    Read the article

  • How VerticalOffset changes when Scrollable height changes while having list inside a list

    - by Prakash
    I am making a WP7 app which has a Listbox of UserControls. Each UserControl has an ItemsControl and Button(for getting more results). On click of the button the ItemsControl items will be increased by 5 or 10. Now on clicking on the GetMore button of any of the usercontrols except the first or last, there will be an increase in Scrollable height(Total height of the listbox) of the ListBox but the VerticalOffset(position of scrollbar from top) of the ListBox remains same. Now the problem I am facing is that the Vertical Offset is not absolute but relative to Scrollable Height. So the content being viewed till then will be changed basing on the new value of ScollableHeight. I want to know the relation between them, so that I can do some math and set the VerticalOffset value. I have added some dependency properties on VerticalOffset and ScrollableHeight through which I can get the events when any of them is changed. Also trying to use them to readjust the VerticalOffset. Any suggestions or corrections are highly appreciated.

    Read the article

  • bash script variable inside variable

    - by user316100
    x=1 c1=string1 c2=string2 c3=string3 echo $c1 string1 I'd like to have the output be string1 by using something like: echo $(c($x)) So later in the script I can increment the value of x and have it output string1, then string2 and string3. Can anyone point me in the right direction?

    Read the article

  • PHP Fatal error, trying to request method inside model multiple times

    - by Tom
    The error message [23-Mar-2010 08:36:16] PHP Fatal error: Cannot redeclare humanize() (previously declared in /Users/tmclssns/Sites/nadar/nadar/trunk/webapp/application/filer/models/Filer/Aggregate.php:133) in /Users/tmclssns/Sites/nadar/nadar/trunk/webapp/application/filer/models/Filer/Aggregate.php on line 133 I have a "Filer" model which contains several methods to generate graphs. Each method in there related to generating graphs has the suffix "Graph" in the method name. As we have some performance issues, I try to render the graphs in advance (using cron) instead of rendering them on each request. The code below is what I came up with: public function generategraphsAction() { $this->_helper->viewRenderer->setNoRender(); $config = Zend_Registry::get('config'); $id = $this->_getParam('filerid'); $filer = new Filer($id); $filer_methods = get_class_methods($filer); foreach ($filer_methods as $filer_method) { if (preg_match('/^(.*)Graph$/i', $filer_method, $matches)) { $path = $config->imaging_caching_dir . "/$id/{$matches[1]}.png"; $filer->$matches[0]($path); } } // var_dump(get_class_methods($filer)); die; } The result from the var_dump(), when uncommented, is: array 0 => string '__construct' (length=11) 1 => string 'find_by_name' (length=12) 2 => string 'getPartner' (length=10) 3 => string 'getSlots' (length=8) 4 => string 'getGroups' (length=9) 5 => string 'grouplist' (length=9) 6 => string 'getAggregates' (length=13) 7 => string 'getVolumes' (length=10) 8 => string 'getAggregateVolumes' (length=19) 9 => string 'getShelves' (length=10) 10 => string 'getAutoSupportHistory' (length=21) 11 => string 'getAutoSupportMail' (length=18) 12 => string 'getOrphans' (length=10) 13 => string 'getAll' (length=6) 14 => string 'getDiskRevOverview' (length=18) 15 => string 'getDiskTypeOverview' (length=19) 16 => string 'getDiskTypeSizeFunctionOverview' (length=31) 17 => string 'getLicenses' (length=11) 18 => string 'removeGroup' (length=11) 19 => string 'addGroup' (length=8) 20 => string 'hasGroup' (length=8) 21 => string 'aggdefaultGraph' (length=15) 22 => string 'aggbarGraph' (length=11) 23 => string 'voldefaultGraph' (length=15) 24 => string 'volbarGraph' (length=11) 25 => string 'replicationGraph' (length=16) 26 => string 'getReplicationData' (length=18) 27 => string 'humanize' (length=8) 28 => string 'getFiler' (length=8) 29 => string 'getOptions' (length=10) 30 => string 'getCifsInfo' (length=11) 31 => string 'getCifsStats' (length=12) 32 => string '__get' (length=5) 33 => string 'tr' (length=2) 34 => string 'trs' (length=3) 35 => string 'fieldList' (length=9) The generategraphsAction() method finds the 'Graph' methods correctly: array 0 => string 'aggdefaultGraph' (length=15) 1 => string 'aggdefault' (length=10) array 0 => string 'aggbarGraph' (length=11) 1 => string 'aggbar' (length=6) array 0 => string 'voldefaultGraph' (length=15) 1 => string 'voldefault' (length=10) array 0 => string 'volbarGraph' (length=11) 1 => string 'volbar' (length=6) array 0 => string 'replicationGraph' (length=16) 1 => string 'replication' (length=11) However when the first graph is generated, it generates the above listed PHP fatal error. Anyone can come up with a solution to this? I tried to pass by reference or switch a few things around (like re declare the Filer model, $current_filer = new Filer($id); and unset() it again after the request, but resulted in the same error) without much success. The referenced method "humanize" isn't used for anything I'm doing at the moment, but belongs to the Model because it's used in several other places. Of course, removing the method is not really an option right now, and the model contains several other methods as well so I assume if I just move the humanize method around, it will generate an error on the next one. For reference, the humanize() method: public function humanize ($kbytes, $unit = null) { // KiloByte, Megabyte, GigaByte, TeraByte, PetaByte, ExaByte, ZettaByte, YottaByte $units = array('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if (null !== $units) { $i = array_search(substr($unit, -2), $units); if (! $i) { $i = floor((strlen($kbytes) - 1) / 3); } } else { $i = floor((strlen($kbytes) - 1) / 3); } $newSize = round($kbytes / pow(1024, $i), 2); return $newSize . $units[$i]; } Thanks in advance for the help offered.

    Read the article

  • How do I name an array key with a key inside the array

    - by Confused
    I have some data, yes, data. This data came from a MySQL query and it will always contain 4 items, always. I want to cache that data in an array table for use later within a web page but I want to keep the keys from the query and separate out each grouping within a multidimensional array. However to save time iterating through the array each time I want to find a given group of data, I want to call the keys of the first array the same as the ID key which is always the first key within each four items. At the minute I'm using this code: function mysql_fetch_full_result_array($result) { $table_result=array(); $r=0; while($row = mysql_fetch_assoc($result)){ $arr_row=array(); $c=0; while ($c < mysql_num_fields($result)) { $col = mysql_fetch_field($result, $c); $arr_row[$col -> name] = $row[$col -> name]; $c++; } $table_result[$r] = $arr_row; $r++; } return $table_result; } I'm currently testing this using 3 unique users, so I'm getting three rows back from the query and the data from this function ends up in the format: [0]=> . . [id] => 1 . . [name] => random name . . [tel] => random tel . . [post] => post code data [1]=> . . [id] => 34 . . [name] => random name . . [tel] => random tel . . [post] => post code data [2]=> . . [id] => 56 . . [name] => random name . . [tel] => random tel . . [post] => post code data So how do I alter the code to instead of the keys [0], [1], [2] give me the output: [1]=> . . [id] => 1 . . [name] => random name . . [tel] => random tel . . [post] => post code data [34]=> . . [id] => 34 . . [name] => random name . . [tel] => random tel . . [post] => post code data [56]=> . . [id] => 56 . . [name] => random name . . [tel] => random tel . . [post] => post code data I don't mind if the main array keys are strings of numbers rather than numbers but I'm a bit stuck, I tried changing the $table_result[$r] = $arr_row; part to read $table_result[$result['id']] = $arr_row; but that just outputs an array of one person. I know I need another loop but I'm struggling to work out how to write it.

    Read the article

  • Google Chrome extension: Use Javascript inside webkit notifications?

    - by Arnaud Leymet
    I have been following the Google Chrome Extensions Developer's guide and have been able so far to create an extension with a browser action without popup that would trigger a webkit notification in HTML format. Fact is that this HTML file contains action buttons, links and javascript, but none of them seems to respond. Is this a by-design behavior or is there a way for embedding javascript/links/buttons in these webkit notifications?

    Read the article

  • Switch/case without break inside DllMain

    - by Sherwood Hu
    I have a Dllmain that allocates Thread local storage when a thread attaches to this DLL. Code as below: BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { LPVOID lpvData; BOOL fIgnore; switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: onProcessAttachDLL(); // Allocate a TLS index. if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE; // how can it jump to next case??? case DLL_THREAD_ATTACH: // Initialize the TLS index for this thread. lpvData = (LPVOID) LocalAlloc(LPTR, MAX_BUFFER_SIZE); if (lpvData != NULL) fIgnore = TlsSetValue(dwTlsIndex, lpvData); break; ... } I know that for the main thread, the DLL_THREAD_ATTACH is not entered, as per Microsoft Documentation. However, the above code worked. I am using VC2005. When I entered the debugger, I saw that after it entered DLL_THREAD_ATTACH case when ul_reason_for_call = 1! How can that happen? If I add `break' at the end of DLL_PROCESS_ATTACH block, the DLL failed to work. How can this happen?

    Read the article

  • How to get url request parameter from inside LIferay/IceFaces/JSF portlet backing bean

    - by Negatizmo
    Is posible for a portlet to read a request parameter of its surrounding page? E.g. the URL of the page the portlet resides in is http://example.com/mygroup/mypage?foo=bar Is it possible to read the "foo" parameter from a portlet that is on that page? Portlet Container is Liferay 6.0.5. P.S. I have already tried: com.liferay.portal.util.PortalUtil.getOriginalServletRequest(com.liferay.portal.util.PortalUtil.getHttpServletRequest((javax.portlet.PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest())).getParameter("foo") but I always get null for productId Thanks!

    Read the article

  • can we use join inside join in mysql?

    - by I Like PHP
    i have 3 tables structure is below tbl_login login_id | login_name 1 | keshav tbl_role role_id | login_id( refer to tbl_login.login_id) 1 | 1 tbl_stuff stuff_id | role_id( refer to tbl_role.role_id) 1 | 1 i need data in follow format stuff_id | login_name 1 | keshav how to use JOIN to retrive the above data in mysql?

    Read the article

  • Flash AS 3 Loader OnComplete Inside a Loop

    - by meengla
    Hi, I think I posted my question as an answer elsewhere (http://stackoverflow.com/questions/2338317/how-to-get-associated-urlrequest-from-event-complete-fired-by-urlloader/2776515#2776515) . Sorry. Here is my question again: Hi, How can I make your function work for loader object in a loop? Thanks! Meengla Here is my existing (rough) code; I always get the mylabel from the last element of the array. var _loader = new Loader(); for (j = 0; j < 5; j++) { //mylabel variable is correct setup in the loop _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void { doneLoad(e, mylabel); }); _loader.load(new URLRequest(encodeURI(recAC[j].url))); }//for loop

    Read the article

< Previous Page | 43 44 45 46 47 48 49 50 51 52 53 54  | Next Page >