You are here: Home » Content » Structures

Structures

Module by: Dr. Duong Tuan Anh

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.

2. EXPERIMENT

  • 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)
  • 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.
  • a. Using the data type
struct MonthDays
{
char name[10];
int days;
};
define 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
  1. Declare a data type named Car, which is a structure consisting of the following information for each car:
Figure 1
  1. Using the data type defined in a) write a C++ program that inputs the data given in the above table into an array of 5 structures., and then computes and displays a report consisting of 3 columns: car-number, kms-driven and gas-litres-used.

Comments, questions, feedback, criticisms?

Send feedback