Skip to content

Commit c0bf5e6

Browse files
committed
formatting code style for ch09
1 parent 3c19bc8 commit c0bf5e6

File tree

4 files changed

+36
-68
lines changed

4 files changed

+36
-68
lines changed

ch09/ex9_15.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
//
2-
// ex9_15.cpp
3-
// Exercise 9.15
4-
//
5-
// Created by pezy on 12/2/14.
6-
// Copyright (c) 2014 pezy. All rights reserved.
7-
//
8-
// @Brief Write a program to determine whether two vector<int>s are equal.
1+
//! @file Exercise 9.15
2+
//! @author pezy
3+
//! @date 2014-12-02
4+
//! @Brief Write a program to determine whether two vector<int>s are equal.
95

106
#include <iostream>
117
#include <vector>
128

139
int main()
1410
{
15-
std::vector<int> vec1{1,2,3,4,5};
16-
std::vector<int> vec2{1,2,3,4,5};
17-
std::vector<int> vec3{1,2,3,4};
11+
std::vector<int> vec1{1, 2, 3, 4, 5};
12+
std::vector<int> vec2{1, 2, 3, 4, 5};
13+
std::vector<int> vec3{1, 2, 3, 4};
1814

19-
std::cout << (vec1 == vec2 ? "true" : "false") << std::endl;
20-
std::cout << (vec1 == vec3 ? "true" : "false") << std::endl;
15+
std::cout << std::boolalpha << (vec1 == vec2) << std::endl;
16+
std::cout << std::boolalpha << (vec1 == vec3) << std::endl;
2117

2218
return 0;
2319
}

ch09/ex9_16.cpp

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
//
2-
// ex9_16.cpp
3-
// Exercise 9.16
4-
//
5-
// Created by pezy on 12/2/14.
6-
// Copyright (c) 2014 pezy. All rights reserved.
7-
//
8-
// @Brief Repeat the previous program, but compare elements in a
9-
// list<int> to a vector<int>.
1+
//! @file Exercise 9.16
2+
//! @author pezy
3+
//! @date 2014-12-02
4+
//! @Brief Repeat the previous program, but compare elements in a list<int> to a vector<int>.
105

116
#include <iostream>
127
#include <vector>
138
#include <list>
149

1510
int main()
1611
{
17-
std::list<int> vec1{1,2,3,4,5};
18-
std::vector<int> vec2{1,2,3,4,5};
19-
std::vector<int> vec3{1,2,3,4};
12+
std::list<int> list{1, 2, 3, 4, 5};
13+
std::vector<int> vec1{1, 2, 3, 4, 5};
14+
std::vector<int> vec2{1, 2, 3, 4};
2015

21-
std::cout << (std::vector<int>(vec1.begin(), vec1.end()) == vec2 ? "true" : "false")
22-
<< std::endl;
23-
std::cout << (std::vector<int>(vec1.begin(), vec1.end()) == vec3 ? "true" : "false")
24-
<< std::endl;
25-
26-
return 0;
16+
std::cout << std::boolalpha << (std::vector<int>(list.begin(), list.end()) == vec1) << std::endl;
17+
std::cout << std::boolalpha << (std::vector<int>(list.begin(), list.end()) == vec2) << std::endl;
2718
}

ch09/ex9_27.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
//
2-
// ex9_27.cpp
3-
// Exercise 9.27
4-
//
5-
// Created by pezy on 12/3/14.
6-
// Copyright (c) 2014 pezy. All rights reserved.
7-
//
8-
// @Brief Write a program to find and remove the odd-valued
9-
// elements in a forward_list<int>.
1+
//! @file Exercise 9.27
2+
//! @author pezy
3+
//! @date 2014-12-03
4+
//! @Brief Write a program to find and remove the odd-valued elements in a forward_list<int>.
105

116
#include <iostream>
127
#include <forward_list>
@@ -15,15 +10,12 @@ using std::forward_list; using std::cout; using std::endl;
1510

1611
int main()
1712
{
18-
forward_list<int> flst = {0,1,2,3,4,5,6,7,8,9};
19-
for (auto prev = flst.before_begin(), curr = flst.begin(); curr != flst.end(); )
13+
forward_list<int> flst = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
14+
for (auto prev = flst.before_begin(), curr = flst.begin(); curr != flst.end();)
2015
if (*curr & 0x1) curr = flst.erase_after(prev);
2116
else prev = curr++;
22-
17+
2318
for (auto i : flst)
2419
cout << i << " ";
25-
26-
return 0;
20+
cout << endl;
2721
}
28-
29-

ch09/ex9_49.cpp

+10-21
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
1-
//
2-
// ex9_49.cpp
3-
// Exercise 9.49
4-
//
5-
// Created by pezy on 12/5/14.
6-
// Copyright (c) 2014 pezy. All rights reserved.
7-
//
8-
// @Brief A letter has an ascender if, as with d or f, part of the letter extends
9-
// above the middle of the line.
1+
//! @file Exercise 9.49
2+
//! @author pezy
3+
//! @date 2014-12-05
4+
//! @Brief A letter has an ascender if, as with d or f, part of the letter extends above the middle of the line.
105
// A letter has a descender if, as with p or g, part of the letter extends below the line.
11-
// Write a program that reads a file containing words and reports the longest word
12-
// that contains neither ascenders nor descenders.
6+
// Write a program that reads a file containing words and reports the longest word that contains
7+
// neither ascenders nor descenders.
138

149
#include <string>
1510
#include <fstream>
1611
#include <iostream>
1712

18-
using std::string; using std::cout; using std::endl; using std::ifstream;
13+
using std::string; using std::ifstream; using std::cout; using std::endl;
1914

20-
int main()
21-
{
15+
int main() {
2216
ifstream ifs("../data/letter.txt");
2317
if (!ifs) return -1;
2418
string longest_word;
25-
for (string word; ifs >> word; )
19+
for (string word; ifs >> word;)
2620
if (word.find_first_not_of("aceimnorsuvwxz") == string::npos &&
2721
word.size() > longest_word.size())
2822
longest_word = word;
29-
30-
cout << longest_word << endl;
31-
32-
ifs.close();
3323

34-
35-
return 0;
24+
cout << longest_word << endl;
3625
}

0 commit comments

Comments
 (0)