#include <iostream>
using namespace std;
void show(const char *arr,int n=0);
int main()
{
char *p1="why me?";
show(p1);
cout<<endl;
for(int i=0;i<3;i++)
{
cout<<"i = "<<i<<endl;
show(p1,i);
}
cout<<"Done\n";
return 0;
}
void show(const char *arr,int n)
{
static int uses=0;
int lim = uses++;
if(n==0)
lim=1;
for(int i=0;i<lim;i++)
{
cout<<arr<<endl;
}
}
#include <iostream>
using namespace std;
const int SIZE=20;
struct CandyBar
{
char *name;
double weight;
int calories;
};
void fillful(CandyBar &p,char *a_name="Millennium munch",double wei=2.85,int calo=350);
void show(const CandyBar &p);
int main()
{
CandyBar arr;
char a_name[SIZE];
double wei;
int calo;
cout<<"Please enter the Chocolate's name:";
cin.get(a_name,SIZE);
cout<<"Please enter the Chocolate's weight:";
cin>>wei;
cout<<"Please enter the Chocolate's calories:";
cin>>calo;
fillful(arr,a_name,wei,calo);
show(arr);
cout<<"Done"<<endl;
return 0;
}
void fillful(CandyBar &p,char *a_name,double wei,int calo)
{
p.name=a_name;
p.weight=wei;
p.calories=calo;
}
void show(const CandyBar &p)
{
cout<<p.name<<" have "<<p.weight<<" pound and "<<p.calories<<" calories."<<endl;
}
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void toup(string & ch);
int main()
{
string ch;
cout<<"Enter a string (q to quit): ";
getline(cin,ch);
while(ch!="q")
{
toup(ch);
cout<<ch<<endl;
cout<<"Next string (q to quit): ";
getline(cin,ch);
}
cout<<"Bye."<<endl;
return 0;
}
void toup(string & ch)
{
for(int i=0;i<ch.length();i++)
ch[i]=toupper(ch[i]);
}
#include <iostream>
#include <cstring>
using namespace std;
struct stringy
{
char *str;
int ct;
};
void show(const char *str,int cnt=1);
void show(const stringy &bny,int cnt=1);
void set(stringy &bny,const char *str);
int main()
{
stringy beany;
char testing[] = "Reality ins'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 &bny,const char *str)
{
bny.ct=strlen(str);
bny.str=new char[bny.ct+1];
strcpy(bny.str,str);
}
void show(const char *str,int cnt)
{
while(cnt-->0)
{
cout<<str<<endl;
}
}
void show(const stringy &bny,int cnt)
{
while(cnt-->0)
cout<<bny.str<<endl;
}
#include <iostream>
#include <cstring>
using namespace std;
template<typename T>
T maxn(T arr[],int n);
template <> const char*maxn(const char *arr[],int n);
int main()
{
int arr1[6]={1,2,3,4,5,6};
cout<<maxn(arr1,6)<<endl;
double arr2[4]={1.1,2.1,3.1,4.1};
cout<<maxn(arr2,4)<<endl;
const char *arr3[5]={"asd","adfas","asdasdfgff","ad","asdv"};
cout<<maxn(arr3,5);
return 0;
}
template<typename T>
T maxn(T arr[],int n)
{
T max=0;
for(int i=0;i<n;i++)
{ if(arr[i]>max)
max=arr[i]; }
return max;
}
template <> const char*maxn(const char *arr[],int n)
{
unsigned int max=strlen(arr[0]);
const char *ps=arr[0];
for(int i=1;i<n;i++)
{
if(strlen(arr[i])>max)
{
ps=arr[i];
max=strlen(ps);
}
}
return ps;
}
#include <iostream>
template <typename T>
T ShowArray(T arr[],int n);
template <typename T>
T ShowArray(T *arr[],int n);
struct debts
{
char name[50];
double amount;
};
using namespace std;
int main()
{
int things[6]={13,31,103,301,310,130};
struct 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 counts of things: \n";
cout<<ShowArray(things,6)<<endl;
cout <<"Listing MR .E's debts: \n";
cout<<ShowArray(pd,3)<<endl;
return 0;
}
template <typename T>
T ShowArray(T arr[],int n)
{
T sum=0;
for(int i=0;i<n;i++)
sum+=arr[i];
return sum;
}
template <typename T>
T ShowArray(T *arr[],int n)
{
T sum=0;
for(int i=0;i<n;i++)
sum+=*arr[i];
return sum;
}