做练习题
来源:互联网 发布:游族网络百度广告图片 编辑:程序博客网 时间:2024/04/29 08:37
第一题:c语言的
/*
小明从2006年1月1日开始,每三天结识一个美女两天结识一个帅哥,编程实现当输入2006年1月1日之后的任意一天,输出小明那天是结识美女还是帅哥(注意润年问题)(C语言)
记录点:如何判断闰年闰月 记住公式 和判断方法 其他不重要 多练习如何判断就好了
*/
#import <Foundation/Foundation.h>
int sumDay(int y ,int m ,int d);
int main(int argc,constchar * argv[]) {
@autoreleasepool {
int year , month , day ;//输入年月日
printf("请输入年\n:");
scanf("%d",&year);
printf("请输入月\n:");
scanf("%d",&month);
printf("请输入日\n:");
scanf("%d",&day);
int x = sumDay(year, month, day);
printf("从2006年1月1日到%d年%d月%d日一共%d天\n",year,month,day,x);//输出总天数
if(x % 2 ==0)//判断2天
{
printf("小明今天遇到帅哥了\n");
}else if(x %3 ==0)//判断3天
{
printf("小明今天遇到美女了\n");
}else{
printf("小明今天遇到难题了\n");//其他天
}
}
return 0;
}
int sumDay(int y ,int m ,int d)
{
int day = d - 1;//天数
int yearDay = 0;//年数的总天数
int monthDay = 0;//月数的总天数
int rYear [12] = {31,29,31,30,31,30,31,30,31,30,31,30};//每个月的天数
int pYear [12] = {31,28,31,30,31,30,31,30,31,30,31,30};//平常年每个月的天数
int yc = y - 2006;//年数差
int mc = m -1;//月入当月不加入天数计算
int dy = 2006;//基础年;
for(int i =0 ; i < yc ; i ++)//判断是否为润年如果是按照366计算天数如果不是按照365计算
{
if((dy + i)% 4 == 0 && (dy + i) % 100 != 0 )
{
yearDay += 366;
}else if((dy + i) %400 ==0)
{
yearDay += 366;
}else{
yearDay += 365;
}
}
for (int j =0; j < mc; j++) {//计算月数如果是闰年按照闰年月的天数想家 如果不是反之
if(y % 4 ==0 && y %100 !=0)
{
monthDay += rYear[j];
}else if(y %400 ==0)
{
monthDay += rYear[j];
}else{
monthDay += pYear[j];
}
}
return yearDay + monthDay + day;//返回年的总天数月的总天数和天数的总和
return 0;
}
-------------------------------------------------------
第二题 oc的学生成绩对比
/*入学测试题:10
要求:定义一个学生类,需要有性命,年龄,考试成绩三个成员属性,创建5个学生对象,属性可以任意值
1>不使用@property,手动编写setter,getter注意内存管理
2>增加一个便利构造器
3>使用NSLog输出学生对象时,输出信息格式为:My Name Is xxx Age Is xxx Score Is xxx
4>对5个学生对象按照成绩-年龄-姓名优先级排序成绩相同按照年龄,年龄相同按照姓名的顺序排序
思路:创建一个数组将学生属性导入进去
编写一个方法对比学生分数年龄姓名的大小
*/
Student类.h文件
#import <Foundation/Foundation.h>
@interface Student : NSObject
{
//手动定义3个属性
int _score;
int _age;
NSString *_name;
}
//setter getter
- (void)setScore:(int)score;
- (void)setAge:(int)age;
- (void)setName:(NSString *)name;
- (int)score;
- (int)age;
- (NSString *)name;
//重写构造方法带参数
- (id)initWithName:(NSString *)name andScore:(int)score andAge:(int)age;
//判断 分数 年龄 姓名的类方法
+ (BOOL)isEqStu1:(Student *)stu1 andStu2:(Student *)stu2;
@end
-----------------------------------------------
Student类.m文件
#import "Student.h"
@implementation Student
// setter getter方法
- (void)setScore:(int)score
{
_score = score;
}
- (void)setAge:(int)age
{
_age = age;
}
- (void)setName:(NSString *)name
{
_name = name;
}
- (int)score
{
return _score;
}
- (int)age
{
return _age;
}
- (NSString *)name
{
return _name;
}
//重新定义description方法
- (NSString*)description
{
return [NSStringstringWithFormat:@"My Name Is %@, My Score Is %d , My Age Is %d",_name,_score,_age];
}
//重写构造类型
- (id)initWithName:(NSString *)name andScore:(int)score andAge:(int)age
{
if(self = [superinit])
{
_name = name;
_score = score;
_age = age;
}
return self;
}
//判断成绩年龄姓名
+ (BOOL)isEqStu1:(Student *)stu1 andStu2:(Student *)stu2
{
if(stu1.score > stu2.score)//判断分数
{
return NO;
}else if(stu1.score < stu2.score)//前面的小于后面调换位置
{
return YES;
}else
{
if(stu1.age > stu2.age)//如果分数相同判断年龄
{
return NO;
}else if(stu1.age < stu2.age )//前面小于后面的调换位置
{
return YES;
}else{
//名字的排序是按照由a-z的先后顺序排列的想电话簿一样
switch([stu1.namecompare:stu2.name]){
case 1:
return YES;//如果前面大于后面调换
break;
case -1:
return NO;//前面小于后面不掉换
break;
case 0:
return NO;//相同也不掉换
break;
}
}
}
}
@end
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc,constchar * argv[]) {
@autoreleasepool {
//定义5个学生
Student *stu = [[Studentalloc]initWithName:@"alucy"andScore:90andAge:20];
Student *stu1 = [[Studentalloc]initWithName:@"blucy"andScore:90andAge:20];
Student *stu2 = [[Studentalloc]initWithName:@"clucy"andScore:90andAge:20];
Student *stu3 = [[Studentalloc]initWithName:@"dlucy"andScore:90andAge:20];
Student *stu4 = [[Studentalloc]initWithName:@"elucy"andScore:90andAge:20];
//定义一个可变数组存放学生对象
NSMutableArray *array =[NSMutableArrayarrayWithObjects:stu,stu1,stu2,stu3,stu4,nil];
//定义一个学生对象作为冒泡法的接收对象
Student *s = [[Studentalloc]init];
//冒泡排序法
for(int i =0; i < array.count;i++)
{
for(int j = i+1 ;j < array.count ;j++)
{
//调用判断方法
if([StudentisEqStu1:array[i]andStu2:array[j]])
{
s = array[i];
array[i] = array[j];
array[j] = s;
}
}
NSLog(@"%@",array[i]);//遍历打印数组对象
}
}
return 0;
}
-----------------------------------------------------------------------------------------
/*
编写一个学生管理系统程序,用来记录学生的信息(包括姓名、年龄、性别、学号、分数),提供增加、删除、查询学生信息的入口。(C语
*/
#import <Foundation/Foundation.h>
struct student {
char name[20];
int age;
char sex[20];
int number;
int score;
};
struct student stu[100];
int z = 0;
void caidan();
void zengjia();
void chaxun();
void shanchu();
void tuichu();
int main()
{
caidan();
if(z > 90)
{
tuichu();
}
return 0;
}
void caidan(){
printf(" 欢迎进入菜鸟写的学生管理系统---如果中途崩溃请直接重启电脑不谢 \n");
printf(" ---> 广告切入还剩5s 我是angelaByeBye欢迎一起来玩大战神,我要一个上3个 <--- \n");
printf(" 增加学生信息请按1号键 \n");
printf(" 查找学生信息请按2号键 \n");
printf(" 删除学生信息请按3号键 \n");
printf(" 退出学生系统请直接关闭电源 \n:");
int t = 0;
scanf("%d",&t);
if(t == 1)
{
zengjia();
}else if(t ==2)
{
chaxun();
}else if(t ==3)
{
shanchu();
}else{
tuichu();
}
}
void zengjia(){
printf("请输入学生姓名:\n");
scanf("%s",stu[z].name);
printf("请输入学生年龄:\n");
scanf("%d",&stu[z].age);
printf("请输入学生性别:\n");
scanf("%s",stu[z].sex);
printf("请输入学生学号:\n");
scanf("%d",&stu[z].number);
for (int i =0; i < z ; i++) {//这里要说明一下i<z这里是不把当前的学号计算在for循环的查询范围
while (stu[i].number ==stu[z].number) {
printf("学号存在请重新输入\n");
scanf("%d",&stu[z].number);
}
}
printf("请输入学生成绩:\n");
scanf("%d",&stu[z].score);
printf(" 姓名:%s 年龄:%d 性别:%s学号:%d 成绩:%d\n ~:>@~:>@~:>@~:>@~:>@~:>@~:>@\n",stu[z].name,stu[z].age,stu[z].sex,stu[z].number,stu[z].score);
z++;
caidan();
}
void chaxun(){
printf("请输入要查询的学号\n:");
int a = 0;
scanf("%d",&a);
for(int i =0 ; i <= z ; i++)//这里i<=z是把当前的学号加入到查询范围
{
if(stu[i].number == a)
{
printf(" 姓名:%s 年龄:%d 性别:%s学号:%d 成绩:%d\n ~:>@~:>@~:>@~:>@~:>@~:>@~:>@\n",stu[i].name,stu[i].age,stu[i].sex,stu[i].number,stu[i].score);
break;
}
elseif(i == z)//如果是最后一次遍历就直接提示没有然后退出循环
{
printf("没有相关学号\n");
break;//好像多余
}
}
caidan();
}
void shanchu(){
printf("请输入要删除的学号\n:");
int a = 0;
scanf("%d",&a);
for(int i =0 ; i <= z ; i++)
{
if(stu[i].number == a)
{
stu[i] = stu[ z + 1];
printf("删除成功\n");
break;
}
else if(i ==z)
{
printf("没有相关学号\n");
break;
}
}
caidan();
}
void tuichu(){
printf("感谢使用菜鸟写的学生管理系统\n\n\n\n回见!!\n");
printf("电脑正在关机中,稍后.................................................\n");
}
- 做练习题
- 做的C语言练习题
- (Sql)考试前做的练习题...
- 自做算法导论第一章练习题
- 用perl做ProjectEuler练习题01
- JAVA练习题,能做多少就做多少
- JAVA练习题,能做多少就做多少
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 练习题
- 安卓网络框架,上传图片花图,上传状态411被服务器驳回
- VMware Workstation12Pro 安装CentOS7 ISO,vmware 安装CentOS7
- jar文件的深入认识
- SQL语言的组成
- char*,const char*, string,int之间的转换
- 做练习题
- centos 配置jdk里面的注意事项
- iOS 锁屏后暂停歌曲的方法设置
- Maven的pom.xml介绍
- Maven 项目不打包 *.hbm.xml 映射文件
- uva442
- OpenGL圆形绘制算法
- 实时分布式具备高容错性的计算系统storm------核心topology架构图和storm运行topology的工作流程图
- JVM指令详解(上)