User Tools

Site Tools


journal:fall2019:mgardne8:week11

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
journal:fall2019:mgardne8:week11 [2019/10/31 06:24]
127.0.0.1 external edit
journal:fall2019:mgardne8:week11 [2019/11/07 00:19] (current)
mgardne8 [NOVEMBER 6, 2019]
Line 1: Line 1:
 =====data week11===== =====data week11=====
 ---- ----
-====MONTH DayYEAR====+====NOVEMBER 62019==== 
 + 
 +Something new I learned about this week within C++; 
 + 
 +*Range-based for Statement* 
 + 
 +Microsoft c++ documentation describes them as follows: 
 + 
 +Use the range-based for statement to construct loops that must execute through a "range", which is defined as anything that you can iterate through—for example, std::vector, or any other C++ Standard Library sequence whose range is defined by a begin() and end(). 
 + 
 +They are used in the following format: 
 + 
 +for ( for-range-declaration : expression ) 
 +statement 
 + 
 +I am glad to find that there exists something like this within C++ as it is a lot like pythons 'for x in y' and this is something that I love, and made me sad to live without. 
 + 
 +I used this recently in an assignment for Han's c++ class in  conjunction with vectors as follows: 
 + 
 +        for( vector<int> v : vect ) 
 +        { 
 +                total = accumulate( v.begin(), v.end(), total ); 
 +                count = count + v.size(); 
 +        } 
 + 
 +This allowed me to iterate over all the objects within a vector of vectors that contain ints, summing them up and counting the number of elements. (To calculate an average). 
 + 
 +This has the added benefit of 'just working' even when all the vectors within the main vector vary in size. 
 + 
 +Additionally I nested these style of for loops to create a compact and efficient way of outputting the data for the project.  
 +        for( string name : names ) 
 +        { 
 +                cout   << endl << name << endl << "    Grades: "; 
 +                for( int grade : grades.at(i) ) 
 +                        cout   << grade << " "; 
 +                cout   << endl << "    Average: " << average(grades.at(i)); 
 +                cout   << endl << "    LetterG: " << get_let(avgs.at(i)) << endl; 
 +                i++; 
 +         }
  
-Filler text- your entry goes here; remove this line to receive full credit. 
  
journal/fall2019/mgardne8/week11.1572517461.txt.gz · Last modified: 2019/10/31 06:24 by 127.0.0.1