第六章

  • 实验作业

1.调试分析课本每一个例题,有可能的话更改成2-3个方法的新程序;

2.编程实现课本每一个编程习题。

3. 有n个人围成一个圆圈,从第一个人开始报数,从1到3循环,凡是报3的退出圈子,问最后退出圈子的人是原来的几号。

4.一个班有5个学生,每一个学生有几门成绩(到底是几门自已定,或3或4或5或6),定义函数来完成下面功能:

    计算第2门课成的平均分;

    找出有2门以上成绩不及格的学生,并输出其学号和全部课程成绩;

    找出平均成绩在90以上或者全部课程在85分以上的学生。

1、

(1)

#include<iostream>
using namespace std;

int main()
{
	int a=10;
	int*p;
	p=&a;
	cout<<"a="<<a<<endl;
	cout<<"p="<<p<<endl;
	cout<<"&a"<<&a<<endl;
	cout<<"*p="<<*p<<endl;
	cout<<"&p="<<&p<<endl;
	cout<<endl;
	*p=15;
	cout<<"a="<<a<<endl;
	cout<<"p="<<p<<endl;
	cout<<"&a"<<&a<<endl;
	cout<<"*p="<<*p<<endl;
	cout<<"&p="<<&p<<endl;

	return 0;
}


(2)

#include<iostream>
using namespace std;

int main()
{
	int a,b,temp;
	int*p=&a,*q=&b;
	cout<<"please input a and b:";
	cin>>a>>b;
	cout<<"初始的两个数为:"<<a<<" "<<b<<endl;
	if(a>b)
	{
		temp=*p;*p=*q;*q=temp;
	}
	cout<<"从大到小排序后的数为:"<<*p<<" "<<*q<<endl;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int a=10,b=10,*ptr1,*ptr2;
	ptr1=&a;
	ptr2=&b;
	cout<<boolalpha<<(*ptr1==*ptr2)<<endl;
	cout<<boolalpha<<(ptr1==ptr2)<<endl;

	return 0;
}

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
	int a[10];
	for(int i=0;i<10;i++)
		a[i]=2*(i+1);
	for(i=0;i<10;i++)
		cout<<setw(4)<<a[i];
	cout<<endl;

	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	char a[]="Hello werld",b[20],*p,*q;
	p=a,q=b;
	for(;*p!='\0';p++,q++)
		*q=*p;
	*q='\0';
	cout<<"string1 is:";
	cout<<a<<endl;
	cout<<"string2 is:";
	cout<<b<<endl;

	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	char*p="student";
	for(;*p!='\0';p++)
		cout<<p<<endl;

	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	char*p="student";
	for(int i=0;p[i]!='\0';i++)
		cout<<p[i];
	cout<<endl;
	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	char s[50];
	char*p=s;
	cout<<"please input a string:";
	cin.get(p,50);
	for(;*p!='\0';)
		p++;
	cout<<"the length is:"<<p-s<<endl;

	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int a[10],i,*p;
	for(i=0;i<10;i++)
	{
		a[i]=(i+1)*2;
	}
	p=a;
	for(i=0;i<10;i++)
	{
		cout<<p[i]<<" ";
	}
	cout<<endl;

	return 0;
}


#include<iostream>
using namespace std;

void lower(char *);

int main()
{
	char zf[50];
	cout<<"请输入一个大写字符串:";
	cin.get (zf,50);
	lower(zf);
	cout<<"转换为小写字符串为:"<<zf<<endl;
	return 0;
}

void lower(char p[])
{
	for(;*p!='\0';p++)
	{
		if(*p<='Z'&&*p>='A')
		*p+=32;

	}
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值