chrinkus / stroustrup-ppp Goto Github PK
View Code? Open in Web Editor NEWChapter work from Bjarne Stroustrup's Programming Principles and Practice text
License: MIT License
Chapter work from Bjarne Stroustrup's Programming Principles and Practice text
License: MIT License
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
Hi Chrinkus,
I've recently been working through this textbook and it's been super useful to have something to check my answers against. Thanks so much for posting all of this!
I think the big error in Exercise 4 Chapter 20 might be that there's no check as to whether the start iterator actually comes before the end iterator. If someone accidentally entered them in reverse into the function's arguments, it would lead to an infinite loop.
template<typename Iter>
Iter high(Iter first, Iter last) {
if (first > last) throw; //Could lead to infinite iterations
Iter high = first;
for (Iter p = first; p != last; ++p) {
if (*high < *p) { high = p; }
}
return high;
}
Not sure what it might be otherwise...
Cheers,
Josh
Exercises 7 and 8 build on 6 and were omitted on my first pass. Admittedly, they are a bit excessive but shouldn't pose too much of a problem to complete.
Exercises 12 and 14 were omitted but should not have been.
Also, exercise 1 is a further enhancement of the calculator from chapters 6 & 7. Update it when 6 and 7 are completed.
It is tempting to refactor most of this chapter's work but the exercises were completed and the painful-to-take-credit-for code will remain. The Chrono implementation can be fixed up though as it comes from the textbook and I hadn't attempted ex 11 & 12 which are enhancements.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
I'm learning C++ and like to use your github to check my work/improve. Overall it is very well done and thank you for sharing!
The issue in your bin_lst() function is that it will not check against the exactly middle or exactly last element in a container.
So if you have a list{1,2,3,4,5,6,7,8,9,10}; , the function will not find 5 or 10. If you add the following code, it should work better. Your bin_lst() function will also work directly with vector as well.
I'm new to Github, so sorry if my formatting is subpar. If you add :
if (half == 0 && *(--last) == val)
return last;
just after the loop at line 60, it will fix your code. It's the best I can manage, so I'm not sure if there's a better solution.
`template<typename Iter, typename T>
Iter bin_lst(Iter first, Iter last, const T& val)
{
auto half = std::distance(first, last);
auto end = last;
while (first != last && half != 0) {
if (*first == val) return first;
half /= 2;
auto mid = first;
std::advance(mid, half);
*mid > val
? std::advance(last, -half)
: std::advance(first, half);
}
//loop exits when half = 0
//but last value wasn't checked
if (half == 0 && *(--last) == val)
return last;
return end;
}`
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
I'm moving on from Chapter 7 as the remaining exercises are worthwhile but I'm wanting to get into Chapter 8 ASAP. Come back and finish up the simple calculator at a later time.
Add a grammar.md
file to dissect the provided concept by the chapter. Come up with a few example implementations.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
I was doing the calculator problem in chapter 8 (Exercise 1) when I ran into this problem. The problem is in the definition of the function Token_stream::get()
. I used Xcode for this exercise.
The error showed by Xcode is Non-void function does not return a value in all control paths
. It does not provide anything else. From what I understand, there could be a scenario when the get()
function won't go through any of the switch-cases which could cause problems. Although I haven't been able to find the solution to this problem.
I would appreciate if this issue is addressed.
P.S. I used the same code from the solutions in this project. So I am sure that there are no syntax errors.
Change chapter 2's file names and notes.md layout to reflect current conventions.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
It also seemed quite strange to me that we're asked to implement a binary search for a List
in this question. It definitely feels like it should come with a warning as it seems like a fairly rare case for there to be a comparison operation which would be more expensive than repeatedly traversing through a bi-directional iterator!
I hope you don't mind me asking whether you've had many encounters where this is the case since working through these exercises?
According to an article I read 'binary search through a linked list' is almost a bit of an geeky joke for developers in the know!
On the whole, I'm sure you'd agree 21 was a pretty dazzling chapter! Definitely brought a lot of things together for me.
As a side note, I'm really interested to hear about your experiences since working through this book, where programming has lead you and what your aspirations are!
I started studying C++ around 6 months ago but I've been learning computer languages for several years now and I'm working towards becoming a video games developer.
I haven't actually had much contact with other developers and have never worked in any sort of software development position so any insight you could offer would be really appreciated!
If you don't mind sharing some of your experiences perhaps it'd be better via email? You can reach me at [email protected]
Chapter 6's 'try this's focus on using intermediate versions of the calculator. Implement clearer examples of them with correct file names. Consider a better way to execute some of the added calculator features found in the exercises rather than having several different calculators with different features.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
Most of chapter 3 follows the general naming conventions with the exception of the 'try this's. Review the code for completion.
Continue work with standardizing repo file names. If any exercises need to be completed or extra work is required, open a specific issue.
Hi .
While i was doing chapter 4 number guesser exercise i got stuck and check your answer to get and idea about structure.While i was controlling if your guesser was right i found its mostly right but it didnt guess 50.
I fix problem later but wanted to let you know about it .Thanks for your work.
/* Write a program to play a numbers guessing game.
The user thinks of a number between 1 and 100 and your program asks questions to figure out what the number is (e.g., βIs the number you are thinking of less than 50?β).
Your program should be able to identify the number after asking no more than seven questions.
Hint: Use the < and <= operators and the if-else construct. */
#include
#include
#include
#include
#include
#include <stdio.h>
using namespace std;
int main() {
double base{ 50 };
double fuck{ 50 };
char choice{};
cout << "is your number bigger than " << fuck;
cout << "\n Y/N\n";
for (int i{ 0 };i <=5;i++) {
cin >> choice;
fuck = fuck / 2;
if (base <= 1)
base = 1;
if (choice == 'y' || choice == 'Y') {
base += fuck;
cout <<"is your number bigger than "<<base<<" Y/N\n";
}
if (choice == 'n' || choice == 'N') {
base -= fuck;
cout<< "is your number bigger than " << base << " Y/N\n";
}
}
cout << "is your number even? Y/N";
int x=base;
char en{};
cin >> en;
if (en == 'y' || en == 'Y')
cout << "Your number is " << x + 1;
else
cout << "your number is " << x;
}
Exercises 7 and 10 add enhancements to the calculator from chapters 6 & 7. Complete these when all of the preceding chapters have had their enhancements bolted on to the calculator.
I came up with mathematical patterns such as factorials and fibonacci sequences for this one (which segues quite nicely into the postscript for that chapter...).
Whether or not those sorts of patterns can actually be expressed as regex is beyond me.
I did see a couple of blog posts, particularly from a guy under the name 'Polygenelubricants', which seemingly managed to express those sorts of patterns with regex. Even so, it really doesn't seem to be the most practical way to express them.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.