c++primer plus 第六章习题

原创 2016年05月05日 22:07:36
#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
	char ch;
	cin.get(ch);
	while (ch != '@')
	{
		if (isalpha(ch))
		{
			if (islower(ch))
				cout << char(ch - 32);
			else if (isupper(ch))
				cout << char(ch + 32);

		}
		else if(!(isdight(ch)))
			cout << ch;
		cin.get(ch);
	}
	system("pause");
	return 0;
}

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
	double donation[10];
	double average=0,sum=0;
	int i=0,num=0;
	cout << "please enter your number:";
	while (i<10&&cin>>donation[i])
	{
		cout << "please enter your number:";
		sum += donation[i];
		i++;
	}
	average = sum / i;
	cout << "平均值:" <<average << endl;
	for (int j = 0; j < i; j++)
	{
		if (donation[j]>average)
		{
			num++;
		}
	}
	cout << "超过平均值的数字个数:" << num << endl;
	system("pause");
	return 0;
}



#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
void menu();
int main()
{
	menu();
	char choice;
	
	while (cin>>choice&&choice!= 'c' && choice != 'p' && choice != 't' && choice != 'g')
	{
		cout << "Please enter c p t g :";
	}
	switch (choice)
	{
	case 'c': cout << "I love you!\n"; break;
	case 'p':cout << "I hate you!\n"; break;
	case't':cout << "I miss you!\n"; break;
	case'g':cout << "oh my gald!\n"; break;
	}
	system("pause");
	return 0;
}
void menu()
{
	cout << "Please enter c p t g :\n"
		"c) carnivore          p) pianist\n"
		"t) tree               g) game\n";
}



#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
void menu();
int main()
{
	menu();
	char choice;
	cin >> choice;
	while (choice != 'q')
	{
		switch (choice)
		{
			case 'a': cout << "I love you!\n"; break;
			case 'b':cout << "I hate you!\n"; break;
			case'c':cout << "I miss you!\n"; break;
			case'd':cout << "oh my gald!\n"; break;
		}
		cout << "Enter your choice:";
		cin >> choice;
	}
	
	system("pause");
	return 0;
}
void menu()
{
	cout << "Please enter a b c d q :\n"
		"a) carnivore          b) pianist\n"
		"c) tree               c) game\n"
		"q) quit\n"
		"Enter your choice:";
}



#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
void menu();
int main()
{
	int choice;
	double tax;
	cout << "Enter your salary:";
	while (cin >> choice)
	{
		if (choice < 0)
			break;
		else if (choice <= 5000)
		{
			tax = 0;
			cout << "Tax:" << tax << endl;
		}
		else if (choice>5000&&choice<=15000)
		{
			tax = (choice-5000)*0.1;
			cout << "Tax:" << tax << endl;
		}
		else if (choice>15000 && choice <= 35000)
		{
			tax = (choice-15000)*0.15 + 10000 * 0.1;
			cout << "Tax:" << tax << endl;
		}
		else
		{
			tax = (choice-35000)*0.2 + 20000 * 0.15 + 10000 * 0.1;
			cout << "Tax:" << tax << endl;
		}
		cout << "Enter your salary:";
	}

	system("pause");
	return 0;
}



#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;
struct donate
{
	string  name;
	double  money;
};
int main()
{
	
	int num;
	cout << "Please enter donate numbers:";
	cin >> num;
	cin.get();
	donate *d1 = new donate[num];
	for (int i = 0; i < num; i++)
	{
		cout << "Please enter name:";
		getline(cin,d1[i].name);
		cout << "Please enter money:";
		cin >> d1[i].money;
		cin.get();
	}
	cout << "Grand Patrons:";
	int counter=0;
	for (int i = 0; i < num; i++)
	{
		if (d1[i].money>10000)
		{
			cout << d1[i].name << '\t'; counter++;
		}

	}
	if (counter == 0)
	{
		cout << "None !" << endl;
	}
	cout << '\n';
	counter = 0;
	cout << "Patrons:";
	for (int i = 0; i < num; i++)
	{
		if (d1[i].money < 10000)
		{
			cout << d1[i].name << '\t'; counter++;
		}		
	}
	cout << "\n";
	if (counter == 0)
	{
		cout << "None !" << endl; 
	}
  delete[]d1;
	system("pause");
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;

int main()
{
	cout << "Enter words(q to quit):";
	string s;
	int counter=0,i=0,j=0;
	while (cin >> s)
	{
		if (s[0] == 'q' || s[0] == 'Q')
			break;
		else if (s[0] == 'a' || s[0] == 'A' || s[0] == 'e' || s[0] == 'E' ||
			s[0] == 'i' || s[0] == 'I')
			counter++;
		else if (s[0] == 'b' || s[0] == 'c')
			i++;
		else
			j++;
	}
	cout << counter << "words begin with vowels" << endl;
	cout << i << "words begin with constants" << endl;
	cout << j << "words begin with others" << endl;
	system("pause");
	return 0;
}



#include<iostream>
#include<stdlib.h>
#include<fstream>
//第六章习题
using namespace std;

int main()
{
	ifstream infile;
	int count=0;
	infile.open("1.txt");
	char s;
	infile >> s;
	while (infile.good())
	{
		++count;
		infile >> s;
	}
	cout << count << " Items!\n";
	infile.close();
	system("pause");
	return 0;
}




#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;
struct donate
{
	string  name;
	double  money;
};
int main()
{
	
	int num;
	cout << "Please enter donate numbers:";
	cin >> num;
	cin.get();
	donate *d1 = new donate[num];
	for (int i = 0; i < num; i++)
	{
		cout << "Please enter name:";
		getline(cin,d1[i].name);
		cout << "Please enter money:";
		cin >> d1[i].money;
		cin.get();
	}
	for (int i = 0; i < num; i++)
	{
		cout <<"Name:"<< d1[i].name <<endl;
		cout <<"Money:"<< d1[i].money << endl;
	}
    delete[]d1;
	system("pause");
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

c++ Primer Plus(第六版)第六章习题,写代码之路

c++ Primer Plus(第六版)习题,写代码之路
  • Robot_x
  • Robot_x
  • 2017年01月20日 11:41
  • 155

c++ primer plus第六章习题答案

直接上代码: 第一题 #include #include using namespace std; int main() { char flag; do { cin >> flag; i...

C Primer Plus 第六章部分习题

1 时间转换: 代码: void time_change() { while (1) { float min = 0; printf("请输入分钟数:"); scanf_s("%f"...

C Primer Plus 第六章课后习题练习……2015.4.24

既然下定决心,就要持之以恒!C Primer Plus!这仅仅只是开始……2015.4.24

c++ primer plus(第6版)中文版 第六章编程练习答案

第六章编程练习答案

《C++ Primer Plus(第六版)》(8)(第六章 分支语句和逻辑运算符 笔记和答案)

1.字符函数库头文件     isalnum()    字母或数字     isalpha()    字母     iscntr()     控制字符     isdigit()    数字(0-9...

C++ Primer Plus学习笔记 第六章 cctype字符函数库 switch语句 continue和break语句 基本文件输入输出

声明:本文整理自《C++ Primer Plus》 1.错误防范。 将表达式mynumber==3反转为3==mynumber,以此来捕获将相等运算符写成赋值运算符。 2.&&运算符 &&...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:c++primer plus 第六章习题
举报原因:
原因补充:

(最多只允许输入30个字)