Programming Languages Homework Run Run Regular Exercise Regular Exercise And Low Fat Diet Health Insurance

subject Type Homework Help
subject Pages 14
subject Words 242
subject Authors D. S. Malik

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
41
c. run! = run!
17. Regular exercise
Regular exercise and low fat diet
33
18. a. 45
b. we will drive across
page-pf2
42
Chapter 8
2. a. currentBalance
b. 91
3. a. This declaration is correct.
b. Array size must be positive. A correct answer is: int testScores[10];
4. a. Valid
b. Invalid. The data type should be string.
6. a. int alpha[50];
b. for (int i = 0; i < 50; i++)
alpha[i] = -1;
page-pf3
43
g. cout << alpha[49] << endl;
h. for (int i = 0; i < 50; i++)
{
cout << alpha[i] << " ";
if ( (i + 1) % 15)
cout << endl;
}
cout << endl;
i. for (int i = 0; i < 50; i = i + 2)
alpha[i] = alpha[i] + 1;
j. int diffAlpha[49];
for (int i = 0; i < 49; i++)
diffAlpha[i] = alpha[i] - alpha[i - 1];
Size of diffAlpha is 49.
7. 0.00 1.50 9.00 28.50 66.00
57.00 1.50 30.00 28.50 66.00
8. 0 2 6 12 0 2 8 9
9. 1 2 2 4 8 32 224 6944
10. 2.50 2.50 5.00 15.00 30.00 75.00
11. int myList[10];
12.
int intList[5];
13. If array index is less than 0 or greater than arraySize 1, we say that the array index is out-of
14. The output of the code is:
points[2] and points[3] are out of order.
page-pf4
44
<< "] are out of order." << endl;
15. a. double heights[10] = {5.2, 6.3, 5.8, 4.9, 5.2, 5.7, 6.7, 7.1, 5.10, 6.0};
b. int weights[7] = {120, 125, 137, 140, 150, 180, 210};
or
d. string seasons[4] = {"fall", "winter", "spring", "summer"};
16. a. Valid. The size of list is 4.
b. Valid. The size of x is 10.
17. alpha[0] = 3, alpha [1] = 12, alpha [2] = -25, alpha [3] = 72,
18. a. for (int i = 0; i < 6; i++)
20. alpha: 1 3 5 7 9 -1 2 5 8 11
21. a. Correct.
22. a. Valid.
page-pf5
45
23. 1 35700.00 714.00
24.
int cars[10];
int sum = 0;
int maxIndex;
25. list: 810 0 270 180 90
26.
Quantity Unit Cost Amount
3 15.00 45.00
2 5.00 10.00
1 75.00 75.00
Total due: $254.00
27. 1 3.50 10.70 235.31
2 7.20 6.50 294.05
4 9.80 10.50 646.54
28. The base address of the array.
page-pf6
46
29. No.
30. List before the first iteration: 12, 50, 68, 30, 46, 5, 92, 10, 38
List after the first iteration: 5, 50, 68, 30, 46, 12, 92, 10, 38
List after the second iteration: 5, 10, 68, 30, 46, 12, 92, 50, 38
32. Cindy Blair
34. a. Invalid; the assignment operator is not defined for C-strings.
b. Valid
35. a. Valid
36. a. Yes
37. a. strcpy(myStr, "Summer Vacation");
38. a. Valid
page-pf7
47
d. Invalid; the assignment operator is not defined for C-strings.
e. Invalid; the relational and assignment operators are not defined for C-strings.
f. Valid
g. Valid
h. Valid
39. double matrix[4][3] = {{2.5, 3.2, 6.0}, {5.5, 7.5, 12.6},
40. a. for (int i = 0; i < 3; i++)
41. a. 30
b. 5
42. a. int alpha[10][20];
b. for (int j = 0; j < 10; j++)
c.
page-pf8
f.
}
43. a. beta is initialized to 0.
b. First row of beta: 0 1 2
Second row of beta: 1 2 3
Third row of beta: 2 3 4
44.
int flowers[28][10];
int animals[15][10];
int trees[100][10];
int inventory[30][10];
b.
void sumRow(int list[][10], int rowSize)
{
int sum;
for (int i = 0; i < rowSize; i++)
{
sum = 0;
page-pf9
}
void print(int list[][10], int rowSize)
{
for (int i = 0; i < rowSize; i++)
{
for (int j = 0; i < 10; j++)
cout << list [i][j] << " ";
cout << endl;
}
}
page-pfa
Chapter 9
2. struct computerType
{
string manufacturer;
};
3. computerType newComputer;
newComputer.manufacturer = "Computer Corporation";
4. a. houseType oldHouse, newHouse;
b. oldHouse.style = "Two-Story";
oldHouse.numOfBedrooms = 5;
5. if (firstHouse.style == secondHouse.style &&
firstHouse.price == secondHouse.price)
6. struct fruitType
{
string name;
};
7. fruitType fruit;
fruit.name = "banana";
page-pfb
51
fruit.fat = 1;
fruit.sugar = 15;
fruit.carbohydrate = 22;
8. a. void getFruitInput(fruitType& fruit)
{
<< "Color: " << fruit.color
<< "Fat: " << fruit.fat
10. a. Valid
b. Valid
c. Invalid; classList[1].name is a struct variable of type nameType while student is a
struct variable of type studentType, mismatch data types;
11. a. classList[0].name.first = "Jessica";
classList[0].name.last = "Miller";
12. a course.name = "Programming I";
course.callNum = 13452;
course.credits = 3;
page-pfc
52
13. a. Invalid; the member name of newEmployee is a struct. Specify the member names to store the
value "John Smith". For example,
newEmployee.name.first = "John";
14. a. newEmployee.name.first = "Mickey";
newEmployee.name.last = "Doe";
newEmployee.pID = 111111111;
15. sportsType soccer[20];
struct sportsType
16. a. for (int j = 0; j < 20; j++)
{
soccer [i].sportName = "";
soccer [i].teamName = "";
page-pfd
17. a. void getData(sportsType & sp)
{
b. void printData(sportsType sp)
{
cout << "Sport Name: " << sp[i].sportName << endl;
cout << "Team Name: " << sp[i].teamName << endl;
18. a. tourType destination;
b. destination.cityName = "Chicago";
destination.distance = 550;
destination.travelTime.hr = 9;
destination.travelTime.min = 30;
page-pfe
54
return dest;
}
e. void getData(tourType& dest)
{
cin >> dest.cityName;
cin >> dest.distance;
cin >> dest.travelTime.hr >> dest.travelTime.min;
}
page-pff
55
Chapter 10
2. In Line 4, the name of the constructor is misspelled. Line 4 should be:
3. A constructor has no type. The statements in Line 6 should be:
syntaxErrors2(int = 0,
4. A class is not a function. The function isEqual must have a return type. Because the second
parameter of the constructor is a default parameter, the first parameter must be a default
5. The function set must have a return type. A constructor cannot be constant. Replace : after } with ;.
The statements in Lines 4, 6, and 12 should be:
6.
a. 16
b. 6
c. 2
d. 7
void setFat(double f);
double getFat() const;
page-pf10
void setSugar(int s);
int getSugar() const;
7.
a.
void foodType::set(string s, int c, double f, int su,
double cr, double p)
{
name = s;
else
sugar = 0;
if (cr >= 0)
carbohydrate = cr;
else
page-pf11
}
cout << "Fat: " << fat << endl;
cout << "Sugar: " << sugar << endl;
cout << "Carbohydrate: " << carbohydrate << endl;
cout << "potassium: " << potassium << endl;
}
c.
}
double foodType::getPotassium() const
{
return potassium;
}
d.
foodType::foodType()
{
set("", 0, 0.0, 0, 0.0, 0.0);
}
page-pf12
f.
fruit2.print();
g.
foodType myFruit("Apple ", 52, 0.2, 10, 13.8, 148.0);
8.
a. i. Line 4
ii. Line 7
iii. Line 6
iv. Line 5
{
productName = "";
id = "";
manufacturer = "";
if (x >= 0)
quantitiesInStock = x;
}
d.
productType::productType(string s, int x, double y, double z)
{
productName = "";
id = s;
manufacturer = "";
page-pf13
59
quantitiesInStock = 0;
if (y >= 0.0)
price = y;
else
price = 0.0;
if (z >= 0.0)
discount = z;
else
discount = 0.0;
}
e.
productType::productType(string n, string pID, string m,
else
price = 0.0;
if (z >= 0.0)
discount = z;
else
}
9. The functions print, getQuantitiesInStock, getPrice, and getDiscount are
10.
a.
void productType::set(string n, string pID, string m,
int x, double y, double z)
{
productName = n;
page-pf14
60
price = 0.0;
if (z >= 0.0)
discount = z;
else
discount = 0.0;
}
b.
void productType::print() const
}
c.
void productType::setQuantitiesInStock(int x)
{
if (x >= 0)
}
d.
void productType::updateQuantitiesInStock(int x)
e.
int productType::getQuantitiesInStock() const
f.
void productType::setPrice(double x)
g.
double productType::getPrice() const

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.