2025-03-07 10:07:40 +08:00

6.3 KiB
Raw Permalink Blame History

C语言-1

/*------------------------------------------------------------------------------
1【程序设计】下列给定程序中fun函数的功能是分别统计字符串中大写字母和小写字母的个数。
例如给字符串s输入AAaaBBbb123CCcccd则应输出upper6lower8。
------------------------------------------------------------------------------*/
#include <stdio.h>
void fun ( char *s, int *a, int *b)
{
/**********Program**********/
	while(*s != '\0'){
		if(*s >= 'A' && *s <= 'Z'){
			(*a)++;
		}
		if(*s >= 'a' && *s <= 'z'){
			(*b)++;
		}
		s++;
	}


/**********  End  **********/
}
main( )
{
	char s[100];
	int upper=0, lower=0;
	printf( "\nPlease a string : " );
	gets(s);
	fun(s,&upper,&lower);
	printf("\n upper=%d lower=%d\n",upper,lower );
}

C语言-2

/*------------------------------------------------------------------------
题目函数fun的功能将字符串str中第k个字符开始的n个字符逆序重排
例如输入1,5   输出54321abcde
      输入3,6   输出12cba543de
注意部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容仅在
      Program-End之间填入若干语句。不要删除标志否则不得分。
----------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
void fun(char *str, int k, int n )
{
	int i,j;  char t; 
	for(i=k-1,j=k-1+n-1;i<j;i++,j--)
	{ 
/**********Program**********/
		t = str[i];
		str[i] = str[j];
		str[j] = t;

/**********  End  **********/		
	}
}
int main( )
{ 
	char str[]="12345abcde";
	unsigned int k,n;
	scanf("%d,%d",&k,&n);
	if(k+n-1<=strlen(str))
	{          fun(str,k,n);
	puts(str);  }
	else
		printf("所输入的k,n值不合适\n");
	return 0;
}

C语言-3

/*------------------------------------------------------------------
功能:编程统计一个字符串中的字母、数字、空格和其它字符的个数。
---------------------------------------------------------------------*/
#include <stdio.h>
void fun(char s[],int b[])
{
	int i;
/**********Program**********/
	i=0;
	while(s[i] != '\0'){
		if(s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z'){
			b[0]++;
		}else if(s[i] >= '0' && s[i] <= '9'){
			b[1]++;
		}else if(s[i] == ' '){
			b[2]++;
		}else{
			b[3]++;
		}
		i++;
	}

/**********  End  **********/	
}

main ()
{
	char s1[80];int a[4]={0};
	int k;
	void fun(char s[],int b[]) ;
	gets(s1);
	fun(s1,a);
	puts(s1);
	for(k=0;k<4;k++)
		printf("%4d",a[k]);
}

C语言-4

/*------------------------------------------------------------------------
程序功能:从键盘输入三个整数,比较三个数并显示相应信息,具体如下:
1如果三个数都相等显示"***"
2如果三个数中只有某两个数相等显示"@@"
3如果三个数互不相等则显示"&"。
(输出要换行)
------------------------------------------------------------------------
注意部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容仅在
      Program-End之间删除【?】填入若干语句。不要删除标志否则不得分。
----------------------------------------------------------------------*/
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b && b==c) 
 printf("***\n");
/**********Program**********/
	else if(a==b || b==c || a==c)




/**********  End  **********/
printf("@@\n");
    else  printf("&\n");

    return 0;
}

MySQL-1

#1
CREATE TABLE t_hotel_manager(
	mid INT PRIMARY KEY,
	hid INT NOT NULL,
	mname VARCHAR(10) NOT NULL,
	mage INT NOT NULL,
	mgender ENUM('男', '女', '未知'),
	telephone VARCHAR(11)
);
#2
#使用MODIFY添加主键字段为自动增长
ALTER TABLE t_hotel_manager MODIFY mid INT  AUTO_INCREMENT;
#设置自增起始值
ALTER TABLE t_hotel_manager AUTO_INCREMENT = 1000;
#3
INSERT INTO t_hotel_manager()
VALUES(DEFAULT, 10001, '王璐', 32, '女', NULL);
#4
CREATE TABLE t_hotel_bak AS
SELECT *
FROM t_hotel;
#5
UPDATE t_client c
SET c.integral = c.integral + 100
WHERE c.cname LIKE '姚%';
#6 tj11
SELECT c.cname, SUM(r.price)
FROM t_booking b, t_client c, t_room r
WHERE b.cid = c.cid AND b.rid = r.rid
GROUP BY c.cid
ORDER BY 2 DESC
LIMIT 9, 1;

#7 tj12
SELECT h.hname, r.price
FROM t_hotel h, t_room r
WHERE h.hid = r.hid AND r.rname = '大床房' AND r.price = (
	SELECT MAX(price)
	FROM t_room 
	WHERE rname = '大床房'
);

#8 tj13
SELECT h.hname, r.rname, r.price
FROM t_room r
LEFT JOIN t_booking b ON r.rid = b.rid
INNER JOIN t_hotel h ON r.hid = h.hid
WHERE b.bid IS NULL;

#9 视图
CREATE VIEW v_tongji AS
SELECT h.hname, SUM(r.price)
FROM t_hotel h, t_booking b, t_room r
WHERE h.hid = r.hid AND b.rid = r.rid
GROUP BY h.hid;

MySQL-2

#1添加主键
ALTER TABLE tb_student ADD PRIMARY KEY(student_id);

#2设置默认值
ALTER TABLE tb_student ALTER gender SET DEFAULT '男';

#3 插入记录
INSERT INTO tb_student()
VALUES(10025, '张三', DEFAULT, '2012-10-01', 1001);

#4 更新记录
UPDATE tb_teacher t
SET t.teacher_age = 36
WHERE t.teacher_name = '王老师';

#5 tj11
SELECT MAX(t.teacher_age)
FROM tb_teacher t;

#6 tj12
SELECT c.class_name, s.student_name, s.gender
FROM tb_teacher t, tb_student s, tb_class C
where s.class_id = c.class_id AND c.teacher_id = t.teacher_id;

#7 视图
CREATE VIEW v_teacher AS
SELECT c.class_name, t.teacher_name, COUNT(*)
FROM tb_teacher t, tb_student s, tb_class C
WHERE s.class_id = c.class_id AND c.teacher_id = t.teacher_id
GROUP BY c.class_id, t.teacher_name;

#8
DELIMITER $$
DROP TRIGGER IF EXISTS tri_updateTeacherAge;
CREATE TRIGGER tri_updateTeacherAge
BEFORE UPDATE ON tb_teacher
FOR EACH ROW
BEGIN
		IF NEW.teacher_age < 30 THEN
			SET NEW.age = '青年';
		ELSEIF NEW.teacher_age < 50 THEN
			SET NEW.age = '中年';
		ELSE
			SET NEW.age = '老年';
		END IF;
END $$
DELIMITER ;

#9
DELIMITER $$
DROP PROCEDURE IF EXISTS Pro_GetOldClassStudent;
CREATE PROCEDURE Pro_GetOldClassStudent(IN in_class_id INT, OUT out_student_name VARCHAR(50))
BEGIN
	SELECT s.student_name INTO out_student_name
	FROM tb_student s, tb_class c
	WHERE s.class_id = c.class_id AND c.class_id = in_class_id
	ORDER BY s.birthday
	LIMIT 1;
END $$
DELIMITER ;

CALL Pro_GetOldClassStudent(1001, @result);
SELECT @result;