forked from ShujiaHuang/Cpp-Primer-Plus-6th
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
511f1be
commit 78d0757
Showing
4 changed files
with
291 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Create by Shujia Huang on 2021-08-03 | ||
#include <iostream> | ||
#include <string> | ||
|
||
|
||
int main() { | ||
|
||
using namespace std; | ||
|
||
const int Grand_Amount = 10000; | ||
|
||
struct Patron { | ||
string name; | ||
double amount; | ||
}; | ||
|
||
int contribute_num = 0; | ||
cout << "Enter the number of contributor: "; | ||
cin >> contribute_num; | ||
cin.get(); // 读取输入流中的回车符 | ||
|
||
Patron *p_contribution = new Patron [contribute_num]; | ||
for (int i = 0; i < contribute_num; ++i) { | ||
cout << "Enter the name of " << i + 1 << " contributor: "; | ||
getline(cin, p_contribution[i].name); | ||
|
||
cout << "Enter the amount of donation: "; | ||
cin >> p_contribution[i].amount; | ||
cin.get(); // 读取输入流中的回车符 | ||
} | ||
|
||
unsigned int grand_amount_n = 0; | ||
cout << "\nGrand patron: " << endl; | ||
for (int i = 0; i < contribute_num; ++i) { | ||
|
||
if (p_contribution[i].amount > Grand_Amount) { | ||
cout << "Contributor name: " << p_contribution[i].name << "\n" | ||
<< "Contributor amount: " << p_contribution[i].amount << endl; | ||
++grand_amount_n; | ||
} | ||
} | ||
|
||
if (grand_amount_n == 0) { | ||
cout << "None" << endl; | ||
} | ||
|
||
bool is_empty = true; | ||
cout << "\nPatrons: " << endl; | ||
for (int i=0; i < contribute_num; ++i) { | ||
cout << "Contributor name: " << p_contribution[i].name << "\n" | ||
<< "Contributor amount: " << p_contribution[i].amount << endl; | ||
|
||
is_empty = false; | ||
} | ||
|
||
if (is_empty) { | ||
cout << "** None **" << endl; | ||
} | ||
|
||
delete [] p_contribution; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Create by Shujia Huang on 2021-08-03 | ||
#include <iostream> | ||
#include <cctype> | ||
#include <string> | ||
|
||
|
||
int main() { | ||
|
||
using namespace std; | ||
|
||
unsigned int vowels = 0; | ||
unsigned int consonants = 0; | ||
unsigned int other = 0; | ||
string input; | ||
|
||
cout << "Enter words (q to quit): " << endl; | ||
while (cin >> input) { | ||
if (input == "q") | ||
break; | ||
|
||
if (isalpha(input[0])) { | ||
switch(toupper(input[0])) { | ||
|
||
case 'A':; | ||
case 'E':; | ||
case 'I':; | ||
case 'O':; | ||
case 'U': | ||
++vowels; | ||
break; | ||
|
||
default: | ||
++consonants; | ||
break; | ||
} | ||
} else { | ||
++other; | ||
} | ||
} | ||
|
||
cout << vowels << " words beginning with vowels.\n" | ||
<< consonants << " words beginning with consonants.\n" | ||
<< other << " words beginning with other letter." << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Create by Shujia Huang on 2021-08-04 | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
|
||
|
||
int main() { | ||
using namespace std; | ||
|
||
string fn; | ||
ifstream in_file_handle; | ||
|
||
unsigned int n = 0; | ||
char ch; | ||
|
||
cout << "Enter a file name: "; | ||
getline(cin, fn); | ||
|
||
in_file_handle.open(fn.c_str()); | ||
while ((ch = in_file_handle.get()) != EOF) { | ||
++n; | ||
} | ||
in_file_handle.close(); | ||
|
||
cout << "There are " << n << " characters in " | ||
<< fn << " file." << endl; | ||
|
||
return 0; | ||
} |