CSIS 10A String (and Function) Drills
1. The following code has a function call in it:
int main( )
{
string name;
char grade;
int score;
score = easy ( name, grade );
a) what is the name of the function? ______
b) What are the arguments? ______
c) What are the data types of the arguments? ______
d) What is the return type? ______
e) Write ONLY the first line of the function (the head or prototype) below:
2. The following code has a function call in it:
int main( )
{
float z_score, ans;
int myAge, n_years;
char grade;
ans = rent (z_score, myAge, grade, n_years );
a) what is the name of the function? ______
b) What are the arguments? ______
c) What are the data types of the arguments? ______
d) What is the return type? ______
e) Write ONLY the first line of the function (the head or prototype) below:
3. The following code has a function call in it:
int main( )
{
string title, book1, book2;
float interest;
display_ledger ( title, book1, book2, interest );
a) what is the name of the function? ______
b) What are the arguments? ______
c) What are the data types of the arguments? ______
d) What is the return type? ______
e) Write ONLY the first line of the function (the head or prototype) below:
4. What are the outputs of this code?
OUTPUT
string s1 = “abra”, s2 = “cad”, s3;
s3 = s2 + s1;
cout < s1 < endl;
cout < s3 < endl;
s1 += s3 ;
cout < s1 < endl;
cout < s2 < endl;
5. Write a function called concat4 it accepts 4 string variables as arguments and returns
a string that contains all four of the arguments. For example, concat4("one","two","3","4");
returns the string "onetwo34"
6. Write a function called first that accepts 3 string variables and returns the string that comes first in the dictionary. For example first("fun","program", "create") returns the string "create"
7. Write a function called middle that accepts 3 string variables and returns the string that comes between the other two in the dictionary. For example middle("fun","program", "create") returns the string "fun"
8. Write a function called greeting that accepts a string for language (english, spanish, japanese, or chinese) and displays a greeting in that language (hello, hola, konichiwa, ni hao)
9. Write a function convert that takes a person’s firstname, initial and lastname and returns their fullname in last, first, MI format. For example convert ("Joe", "P","Cupertino"); returns the string "Cupertino, Joe P"