Download PROGRAMMING FUNDAMENTALS IN C++

Transcript
CHAPTER 1. STUDENT MANUAL
40
1.4.6 LAB SESSION 5: STRINGS AND STRUCTURES
1.4.6.1 1. OBJECTIVE
The objectives of Lab session 5 are (1) to get familiar with strings; (2) to get familiar with structures; (3)
to practice on processing arrays of structures.
1.4.6.2 2. EXPERIMENT
2.1) Write a C++ program that accepts a string of characters from a terminal and displays the hexadecimal
equivalent of each character.
(Hint: Use the cin.getline() function to input a string)
2.2) Write a C++ program that accepts a two strings of characters from a keyboard and displays the
concatenation of the two strings.
(Hint: Use the cin.getline() function to input a string)
2.3) Write and run a program that reads three strings and prints them out in an alphabetical order.
(Hint: Use the strcmp() function).
2.4) Write a C++ program that accepts a string of characters from a terminal and converts all lower-case
letters in the string to upper-case letters.
2.5) a. Using the data type
struct MonthDays
{
char name[10];
int days;
};
dene an array of 12 structures of type MonthDays. Name the array months and initialize the array with
the names of the 12 months in a year and the number of days in each month.
b.
Include the array created in a) in a program that displays the names and number of days in each
month.
2.6) a. Declare a data type named Car, which is a structure consisting of the following information for
each car:
Figure 1.17
Available for free at Connexions <http://cnx.org/content/col10788/1.1>