Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ I need help debugging, this line std::vector v { 1, 2, 3, 4, 5 }; is causing the problem but i cant figure
C++ I need help debugging, this line "std::vector
1. #include#include int main() { // Print the numbers in v in reverse order. std::vector v { 1, 2, 3, 4, 5 }; for (std::size_t i = v.size(); i >= 0u; --i) std::cout << v[i] << ' '; return 0; }
2. I cant find the problem with this
#include// A fraction is like a rational number, but is primarily designed // to represent the ratio of two numbers, not the qotient. That is // to say, a fraction is an unreduced rational number. // // NOTE: This is just a stub of a class, used for the purpose of // testing. struct Fraction { // Initalize the raitonal to 0/1 (i.e.,, just 0). Fraction() : n(0), d(1) { } // Initilize the fracto to p/q. Fraction(int p, int q) : n(p), d(q) { } int n, d; }; // Returns true when a and b have the same numerators and // denominators. bool operator==(Fraction a, Fraction b) { return a == b; } // Returns true when the numerators or denominators of a and // b differ. bool operator!=(Fraction a, Fraction b) { return !(a == b); } // Write the given fraction to the output stream. std::ostream& operator<<(std::ostream& os, Fraction f) { return os << f.n << '/' << f.d; } int main() { Fraction f1(3, 4); Fraction f2(1, 3); // Check that operator != works. Should print true. std::cout << (f1 != f2) << ' '; }
3. This one is right but has the wrong output
#include// Read a number from the input stream. int get_number(std::istream& is) { unsigned result; is >> result; } int main() { // Read a sequence of numbers and pritn the total. int tot; while (true) { int n = get_number(std::cin); if (!std::cin) break; tot += n; } std::cout << "total: " << tot << ' '; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started