#include
#include
using namespace std;
void string_display(string* ad, int num);
int main()
{
string a = "dhsaih caishihsa saia";
string* b = &a;
string_display( b, 5);
}
void string_display(string* ad, int num)
{
if (num > 0)
{
cout << *ad << endl;
string_display(ad, num - 1);
}
}
#include
#include
using namespace std;
struct candy_bar
{
char name[20];
double weight;
int hot;
};
void strcut_value(candy_bar& a, const char* name = "Miilennium Munch", double weight=2.85, int hot=350);
void display(candy_bar a);
int main()
{
candy_bar a ;
char name[20] = "dbhsab dh";
char* b = name;
strcut_value(a, b, 22, 1);
display(a);
candy_bar c;
strcut_value(c);
display(c);
}
void strcut_value(candy_bar& a, const char* name, double weight, int hot)
{
strcpy_s(a.name, name);
a.weight = weight;
a.hot = hot;
}
void display(candy_bar a)
{
cout << "Name: " << a.name << endl;
cout << "Weight: " << a.weight << endl;
cout << "Hot: " << a.hot << endl;
}
#include
#include
#include
using namespace std;
void to_up(string& a);
int main()
{
string a;
cout << "Enter a string (q to quit):";
while (getline(cin, a) && a != "q")
{
to_up(a);
cout <
for (int i = 0; i < a.size(); i++)
{
a[i] = toupper(a[i]);
}
}
#include
using namespace std;
#include;
struct stringy {
char* str;
int ct;
};
void set(stringy& first, const char* test);
void show(const stringy& first, int num=1);
void show(const char* first, int num = 1);
int main()
{
stringy beany;
char testing[] = "Reality isn't what it used to be.";
set(beany, testing);
show(beany);
show(beany, 2);
testing[0] = 'D';
testing[1] = 'u';
show(testing);
show(testing, 3);
show("Done!");
return 0;
}
void set(stringy& first,const char* test)
{
first.str = new char[strlen(test) + 1];
strcpy_s(first.str, strlen(test) + 1,test);
}
void show(const stringy& first, int num)
{
cout << first.str< 1)
{
cout << first.str << endl;
num--;
}
}
void show(const char * first, int num)
{
cout << first << endl;
while (num > 1)
{
cout << first << endl;
num--;
}
}
#include
using namespace std;
template
T Max5(const T* array);
int main()
{
int test1[5] = { 1, 3, 5, 7, 9 };
double test2[5] = { 10.0, 20.0, 15.0, 12.0, 30.0 };
cout << "The max of int array is: " << Max5(test1) << endl;
cout << "The max of double array is: " << Max5(test2) << endl;
return 0;
}
template
T Max5(const T* array)
{
T tempt = array[0];
for (int i = 0; i < 5; i++)
{
if (array[i] > tempt)
tempt = array[i];
}
return tempt;
}
#include
#include
using namespace std;
template
T maxn(T *arr, int n);
template <>
const char *maxn(const char *str[], int n);
int main()
{
int test1[6] = {1, 3, 5, 7, 9, 11};
double test2[4] = {10.0, 20.0, 15.0, 12.0};
const char *test3[5] = {"123", "12345", "123456", "abcdefg", "xio"};
cout << "The max of int array is: " << maxn(test1, 6) << endl;
cout << "The max of double array is: " << maxn(test2, 4) << endl;
cout << "The max of string array is: " << maxn(test3, 5) << endl;
return 0;
}
template
T maxn(T *arr, int n)
{
T temp = arr[0];
for (int i = 0; i < n; i++)
{
if (temp < arr[i])
{
temp = arr[i];
}
}
return temp;
}
template <>
const char *maxn(const char *str[], int n)
{
const char *temp = *str;
for (int i = 1; i < n; i++)
{
if (strlen(temp) < strlen(str[i]))
{
temp = str[i];
}
}
return temp;
}
#include
template
T SumArray(T arr[], int n);
template
T SumArray(T *arr[], int n);
struct debts
{
char name[50];
double amount;
};
int main()
{
using namespace std;
int things[6] = {13, 31, 103, 301, 310, 130};
debts mr_E[3] =
{
{"Ima Wolfe", 2400.0},
{"Ura Foxe", 1300.0},
{"Iby Stout", 1800.0}
};
double *pd[3];
for (int i = 0; i < 3; i++)
{
pd[i] = &mr_E[i].amount;
}
cout << "Listing Mr. E's total of things:" << endl;
cout << SumArray(things, 6) << endl;
cout << "Listing Mr. E's total of debts:" << endl;
cout << SumArray(pd, 3) << endl;
return 0;
}
template
T SumArray(T arr[], int n)
{
using namespace std;
double sum = 0.0;
for (int i = 0; i < n; i++)
{
sum += arr[i];
}
return sum;
}
template
T SumArray(T *arr[], int n)
{
using namespace std;
double sum = 0.0;
for (int i = 0; i < n; i++)
{
sum += *arr[i];
}
return sum;
}