Skip to content

Commit ee028c6

Browse files
committed
update codes
1 parent edcd1b8 commit ee028c6

File tree

2 files changed

+68
-63
lines changed

2 files changed

+68
-63
lines changed

chapter06/assignment/assign6.11.5.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,32 @@
33

44
int main()
55
{
6-
unsigned int income;
6+
int income;
77
float tax;
88
std::cout << "Input your income: ";
9-
while (std::cin >> income)
9+
std::cin >> income;
10+
while (income > 5000)
1011
{
11-
while(income > 0)
12+
if (income > 35000)
1213
{
13-
if (income > 35000)
14-
{
15-
std::cout << "jiao" << std::endl;
16-
int tempTax = (income - 35000) * 0.2;
17-
tax += tempTax;
18-
income -= 35000;
19-
std::cout << "@@@" << std::endl;
20-
}
21-
else if (income > 15001 && income < 35000)
22-
{
23-
int tempTax = (income - 15000) * 0.15;
24-
tax += tempTax;
25-
income -= 15000;
26-
std::cout << "#####" << std::endl;
27-
}
28-
else if (income > 5001 && income < 15000)
29-
{
30-
int tempTax = (income - 5000) * 0.1;
31-
tax += tempTax;
32-
income -= 5000;
33-
std::cout << "$$$" << std::endl;
34-
35-
}
14+
int tempTax = (income - 35000) * 0.2;
15+
tax += tempTax;
16+
income = 35000;
17+
}
18+
else if (income > 15000 && income <= 35000)
19+
{
20+
int tempTax = (income - 15000) * 0.15;
21+
tax += tempTax;
22+
income = 15000;
3623
}
37-
38-
std::cout << income << " needs to pay: " << tax << std::endl;
24+
else if (income > 5000 && income <= 15000)
25+
{
26+
int tempTax = (income - 5000) * 0.1;
27+
tax += tempTax;
28+
income = 5000;
3929

30+
}
4031
}
4132

42-
std::cout << income << " needs to pay: " << tax << std::endl;
33+
std::cout << "Tax: " << tax << std::endl;
4334
}

chapter06/assignment/assign6.11.7.cpp

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,64 @@
55
int main()
66
{
77
std::cout << "Enter words (q to quit)" << std::endl;
8-
const int Size = 50;
9-
char ch;
10-
char word[Size];
11-
int index = 0;
128
int others = 0;
13-
int voel = 0;
14-
int constant = 0;
9+
int vowels = 0;
10+
int consonants = 0;
11+
std::string words;
1512
// memset(word, 0, sizeof(word));
16-
std::cin.get(ch);
17-
while (ch != 'q')
13+
while(std::cin >> words, words.size() > 1 && words != "q")
1814
{
19-
if (ch != ' ' && ch != '\n')
15+
std::cout << words << std::endl;
16+
if(isalpha(words[0]))
2017
{
21-
word[index] = ch;
22-
index += 1;
23-
}
24-
else
25-
{
26-
word[index + 1] = '\0';
27-
std::cout << word << std::endl;
28-
index = 0;
29-
if(isalpha(word[0]))
18+
if (words[0] == 'a' || words[0] == 'o' || words[0] == 'e'|| words[0] == 'i'|| words[0] == 'u')
3019
{
31-
if (word[0] == 'a' | word[0] == 'o' | word[0] == 'e'| word[0] == 'i'| word[0] == 'u')
32-
{
33-
voel += 1;
34-
}
35-
else{
36-
constant += 1;
37-
}
20+
vowels += 1;
3821
}
39-
else
40-
{
41-
others += 1;
22+
else{
23+
consonants += 1;
4224
}
43-
44-
// memset(word, 0, sizeof(word));
4525
}
46-
47-
std::cin.get(ch);
26+
else
27+
{
28+
others += 1;
29+
}
4830
}
31+
// while (strlen(word) > 1 && word[0] != 'q')
32+
// {
33+
// if (ch != ' ' && ch != '\n')
34+
// {
35+
// word[index] = ch;
36+
// index += 1;
37+
// }
38+
// else
39+
// {
40+
// word[index] = '\0';
41+
// std::cout << word << std::endl;
42+
// index = 0;
43+
// if(isalpha(word[0]))
44+
// {
45+
// if (word[0] == 'a' || word[0] == 'o' || word[0] == 'e'|| word[0] == 'i'|| word[0] == 'u')
46+
// {
47+
// vowels += 1;
48+
// }
49+
// else{
50+
// consonants += 1;
51+
// }
52+
// }
53+
// else
54+
// {
55+
// others += 1;
56+
// }
57+
58+
// // memset(word, 0, sizeof(word));
59+
// }
60+
// std::cin.get(ch);
61+
62+
// }
4963

50-
std::cout << voel << " words beginning with vowels" << std::endl;
51-
std::cout << constant << " words beginngin with consonants" << std::endl;
64+
std::cout << vowels << " words beginning with vowels" << std::endl;
65+
std::cout << consonants << " words begining with consonants" << std::endl;
5266

5367
std::cout << others << " others" << std::endl;
5468

0 commit comments

Comments
 (0)