content
stringlengths
263
5.24M
pred_label
stringclasses
1 value
pred_score_pos
float64
0.6
1
// Using the explicit keyword // Uncomment "explicit" to make the compilation of // the expression "box1.hasLargerVolumeThan(50.0)" fail import std; class Cube { public: /*explicit*/ Cube(double side); // Constructor double volume(); // Calculate volume of a cube bool hasLargerVolumeT...
__label__POS
0.886923
// Avoid resource leaks due to exceptions using std::unique_ptr<> // Note: this example is given but not named in the text. // Instead of a custom RAII class DoubleArrayRAII, it uses std::unique_ptr<>. // Unlike the former, the latter can be returned from computeValues() as well. import std; import troubles; double co...
__label__POS
0.665656
// Using a stack defined by nested class templates import stack; import <iostream>; import <string>; int main() { std::string words[]{ "The", "quick", "brown", "fox", "jumps" }; Stack<std::string> wordStack; // A stack of strings for (const auto& word : words) wordStack.push(word); Stack<std...
__label__POS
0.999583
// Avoid resource leaks due to exceptions using std::unique_ptr<> // Note: this example is given but not named in the text. // Instead of a custom RAII class DoubleArrayRAII, it uses std::vector<>. // Unlike the former, the latter can of course be returned from computeValues() as well. import std; import troubles; dou...
__label__POS
0.66023
// Using the std::function<> template import <iostream>; import <functional>; #include <cmath> // for std::abs() // A global less() function bool less(int x, int y) { return x < y; } int main() { int a{ 18 }, b{ 8 }; std::cout << std::boolalpha; // Print true/false rather than 1/0 std::function<bo...
__label__POS
0.604835
// Removing all elements that satisfy a certain condition // while iterating over a container #include <vector> #include <string_view> #include <iostream> #include <algorithm> // for std::remove_if() #include <numeric> // for std::iota() std::vector<int> fillVector_1_to_N(size_t N); // Fill a vector with ...
__label__POS
0.788055
// Using a stack defined by a class template with a nested class // (with improvement suggested in the "A Better Stack" section: see Stack<> source) import stack; import std; int main() { std::string words[] {"The", "quick", "brown", "fox", "jumps"}; Stack<std::string> wordStack; // A stack of strings ...
__label__POS
0.999067
// Exercise 19-2 // Replace a custim stack container by the standard stack container adapter #include <stack> #include <iostream> #include <string> #include <array> // for std::size() int main() { std::string words[] {"The", "quick", "brown", "fox", "jumps"}; std::stack<std::string> wordStack; ...
__label__POS
0.992224
// Exercise 19-5 Create a generic average() algorithm using std::accumulate() #include <iostream> #include <numeric> #include <utility> // for std::pair<> (only required for Solution 2 below) #include <optional> #include <vector> // Solution 1: simply use accumulate to sum, and determine the count using std::...
__label__POS
0.993989
// Format specifiers for std::format() #include <iostream> #include <format> #include <numbers> // For the pi constant #include <cmath> // For the square root function int main() { // 2 square feet pond surface for every 6 inches of fish const double fish_factor{ 2.0 / 0.5 }; // Area per unit length of...
__label__POS
0.830263
import array; import box; import std; int main() { try { try { const std::size_t size {21}; // Number of array elements const int start {-10}; // Index for first element const int end {start + static_cast<int>(size) - 1}; // Index for...
__label__POS
0.75221
// Using a stack defined by a class template with a nested class // (using std::unique_ptr<>: see Stack<> source) // Note: this is a bonus example that is only hinted at in the text (and not explicitly named). // It requires the use of std::move(), seen only in Chapter 18. import stack; import std; int main() { std...
__label__POS
0.989298
import array; import box; import std; int main() { try { try { const std::size_t size {21}; // Number of array elements const int start {-10}; // Index for first element const int end {start + static_cast<int>(size) - 1}; // Index for...
__label__POS
0.75221
// Exercise 13-4 Working with Employee and Executive objects #include <iostream> #include <vector> #include "Person.h" int main() { std::vector<Employee> employees { Employee(21, "Randy Marathon", Gender::male, 34567), Employee(32, "Anna Pothe...
__label__POS
0.989179
// Formatting text using std::format() #include <iostream> #include <format> #include <numbers> // For the pi constant #include <cmath> // For the square root function int main() { // 2 square feet pond surface for every 6 inches of fish const double fish_factor{ 2.0 / 0.5 }; // Area per unit length of...
__label__POS
0.807782
// Sizing a pond for happy fish #include <iostream> #include <numbers> // For the pi constant #include <cmath> // For the square root function int main() { // 2 square feet pond surface for every 6 inches of fish const double fish_factor { 2.0/0.5 }; // Area per unit length of fish const double inches_per...
__label__POS
0.945655
// Using a stack defined by a class template with a nested class import stack; import std; int main() { std::string words[] {"The", "quick", "brown", "fox", "jumps"}; Stack<std::string> wordStack; // A stack of strings for (const auto& word : words) wordStack.push(word); Stack<std::string> new...
__label__POS
0.999842
// Calculating primes using pointer notation #include <iostream> #include <format> int main() { const size_t max {100}; // Number of primes required long primes[max] {2L}; // First prime defined size_t count {1}; // Count of primes found so far long trial {3L}; // Candidate prime w...
__label__POS
0.672391
// Dereferencing pointers // Calculates the purchase price for a given quantity of items #include <iostream> #include <format> int main() { int unit_price {295}; // Item unit price in cents int count {}; // Number of items ordered int discount_threshold {25}; // Quan...
__label__POS
0.929428
// Using smart pointers #include <iostream> #include <format> #include <memory> // For smart pointers #include <vector> // For std::vector<> container #include <cctype> // For std::toupper() int main() { std::vector<std::shared_ptr<std::vector<double>>> records; // Temperature records by days size_t day{ 1 }...
__label__POS
0.931194
// Generating multiplication tables using nested loops #include <iostream> #include <format> #include <cctype> int main() { size_t table {}; // Table size const size_t table_min {2}; // Minimum table size - at least up to the 2-times const size_t table_max {12}; // Maximum table size char reply...
__label__POS
0.871572
// Using a do-while loop to manage input #include <iostream> #include <cctype> // For tolower() function int main() { char reply {}; // Stores response to prompt for input int count {}; // Counts the number of inp...
__label__POS
0.994588
// Classifying the letters in a C-style string #include <iostream> #include <cctype> int main() { const int max_length {100}; // Array size char text[max_length] {}; // Array to hold input string std::cout << "Enter a line of text:" << std::endl; // Read a line of characters including spaces std::cin...
__label__POS
0.82813
#include <iostream> #include <format> #include <string> #include <vector> int main() { std::string text; // The string to be searched std::cout << "Enter some text terminated by *:\n"; std::getline(std::cin, text, '*'); const std::string separators{ " ,;:.\"!?'\n" }; ...
__label__POS
0.896162
// Convert SI to imperial weight // The conversion values are constant, // and should not be changed within the program, // so we recognize this by declaring them as a const. // // Note: we always output "pounds" even if it concerns only 1 pound. // In a later chapter you will learn about the conditional // statement...
__label__POS
0.743654
// Using std::span<const T> to ensure largest() works for const inputs #include <iostream> #include <string> #include <vector> #include <array> #include <span> // Old function prototypes //double largest(const double data[], size_t count); //double largest(const std::vector<double>& data); //int largest(const std::vec...
__label__POS
0.710697
// Using std::string_view parameters #include <iostream> #include <format> #include <string> #include <string_view> #include <vector> using std::string; using std::string_view; using std::vector; void find_words(vector<string>& words, string_view str, string_view separators); void list_words(const vector<string>& wor...
__label__POS
0.747624
// Exercise 6-2. Traversing arrays using pointer arithmetics // An exercise to further deepen your understanding of the relation // between pointers, pointer arithmetic, and arrays. import std; int main() { const int n {50}; int odds[n]; for (int i {}; i < n; ++i) odds[i] = i * 2 + 1; const int perline ...
__label__POS
0.902538
// Exercise 5-7. Outputting product records & cost // Getting the alignment right is tricky. // You have to adjust the field widths until it looks OK. import std; int main() { std::vector<unsigned> product_id; std::vector<unsigned> quantity; std::vector<double> unit_cost; // Read the records while (true) ...
__label__POS
0.921653
// Exercise 5-4 Print out characters entered by the user in reverse order import std; int main() { const std::size_t max_num_characters {1'000}; char string[max_num_characters]; std::print("Please enter a string: "); std::cin.getline(string, max_num_characters); // Count the number of characters std::s...
__label__POS
0.800214
// Exercise 7-2 Frequency of words in text. import std; int main() { std::string text; // The text to be searched std::println("Enter some text terminated by *:"); std::getline(std::cin, text, '*'); const std::string separators {" ,;:.\"!?'\n"}; // Word del...
__label__POS
0.884427
// Using a reference parameter #include <iostream> #include <format> #include <string> #include <vector> using std::string; using std::vector; void find_words(vector<string>& words, const string& str, const string& separators); void list_words(const vector<string>& words); int main() { std::string text; //...
__label__POS
0.741101
// Overloading a function #include <iostream> #include <string> #include <vector> // Function prototypes double largest(const double data[], size_t count); double largest(const std::vector<double>& data); int largest(const std::vector<int>& data); std::string largest(const std::vector<std::string>& words); // int larg...
__label__POS
0.826195
// Exercise 7-4 Check for anagrams. // There's more than one way to do this. // We chose to delete characters in one word that are common to both. // If the length of the word that has characters deleted is zero, they are anagrams. import std; int main() { std::string word1, word2; std::print("Enter the first w...
__label__POS
0.848541
// Exercise 7-3 Replacing a word in text by asterisks. // Because we are looking for the word regardless of case, // the best way is to scan the text character by character. import std; int main() { std::string text; // The text to be searched std::string word; // Stores the word to be replaced std::pri...
__label__POS
0.704623
// Exercise 7-6 Finding words that begin with a given letter. // If you wanted the words ordered by the first letter, you could sort the contents of letter first. // You could also retain all the sets of words for each letter in a separate vector for each set; // for this you could in other words use a std::vector<std:...
__label__POS
0.915415
// Exercise 7-7 // Practice string concatenation, looping over strings, and stoi()-like functions import std; int main() { std::println("Enter a sequence of numbers terminated by #:"); // Read a long string containing any number of integers std::string numbers; std::getline(std::cin, numbers, '#'); long ...
__label__POS
0.954652
// Exercise 7-1 Storing student names and grades. // This uses a vector of string objects to store the names. import std; int main() { std::vector<std::string> names; std::vector<double> grades; std::size_t max_length {}; // Longest name length double average_grade {}; // First accumulates the sum of...
__label__POS
0.711622
// Exercise 9-4. Using std::optional<> import std; // Function prototypes std::optional<double> largest(std::span<const double> data); std::optional<int> largest(std::span<const int> data); std::optional<std::string> largest(std::span<const std::string> words); int main() { const double array[]{ 1.5, 44.6, 13.7, 21...
__label__POS
0.746564
// Exercise 4-2 Testing for exact division of one integer by another. // We can use an if statement to check that the input is valid // and we can use another to arrange the input as we need. // Then we use an if-else to generate the appropriate output. import std; int main() ...
__label__POS
0.683061
// Exercise 8-7 Computing Fibonacci numbers iteratively. // On most systems (it depends on sizeof(unsigned long long)), // you can correctly compute up to 93 Fibonacci numbers with this program. import std; unsigned long long fib(unsigned int n); int main() { unsigned int num{}; std::print("Good day, master. How...
__label__POS
0.737321
// Exercise 8-2 Reversing the order of a string of characters. /****************************************************************** The reverse() function works with an argument of type string, or a C-style string terminated with '\0'. *******************************************************************/ import std; st...
__label__POS
0.951257
// Exercise 8-1 Reading and validating a date of birth. // As always, there are many ways of doing this! import std; int validate_input(int lower, int upper, const std::string& description); int year(); int month(); int day(int month_value, int year_value); std::string ending(int date_day); int main() { std::prin...
__label__POS
0.629026
// Exercise 3-1. Output an integer and its complements in binary and decimal. // This tests how well you remember string formatting using std::format() // (see Chapter 2 if you forgot some of the formatting options), // as well as two's complement binary encoding and bitwise ~. import std; // See Appendix A (availa...
__label__POS
0.780293
module words; import std; size_t max_word_length(const words::Words& words); void words::extract_words(Words& words, const std::string& text, const std::string& separators) { std::size_t start {text.find_first_not_of(separators)}; // Start index of first word while (start != std::string::npos) { std::size...
__label__POS
0.765835
module words.utils; import std; std::size_t max_word_length(const words::Words& words) { std::size_t max{}; for (auto& pword : words) if (max < pword->length()) max = pword->length(); return max; } void words::utils::extract_words(Words& words, const std::string& text, const std::string& separators) { st...
__label__POS
0.807791
module words.sorting; /* Additional helpers for word::sort(Words&) */ void swap(words::Words& words, std::size_t first, std::size_t second) { auto temp{ words[first] }; words[first] = words[second]; words[second] = temp; } void sort(words::Words& words, std::size_t start, std::size_t end); // Sort strings in a...
__label__POS
0.792401
export module words; import std; export namespace words { using Words = std::vector<std::shared_ptr<std::string>>; void sort(Words& words); void extract_words(Words& words, const std::string& text, const std::string& separators); void print_words(const Words& words); } namespace words { std::size_t max_wo...
__label__POS
0.682206
module words; import std; size_t max_word_length(const words::Words& words); void words::extract_words(Words& words, const std::string& text, const std::string& separators) { std::size_t start {text.find_first_not_of(separators)}; // Start index of first word while (start != std::string::npos) { std::size...
__label__POS
0.765835
module words; import std; import :internals; void words::extract_words(Words& words, const std::string& text, const std::string& separators) { std::size_t start {text.find_first_not_of(separators)}; // Start index of first word while (start != std::string::npos) { std::size_t end{ text.find_first_of(separa...
__label__POS
0.778781
// Constraint based specialization #include <concepts> // For the std::equality_comparable<> concept #include <iterator> // The iterator concepts and the iter_difference_t<>() trait #include <vector> #include <list> #include <iostream> // Precondition: incrementing first eventually leads to last template <std::input...
__label__POS
0.969252
// Animal class and classes derived from Animal export module animals; import std; export class Animal { public: Animal(std::string_view name, int weight) // Constructor : m_name{ name }, m_weight{ weight } {} protected: void who() const // Display name and weight { std::println...
__label__POS
0.821548
// Creating and working with Standard iterators #include <vector> #include <iostream> int main() { std::vector<char> letters{ 'a', 'b', 'c', 'd', 'e' }; auto my_iter{ letters.begin() }; std::cout << *my_iter << std::endl; // a *my_iter = 'x'; std::cout << letters[0] << std::endl; // x ++my_ite...
__label__POS
0.972516
// Removing all elements that satisfy a certain condition // while iterating over a container #include <vector> #include <string_view> #include <iostream> std::vector<int> fillVector_1toN(size_t N); // Fill a vector with 1, 2, ..., N void printVector(std::string_view message, const std::vector<int>& numbers); void ...
__label__POS
0.955347
// Removing all elements that satisfy a certain condition // usign the remove-erase idiom and the range-based version of std::remove_if. // Unlike the iterator-based version, std::ranges::erase_if() returns a subrange, // and not an iterator. // Note also that in this case std::erase_if() is even more compact (see E...
__label__POS
0.742526
// Exercise 20-3 Replacing custom container types with standard ones /* The following replacements were made compared to Soln17_06.cpp: - LinkedList<T> --> std::vector<T> (not std::list<>, because vector<> should be your go-to container; there's rarely a good reason to use linked lists) - SparseArray<T> --> std...
__label__POS
0.645039
// Inserting in and erasing from sequence containers #include <iostream> #include <vector> void printVector(const std::vector<int>& v); int main() { std::vector numbers{ 2, 4, 5 }; // Deduced type: std::vector<int> numbers.insert(numbers.begin(), 1); // Add single element to the beginning of the sequence pr...
__label__POS
0.96807
// Removing all elements that satisfy a certain condition // usign the remove-erase idiom #include <vector> #include <string_view> #include <iostream> #include <algorithm> std::vector<int> fillVector_1toN(size_t N); // Fill a vector with 1, 2, ..., N void printVector(std::string_view message, const std::vector<int>&...
__label__POS
0.948699
// Exercise 20-5 Create a generic average() algorithm using std::accumulate() import std; // Solution 1: simply use accumulate to sum, and determine the count using std::distance() // (the latter is more general than using iterator arithmetic, end - begin, // which only works for random-access iterators) template <t...
__label__POS
0.983178
// Exercise 20-2 // Replace a custom stack container by the standard stack container adapter import std; /* Two challenges: - std::stack<>::pop() is a void function. To access the top of the stack, you use std::stack<>::top(). - std::stack<const T> is not allowed */ int main() { std::string words[]{ "The...
__label__POS
0.992277
// Exercise 15-1 Animals.cppm // Animal classes export module animals; import std; export class Animal { public: Animal(std::string_view name, unsigned weight);// Constructor virtual ~Animal() = default; // Very important: a virtual destructor! virtual std::string who() const; /...
__label__POS
0.737749
// Polymorphic vectors of smart pointers #include <iostream> #include <memory> // For smart pointers #include <vector> // For vector #include "Box.h" // For the Box class #include "ToughPack.h" // For...
__label__POS
0.883626
// Polymorphic vectors of smart pointers #include <iostream> #include <memory> // For smart pointers #include <vector> // For vector #include "Box.h" // For the Box class #include "ToughPack.h" // For...
__label__POS
0.946741
// Calling the base class version of a virtual function (see ToughPack::volume()) #include <iostream> #include <memory> // For smart pointers #include <vector> // For vector #include "Box.h" // For the Box class #include "Toug...
__label__POS
0.928122
/*****************************************************************\ To implement printCount(), you first need a static member variable to store the object count. Every constructor should then increment this count, and you need to add a destructor that decrements it. \************************************************...
__label__POS
0.957528
// Create a doubly-linked list of Packages import box.random; import truckload; import std; /* To show reverse iteration, we've modified findSmallestBox() to iterate in reverse order */ SharedBox findLargestBox(const Truckload& truckload); SharedBox findSmallestBox(const Truckload& truckload); int main() { Tru...
__label__POS
0.656417
module integer; import std; /******************************************************************\ Implementing compare() as a friend is quite simple. We must declare the function as a friend in the class definition. We now need both objects as arguments and the code in the body of the function just compares the ...
__label__POS
0.631072
// Using the explicit keyword // Uncomment "explicit" to make the compilation of // the expression "box1.hasLargerVolumeThan(50.0)" fail #include <iostream> class Cube { public: /*explicit*/ Cube(double side); // Constructor double volume(); // Calculate volume of a cube bool hasLarge...
__label__POS
0.894332
// Avoid resource leaks due to exceptions using std::unique_ptr<> // Note: this example is given but not named in the text. // Instead of a custom RAII class DoubleArrayRAII, it uses std::unique_ptr<>. // Unlike the former, the latter can be returned from computeValues() as well. #include <iostream> #include <memory> #...
__label__POS
0.660435
// Avoid resource leaks due to exceptions using std::unique_ptr<> // Note: this example is given but not named in the text. // Instead of a custom RAII class DoubleArrayRAII, it uses std::vector<>. // Unlike the former, the latter can of course be returned from computeValues() as well. #include <iostream> #include <vec...
__label__POS
0.822245
/* * Copyright (C) 2022 Appvia Ltd <info@appvia.io> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This ...
__label__POS
0.874873
// Using a stack defined by nested class templates // (with improvement suggested in the "A Better Stack" section: see Stack<> source) #include "Stack.h" #include <iostream> #include <string> int main() { std::string words[]{ "The", "quick", "brown", "fox", "jumps" }; Stack<std::string> wordStack; // ...
__label__POS
0.99942
// Using a stack defined by nested class templates // (using std::unique_ptr<>: see Stack<> source) // Note: this is a bonus example that is only hinted at in the text (and not explicitly named). // It requires the use of std::move(), seen only in Chapter 18. #include "Stack.h" #include <iostream> #include <string> i...
__label__POS
0.994916
// Using a stack defined by nested class templates #include "Stack.h" #include <iostream> #include <string> int main() { std::string words[]{ "The", "quick", "brown", "fox", "jumps" }; Stack<std::string> wordStack; // A stack of strings for (const auto& word : words) wordStack.push(word); St...
__label__POS
0.999872
// Using the std::function<> template #include <iostream> #include <functional> #include <cmath> // for std::abs() // A global less() function bool less(int x, int y) { return x < y; } int main() { int a{ 18 }, b{ 8 }; std::cout << std::boolalpha; // Print true/false rather than 1/0 std::function<...
__label__POS
0.772255
// Exercising the SparseArray class template in combination with the LinkedList class template import sparse_array; import linked_list; import std; int main() { std::string text; // Stores input prose or poem std::println("Enter a poem or prose over one or more lines.\n" ...
__label__POS
0.895643
// Defaulting the == operator #include <iostream> #include <format> #include <string_view> #include <vector> #include "Box.h" void show(const Box& box) { std::cout << std::format("Box({:.1f}, {:.1f}, {:.1f})", box.getLength(), box.getWidth(), box.getHeight()); } void show(const Box& box1, std::str...
__label__POS
0.870073
// Overloading <=> and == to fully support all comparison operators #include <iostream> #include <format> #include <string_view> #include <vector> #include "Box.h" void show(const Box& box) { std::cout << std::format("Box({:.1f}, {:.1f}, {:.1f})", box.getLength(), box.getWidth(), box.getHeight());...
__label__POS
0.719501
// Exercising the LinkedList template class // This program reverses the text that is entered import linked_list; import std; int main() { std::string text; // Stores input prose or poem std::println("Enter a poem or prose over one or more lines.\n" "Terminate the input wi...
__label__POS
0.983135
// Exercise 5-7. Outputting product records & cost // Getting the alignment right is tricky. // You have to adjust the field widths until it looks OK. import <iostream>; import <format>; import <vector>; #include <cctype> int main() { std::vector<size_t> product_id; std::vector<size_t> quantity; std::vector<dou...
__label__POS
0.914381
// Exercise 5-4 Print out characters entered by the user in reverse order import <iostream>; int main() { const size_t max_num_characters {1'000}; char string[max_num_characters]; std::cout << "Please enter a string: "; std::cin.getline(string, max_num_characters); // Count the number of characters siz...
__label__POS
0.658364
// Exercise 4-2 Testing for exact division of one integer by another. // We can use an if statement to check that the input is valid // and we can use another to arrange the input as we need. // Then we use an if-else to generate the appropriate output. import <iostream>; int ...
__label__POS
0.799964
// Exercise 4-05 // Using the conditional operator to select output. import <iostream>; import <format>; int main() { int mice {}; // Count of all mice int brown {}; // Count of brown mice int white {}; // Count of white mice std::cout << "How many brown mice do you have? "; std::cin >> brown; ...
__label__POS
0.91202
// Exercise 8-2 Reversing the order of a string of characters. /****************************************************************** The reverse() function works with an argument of type string, or a C-style string terminated with '\0'. *******************************************************************/ import <iostrea...
__label__POS
0.8725
// Exercise 3-1. Output an integer and its complements in binary and decimal. // This tests how well you remember string formatting using std::format() // (see Chapter 2 if you forgot some of the formatting options), // as well as two's complement binary encoding and bitwise ~. import <iostream>; import <format>; /...
__label__POS
0.766145
// Exercise 3-2. Calculating the number of boxes that can be stored on a shelf, without overhang. // We have to calculate how many boxes we can get into a row, // and how many rows we can have, and then multiply these numbers together. // The 'no overhang' problem is easily handled: casting from double to long // (us...
__label__POS
0.847054
// Animal class and classes derived from Animal export module animals; import <string>; import <string_view>; import <iostream>; export class Animal { public: Animal(std::string_view name, int weight) // Constructor : m_name{ name }, m_weight{ weight } {} protected: void who() const /...
__label__POS
0.619759
// Exercise 20-5 Create a generic average() algorithm using std::accumulate() import <iostream>; import <numeric>; import <utility>; // for std::pair<> (only required for Solution 2 below) import <optional>; import <vector>; // Solution 1: simply use accumulate to sum, and determine the count using std::distance()...
__label__POS
0.984889
// Exercise 20-2 // Replace a custom stack container by the standard stack container adapter import <stack>; import <iostream>; import <string>; /* Two challenges: - std::stack<>::pop() is a void function. To access the top of the stack, you use std::stack<>::top(). - std::stack<const T> is not allowed */ ...
__label__POS
0.988107
// Exercise 15-1 Animals.cppm // Animal classes export module animals; import <string>; import <string_view>; export class Animal { public: Animal(std::string_view name, unsigned weight);// Constructor virtual ~Animal() = default; // Very important: a virtual destructor! virtual std::string w...
__label__POS
0.612801
/*****************************************************************\ To implement printCount(), you first need a static member variable to store the object count. Every constructor should then increment this count, and you need to add a destructor that decrements it. \************************************************...
__label__POS
0.901489
module integer; import <iostream>; /****************************************************************\ Implementing compare() as a friend is quite simple. We must declare the function as a friend in the class definition. We now need both objects as arguments and the code in the body of the function just compares th...
__label__POS
0.651765
// Create a doubly-linked list of Packages import box.random; import truckload; import <iostream>; /* To show reverse iteration, we've modified findSmallestBox() to iterate in reverse order */ SharedBox findLargestBox(const Truckload& truckload); SharedBox findSmallestBox(const Truckload& truckload); int main() ...
__label__POS
0.691706
// Exercise 17-5 Exercising the LinkedList template class // This program reverses the text that is entered import linked_list; import <string>; import <string_view>; import <iostream>; int main() { std::string text; // Stores input prose or poem std::cout << "\nEnter a poem or prose o...
__label__POS
0.909058
/* * Copyright (C) 2023 Appvia Ltd <info@appvia.io> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This ...
__label__POS
0.629995
// Exercise 6-2. Traversing arrays using pointer arithmetics // An exercise to further deepen your understanding of the relation // between pointers, pointer arithmetic, and arrays. #include <iostream> #include <format> int main() { const size_t n {50}; size_t odds[n]; for (size_t i {}; i < n; ++i) odds[i]...
__label__POS
0.751491
// Exercise 5-7. Outputting product records & cost // Getting the alignment right is tricky. // You have to adjust the field widths until it looks OK. #include <iostream> #include <format> #include <cctype> #include <vector> int main() { std::vector<size_t> product_id; std::vector<size_t> quantity; std::vector<d...
__label__POS
0.978107
// Exercise 5-4 Print out characters entered by the user in reverse order #include <iostream> int main() { const size_t max_num_characters {1'000}; char string[max_num_characters]; std::cout << "Please enter a string: "; std::cin.getline(string, max_num_characters); // Count the number of characters si...
__label__POS
0.75019
// Exercise 7-2 Frequency of words in text. #include <iostream> #include <format> #include <string> #include <vector> int main() { std::string text; // The text to be searched std::cout << "Enter some text terminated by *:\n"; std::getline(std::cin, text, '*'); const ...
__label__POS
0.796709
package com.bsg6.chapter08; import org.springframework.lang.NonNull; import java.util.Objects; import java.util.StringJoiner; public class Artist { Integer id; @NonNull String name; public Artist() {} public Artist(@NonNull String name) { this.name=name; } public Artist(Integer...
__label__POS
0.867825