T

@thomascutler

6.5a Message Goodbye

C++
4 months ago
#include <iostream> using namespace std; string message_goodbye(string name, int message = 1) { string full_message; switch(message){ case 1: full_message = "Goodbye, " + name + "!"; break;

6.4d Determine Winner

C++
4 months ago
#include <iostream> #include <string> using namespace std; string player1_name = "Todd"; string player2_name = "Mandy"; int score1; int score2;

6.4c Find Area

C++
4 months ago
#include <iostream> #include <string> using namespace std; int number_of_sides; string find_area(int length, int height) { int area; string area_message = "The area of your shape is ";

6.4b Ticket Prices with Local Scope

C++
4 months ago
#include <iostream> #include <string> using namespace std; string determineTicketType(int age) { if (age < 13) { return "Child"; } else if (age >= 13 && age <= 64) { return "Adult";

6.4a Greeting with Local Scope

C++
4 months ago
#include <iostream> #include <string> using namespace std; /** Makes a personalized greeting */ string greet(const string& name) { return "Hello " + name + "!";

6.3d Boxes

C++
4 months ago
#include <iostream> using namespace std; void print_boxes(int n) { if (n <= 0) { return; } cout << "[]"; print_boxes(n - 1);

6.3c Every Second

C++
4 months ago
#include <iostream> #include <string> using namespace std; string every_second(string s) { if (s.length() <= 1) { return s; }

6.3b Helper Functions Revisited

C++
4 months ago
#include <iostream> #include <string> using namespace std; int count_char(const string& str, char c) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str[i] == c) { count++; }

6.3a Helper Functions

C++
4 months ago
#include <iostream> #include <string> using namespace std; int count_spaces(const string& str) { int spaces = 0; for (char ch : str) {

6.3 DESCRIBE

C++
4 months ago
#include <iostream> // Function definition for factorial calculation long long factorial(int n) { // Base case: if n is 0 or 1, return 1 if (n <= 1) { return 1; } // Recursive step: call factorial function again with a smaller problem (n - 1) else {

6.2d Differing Numbers of Parameters and Arguments

C++
4 months ago
/* params.cpp provides an experimental setting * for exploring reference parameters. * * Begun by: Adams, for Hands On C++. * Completed by: * Date: * * Specification: * output(screen): the values of 3 variables, int1, int2, int3, ***************************************************************/

6.2c Value Parameters and Identical Argument Names

C++
4 months ago
#include <iostream> using namespace std; //hypthesis: Considering the last two lessons I think that it will again be treated with a copy and the original values will nto be updated showing arg1=arg2=arg3=-1 void Change(int, int, int); int main() { // 0. Print a message explaining the program; cout << "\nThis program provides a 'laboratory' in which\n" << "experiments can be performed on parameter-passing.\n";

6.2b Value Parameters and Their Arguments

C++
4 months ago
#include <iostream> using namespace std; //hypthesis: I think that arg1 arg2 and arg3 will remain unchanged because a copy will be stored in the paramter variable and any changes will afect the copy not he original value. void Change(int, int, int); int main() { // 0. Print a message explaining the program; cout << "\nThis program provides a 'laboratory' in which\n" << "experiments can be performed on parameter-passing.\n";

6.2a Changing Parameters

C++
4 months ago
/* params.cpp provides an experimental setting * for exploring reference parameters. * * Begun by: Adams, for Hands On C++. * Completed by: * Date: * * Specification: * output(screen): the values of 3 variables, int1, int2, int3, ***************************************************************/

6.2 Describe Parameters

C++
4 months ago
#include <iostream> // Function definition with two parameters: a and b void print_sum(int a, int b) { int sum = a + b; std::cout << "The sum of " << a << " and " << b << " is: " << sum << std::endl; } int main() { // Calling the function with actual values

6.1d Hide Characters

C++
4 months ago
#include <iostream> #include <string> using namespace std; /** Returns a string of asterisks of the same length as a given string. @param str a string such as "secret" @return a string with each character of str changed to a *, such as "******".

6.1c Even or Odd

C++
4 months ago
#include <iostream> #include <random> using namespace std; bool is_even() { random_device rd; mt19937 gen(rd()); int n = gen() % 100;

6.1b Say Hello!!!

C++
4 months ago
#include <iostream> using namespace std; void shout() { cout << "Hello!!!" << endl; } int main() {

6.1a Call Function

C++
4 months ago
#include <iostream> #include <string> using namespace std; /** Forms an abbreviated version of a string. @param str a string @param length the number of characters to show in the abbreviation @return str, if it has at most length characters, or a string

6.1 Describe: Functions and Returns

C++
4 months ago
#include <iostream> int add(int a, int b) { return a + b; } int main() { int x = 5; int y = 3; int result = add(x, y);