content
stringlengths
263
5.24M
pred_label
stringclasses
1 value
pred_score_pos
float64
0.6
1
// Program 9.3 Passing a Pointer to a function #include <stdio.h> // Function prototypes int sum(int,int); int product(int,int); int difference(int,int); int any_function(int(*pfun)(int, int), int x, int y); int main(void) { int a = 10; // Initial value for a int b = 5; ...
__label__POS
0.999887
// Program 9.2 Arrays of Pointers to functions #include <stdio.h> // Function prototypes int sum(int, int); int product(int, int); int difference(int, int); int main(void) { int a = 10; // Initial value for a int b = 5; // Initial value for b int result = 0; ...
__label__POS
0.998008
/* Example 9.6a Recursion example A checkboard unsorted where a fly must visit each cell, but cannot pass through two identical cells. Start and Finish are wildcards */ #include <stdio.h> #include <math.h> #define SIZE 5 // board's size #define MAX_BRANCH 8 // 8 = possible branches bool used[SIZE * ...
__label__POS
0.814521
// Program 9.9 REVERSI An Othello type game #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> #include <ctype.h> #include <string.h> #define SIZE 6 // Board size - must be even const char comp_c = '@'; // Computer's counter const char player_c = 'O'; // Player's c...
__label__POS
0.621343
// Exercise 8.2 A function to return a string representation of an integer #include <stdio.h> #include <stdbool.h> #define STR_LEN 6 // Length of string to store value string // Converts an integer to a string. Caller must allocate string array. // Function returns the string to all...
__label__POS
0.983366
// Exercise 8.3 A function to return a string representation of an integer with a given width #include <stdio.h> #include <stdbool.h> #define STR_LEN 15 // Length of string to store value string // Convert an integer to a string with a fixed width. // if the widh is too small, the minimu...
__label__POS
0.973894
// Exercise 8.4 A function to return the number of words in a string passed as an argument */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define LENGTH_INCREMENT 20 #define MAX_WORD_LENGTH 30 int countwords(char str[]); // Function to count words in a string int se...
__label__POS
0.931418
// Exercise 8.1 A function to calculate an average #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define CAPACITY_INCREMENT 6 // Increment in the capacity for data values double average(double data[], int count) { double sum = 0.0; for(int i = 0 ; i...
__label__POS
0.609348
// Ex4.5 A Modified Guessing Game #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> // For time() function #include <ctype.h> // I added this for toupper() #include <stdbool.h> // I added...
__label__POS
0.718426
// Exercise 11.4 Using a structure to record the count of occurrences of a word. /* This program defines a structure that stores a word and the count of its occurrences. The structures are stored as they are created in a linked list. If you wanted the output in alphabetical order, you could insert the structures ...
__label__POS
0.687592
// Exercise 11.5 Sorting names using a binary tree #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define FIRST_MAX 30 #define SECOND_MAX 50 // Defines a name typedef struct Name { char first[FIRST_MAX]; char second[SECOND_MAX]; } Name; // Defines...
__label__POS
0.832491
// Exercise 6.1 Convert an integer to words #define _CRT_SECURE_NO_WARNINGS #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> #include <string.h> int main(void) { char *unit_words[] = {"zero", "one","two","three","four","five","six","seven","eight","nine"}; char *teen_words[] = {"ten", "eleven","twelve","thirtee...
__label__POS
0.773918
// Exercise 7.4 Read and process daily temperatures #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define DAYS 2 // Initial number of days allowed for #define READINGS_PER_DAY 6 // Readings per day ...
__label__POS
0.694428
//Exercise 5.5 Calculating average student grades. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdbool.h> #include <ctype.h> int main(void) { size_t nclasses = 0; // Number classes size_t nstudents_max = 0; // Maximum number of students in a class char answer = 'N'; ...
__label__POS
0.991159
//Exercise 5.1 Summing reciprocals of five values #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main(void) { const int nValues = 5; // Number of data values double data[nValues]; // Stores data values double reciprocals[nValues]; double sum = 0.0; // Sto...
__label__POS
0.785953
// Sizing a pond for happy fish #include <iostream> #include <cmath> // For 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_foot { 12.0 }; const double...
__label__POS
0.944081
// Calculating primes using pointer notation #include <iostream> #include <iomanip> 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}; ...
__label__POS
0.658132
// Dereferencing pointers // Calculates the purchase price for a given quantity of items #include <iostream> #include <iomanip> int main() { int unit_price{ 295 }; // Item unit price in cents int count{}; // Number of items ordered int discount_threshold{ 25 }; /...
__label__POS
0.835029
// Using smart pointers #include <iostream> #include <iomanip> #include <memory> // For smart pointers #include <vector> // For vector container #include <cctype> // For toupper() int mai...
__label__POS
0.88799
// Generating multiplication tables using nested loops #include <iostream> #include <iomanip> #include <cctype> // for std::tolower() 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...
__label__POS
0.655409
// Using the continue statement to display ASCII character codes #include <iostream> #include <iomanip> #include <cctype> #include <limits> int main() { // Output the column headings std::cout << std::setw(11) << "Character " << std::setw(13) << "Hexadecimal " << std::setw(9) << "Decimal " << std::endl...
__label__POS
0.930998
// Using a do-while loop to manage input #include <iostream> #include <locale> // For tolower() function int main() { char reply{}; // Stores response to prompt for input int count{}; // Counts the number ...
__label__POS
0.988121
// Allocating an array at runtime // This example does not work with some compilers (such as Visual C++) // because dynamic arrays is not standard C++ (it is valid C though). #include <iostream> #include <iomanip> // for std::setprecision() int main() { size_t count {}; std::cout << "How many heights will you...
__label__POS
0.662255
// 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 inclu...
__label__POS
0.82813
// Searching a string for characters from a set #include <iostream> #include <iomanip> #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, '*'...
__label__POS
0.90029
// Comparing strings #include <iostream> // For stream I/O #include <iomanip> // For stream manipulators #include <string> // For the string type #include <cctype> // for std::isalpha() and tolower() #include <vector> ...
__label__POS
0.774681
// Using decltype() inside a function template #include <iostream> #include <vector> #include <algorithm> // for std::min() // Template that computes a so-called "inner product" of two vectors. // Both vectors are supposed to be equally long, // but the function will cope if they aren't. template<typename T1, typenam...
__label__POS
0.816387
// Using string_view parameters #include <iostream> #include <iomanip> #include <string> #include <string_view> #include <vector> using std::string; using std::vector; void find_words(vector<string>& words, std::string_view str, std::string_view separators); void list_words(const vector<string>& words); int main(...
__label__POS
0.788085
// Using a reference parameter #include <iostream> #include <iomanip> #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() { string text; ...
__label__POS
0.729226
// Overloading a function #include <iostream> #include <string> #include <vector> using std::string; using std::vector; // Function prototypes double largest(const double data[], size_t count); double largest(const vector<double>& data); int largest(const vector<int>& data); string largest(const vector<string>& word...
__label__POS
0.78055
// Requesting the compiler to generate a default constructor #include <iostream> // Class to represent a box class Box { private: double length {1.0}; double width {1.0}; double height {1.0}; public: // Default constructor Box() = default; // Constructor Box(double lengthValue, double widthValue, dou...
__label__POS
0.695379
#include "Truckload.h" // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (auto pBox : boxes) { addBox(pBox); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (Package* package{src.pHead}; package; package = package->pNext) { addBox(package->pBox);...
__label__POS
0.701946
#include "Truckload.h" // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (const auto& pBox : boxes) { addBox(pBox); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (Package* package{src.pHead}; package; package = package->getNext()) { addBox(pack...
__label__POS
0.729514
// Calling the base class version of a virtual function (see ToughPack.h) #include <iostream> #include <memory> // For smart pointers #include <vector> // For vector #include "Box.h" // For the Box class #include "ToughPack.h"...
__label__POS
0.927908
// 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
// 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
// Throwing exceptions in nested try blocks #include <iostream> void throwIt(int i) { throw i; // Throws the parameter value } int main() { for (int i {}; i <= 5; ++i) { try { std::cout << "outer try:\n"; if (i == 0) throw i; // Throw...
__label__POS
0.966102
#include "Truckload.h" // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (auto pBox : boxes) { addBox(pBox); } } // Get the first Box SharedBox Truckload::Iterator::getFirstBox() { // Return pHead's box (or nullptr if the list is empty) pCurrent = pHead; return pCurrent? p...
__label__POS
0.787798
#include "Truckload.h" SharedBox Truckload::nullBox {}; // Initialize static class member // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (const auto& pBox : boxes) { addBox(pBox); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (P...
__label__POS
0.803466
// Using the templates for overloaded comparison operators for Box ojects #include <iostream> #include <string_view> #include <vector> #include <utility> // For the std::rel_ops utility function templates #include "Box.h" using namespace std::rel_ops; void show(const Box& box1, std::string_view relationship, cons...
__label__POS
0.723609
// Using a stack defined by nested class templates #include "Stack.h" #include <iostream> #include <string> #include <array> // for std::size() int main() { std::string words[] {"The", "quick", "brown", "fox", "jumps"}; Stack<std::string> wordStack; // A stack of strings for (size_t i {...
__label__POS
0.998158
// Stack.h Templates to define stacks #ifndef STACK_H #define STACK_H #include <stdexcept> template <typename T> class Stack { private: // Nested class class Node { public: T item {}; // The object stored in this node Node* next {}; ...
__label__POS
0.651006
// Using a stack defined by nested class templates #include "Stack.h" #include <iostream> #include <string> #include <array> // for std::size() int main() { std::string words[] {"The", "quick", "brown", "fox", "jumps"}; Stack<std::string> wordStack; // A stack of strings for (size_t i {...
__label__POS
0.998158
// 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::functi...
__label__POS
0.846985
// Inserting in and erasing from sequence containers #include <iostream> #include <vector> void printVector(const std::vector<int>& v); int main() { std::vector<int> numbers{ 2, 4, 5 }; numbers.insert(numbers.begin(), 1); // Add single element to the beginning of the sequence printVector(numbers); ...
__label__POS
0.981123
// Working with maps #include <iostream> #include <iomanip> #include <map> #include <string> #include <string_view> #include <vector> // Type aliases using Words = std::vector<std::string_view>; using WordCounts = std::map<std::string, size_t>; // Function prototypes Words extract_words(std::string_view text, std::st...
__label__POS
0.624684
// 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_1_to_N(size_t N); // Fill a vector with 1, 2, ..., N void printVector(std::string_view message, const std::vecto...
__label__POS
0.835796
// Removing all elements that satisfy a certain condition // while iterating over a container #include <vector> #include <string_view> #include <iostream> std::vector<int> fillVector_1_to_N(size_t N); // Fill a vector with 1, 2, ..., N void printVector(std::string_view message, const std::vector<int>& numbers);...
__label__POS
0.888004
// Format specifiers for std::format() import <iostream>; import <format>; import <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 fi...
__label__POS
0.658962
// Exercise 2-5. Calculating the Body Mass Index. // In the expression for bmi, both h_feet and h_inches will be implicitly converted to double // because the other operand of the sub-expression is double. // If you omit the std::fixed from the final output statement // setprecision() specifies the number of digits pr...
__label__POS
0.760293
// 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 <iomanip> int main() { const size_t n {50}; size_t odds[n]; for (size_t i {}; i < n; ++i) odds[i...
__label__POS
0.643435
// Formatting text using std::format() import <iostream>; import <format>; import <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 fi...
__label__POS
0.623826
// 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 <iomanip> #include <cctype> #include <vector> using std::setw; int main() { std::vector<size_t> product_id; std::vector<size_t> quantit...
__label__POS
0.914047
// Sizing a pond for happy fish import <iostream>; import <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_f...
__label__POS
0.872637
// 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.729052
// Exercise 7-2 Frequency of words in text. #include <iostream> #include <iomanip> #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.731259
// Exercise 7-8 // Practice string concatenation, looping over strings, and stoi()-like functions #include <iostream> #include <string> int main() { std::string numbers; std::cout << "Enter a sequence of numbers terminated by #:\n"; while (true) { std::string number; // Read strings one by one std:...
__label__POS
0.933909
// 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. #include <iostream> #include <cctype> #include <string> int main() { std::string wo...
__label__POS
0.805722
// 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. #include <iostream> #include <string> #include <cctype> int main() { std::string text; // The text to...
__label__POS
0.704277
// Dereferencing pointers // Calculates the purchase price for a given quantity of items import <iostream>; import <format>; int main() { int unit_price {295}; // Item unit price in cents int count {}; // Number of items ordered int discount_threshold {25}; // Quanti...
__label__POS
0.853323
// 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.912306
// Using smart pointers import <iostream>; import <format>; import <memory>; // For smart pointers import <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.791074
// Exercise 7-1 Storing student names and grades. // This uses a vector of string objects to store the names. #include <iostream> #include <iomanip> #include <cctype> #include <vector> #include <string> int main() { std::vector<std::string> names; std::vector<double> grades; size_t max_length {}; ...
__label__POS
0.876332
// Generating multiplication tables using nested loops import <iostream>; import <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.79309
// Using a do-while loop to manage input import <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.983458
// Classifying the letters in a C-style string import <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.627856
// Exercise 4-1 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. #include <iostream> int...
__label__POS
0.856391
// 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'. *******************************************************************/ #include <iostr...
__label__POS
0.950897
// Overloading a function import <iostream>; import <string>; import <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 largest...
__label__POS
0.616928
// 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.899437
#include "Truckload.h" // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (auto pBox : boxes) { addBox(pBox); } } // Output all Box objects in the list void Truckload::listBoxes() const { const size_t boxesPerLine = 5; size_t count {}; for (Package* package{pHead}; packag...
__label__POS
0.725782
// Exercise 11-5 Integer.cpp /*****************************************************************\ 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.887257
// Exercise 11-4 Integer.cpp /****************************************************************\ 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 n me...
__label__POS
0.714295
// Constraint based specialization import <concepts>; // For the std::equality_comparable<> concept import <iterator>; // The iterator concepts and the iter_difference_t<>() trait import <vector>; import <list>; import <iostream>; // Precondition: incrementing first eventually leads to last template <std::input_or_o...
__label__POS
0.82962
// Exercise 14-6 Exercising Shape classes #include "Shapes.h" #include <iostream> #include <vector> double calculateSumAreas(const std::vector<Shape*>& shapes); double calculateSumPerimeters(const std::vector<Shape*>& shapes); void printSums(const std::vector<Shape*>& shapes); int main() { Circle c1{Point{1, 1}, 1...
__label__POS
0.881873
// Sizing a pond for happy fish import std; 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_foot { 12.0 }; double fish_count {}; // Number of fish double fish_length {}; ...
__label__POS
0.718215
// Creating and working with Standard iterators import <vector>; import <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_iter;...
__label__POS
0.862952
// Exercise 14-1 Animals.h // Animal classes #ifndef ANIMALS_H #define ANIMALS_H #include <string> #include <string_view> class Animal { private: std::string name; // Name of the animal unsigned weight; // Weight of the animal public: Animal(std::...
__label__POS
0.765415
// Dereferencing pointers // Calculates the purchase price for a given quantity of items import std; int main() { int unit_price {295}; // Item unit price in cents int count {}; // Number of items ordered int discount_threshold {25}; // Quantity threshold for discoun...
__label__POS
0.816218
// Using smart pointers import std; int main() { std::vector<std::shared_ptr<std::vector<double>>> records; // Temperature records by days for (int day{ 1 };; ++day) // Collect temperatures by day { // Vector to store current day's temperatures created in the free store auto day_records{ std::make...
__label__POS
0.872142
// Generating multiplication tables using nested loops import std; int main() { int table {}; // Table size const int table_min {2}; // Minimum table size - at least up to the 2-times const int table_max {12}; // Maximum table size char reply {}; // Response to prompt do { std:...
__label__POS
0.956235
// Generating multiplication tables using nested loops // In this version an indefinite for loop is used, in combination with break statements. import std; int main() { int table {}; // Table size const int table_min {2}; // Minimum table size - at least up to the 2-times const int table_max {12}; /...
__label__POS
0.840504
// Removing all elements that satisfy a certain condition // while iterating over a container import <vector>; import <string_view>; import <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 rem...
__label__POS
0.798292
// Inserting in and erasing from sequence containers import <iostream>; import <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 prin...
__label__POS
0.8336
// Searching a string for characters from a set import std; int main() { std::string text; // The string to be searched std::println("Enter some text terminated by *:\n"); std::getline(std::cin, text, '*'); const std::string separators{ " ,;:.\"!?'\n" }; // Word delimiters ...
__label__POS
0.770909
// Removing all elements that satisfy a certain condition // usign the remove-erase idiom import <vector>; import <string_view>; import <iostream>; import <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>& num...
__label__POS
0.686558
// Using std::span<const T> to ensure largest() works for const inputs import std; // Old function prototypes //double largest(const double data[], std::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>& w...
__label__POS
0.661937
// Using a reference parameter import std; 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; // The string to be searched std::println("Enter some text ter...
__label__POS
0.702116
// Overloading a function import std; // Function prototypes double largest(const double data[], std::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); /* The following function overload would not comp...
__label__POS
0.786796
// Sorting words recursively import std; using Words = std::vector<std::shared_ptr<std::string>>; void swap(Words& words, std::size_t first, std::size_t second); void sort(Words& words); void sort(Words& words, std::size_t start, std::size_t end); Words extract_words(const std::string& text, const std::string& separa...
__label__POS
0.846581
#include "Truckload.h" SharedBox Truckload::nullBox {}; // Initialize static class member // Constructor Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (const auto& pBox : boxes) { addBox(pBox); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (P...
__label__POS
0.641812
// Using the explicit keyword // Uncomment "explicit" to make the compilation of // the expression "box1.hasLargerVolumeThan(50.0)" fail import <iostream>; class Cube { public: /*explicit*/ Cube(double side); // Constructor double volume(); // Calculate volume of a cube bool hasLarger...
__label__POS
0.813935
// Working with maps import std; // Type aliases using Words = std::vector<std::string_view>; using WordCounts = std::map<std::string_view, std::size_t>; // Function prototypes Words extractWords(std::string_view text, std::string_view separators = " ,.!?\"\n"); WordCounts countWords(const Words& words); void showWor...
__label__POS
0.843544
// Exercise 16-6 Exercising the SparseArray class template with the LinkedList class template #include "SparseArray.h" #include "LinkedList.h" #include <string> #include <iostream> #include <cctype> #include <utility> int main() { std::string text; // Stores input prose or poem std::...
__label__POS
0.674006
// Exercise 16-5 Exercising the LinkedList template class // This program reverses the text that is entered #include "LinkedList.h" #include <string> #include <iostream> int main() { std::string text; // Stores input prose or poem std::cout << "\nEnter a poem or prose over one or more ...
__label__POS
0.953562
// Inserting in and erasing from sequence containers import std; 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 std::println("{}", numbers); // [1, 2, 4, 5] numbers.insert(numb...
__label__POS
0.929827
// Using a stack defined by nested class templates // (with improvement suggested in the "A Better Stack" section: see Stack<> source) import stack; import <iostream>; import <string>; int main() { std::string words[]{ "The", "quick", "brown", "fox", "jumps" }; Stack<std::string> wordStack; // A stack...
__label__POS
0.998365
module truckload; import std; // Constructor - vector of Boxes Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (const auto& box : boxes) { addBox(box); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (Package* package{ src.m_head }; package; package = package->get...
__label__POS
0.660923
// 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. import stack; import <iostream>; import <string>; int main...
__label__POS
0.9876
module truckload; import std; // Constructor - vector of Boxes Truckload::Truckload(const std::vector<SharedBox>& boxes) { for (const auto& box : boxes) { addBox(box); } } // Copy constructor Truckload::Truckload(const Truckload& src) { for (Package* package{ src.m_head }; package; package = package->m_ne...
__label__POS
0.62469