C++ Primer Plus (Six Edition) Chapter 4, Review

Q1. How would you declare each of the following?

               a. actors is an array of 30 char.

               b. betsie is an array of 100 short.

               c. chuck is an array of 13 float.

               d. dipsea is an array of 64 long double.

A:   

char actors[30];
shrt betsie[100];
float chuck[13];
long double dipsea[64];

Q2. Does Chapter Review Question 1 use the array template class instead of built-in arrays.

A:

array<char, 30>actors;
array<short, 100>betsie;
array<float, 13>chuck;
array<long double, 64>dipsea;


Q3. Declare an array of five ints and initialize it to the first five odd posivive integers.

A:

int oddly[5] = {1, 3, 5, 7, 9};


Q4. Write a statement that assigns the sum of the first and last elements of the array in Question 3 to the variable even.

A:

int even = oddly[o] + oddly[4];

Q5. Write a statement that displays the value of the second element in the float array ideas.

A:

cout << ideas[1] << endl;

Q6. Declare an array of char and initialize it to the string "cheeseburger".

A:

char lunch[13] = "cheeseburger";
// number of characters + 1
or
char lunch[] = "cheeseburger";
// let the compiler count elements

Q7. Declare a string object and initialize it to the string "Waldorf  Salad".

A:

string lunch = " Waldorf Salad";

or, if you don't have a using directive,

std::string lunch = "Waldorf  Salad";

Q8. Devise a structure declaration that describes a fish. The structure should include the kind, the weight in whole ounces, and the length in fractional inches.

A:

structure fish
{
   char kind[20];
   int weight;
   float length;
};

Q9. Declare a variable of the type defined in Question 8 and initialize it.

A:

fish petes =
{
    "trout".
     12,
     26.25
};









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值