2021-01-26

程序流程结构

选择结构

/*单行if语句*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//选择结构 单行if语句
	//用户输入分数,若分数大于600,视为考上一本大学
	//注意事项 if条件语句后不要加分号
	int score = 0;
	cout << "请输入你的分数: " << endl;
	cin >> score;
	cout << "您输入的分数为:" << score << endl;
	if (score > 600)
	{
		cout << "恭喜您考上了一本大学" << endl;
	}
	system("pause");
	return 0;
}
/*多行if语句*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//选择结构 多行if语句
	//用户输入分数,若分数大于600,视为考上一本大学
	//若没考上一本大学,则打印未考上一本大学
	//注意事项 if条件语句后不要加分号
	int score = 0;
	cout << "请输入你的分数: " << endl;
	cin >> score;
	cout << "您输入的分数为:" << score << endl;
	if (score > 600)
	{
		cout << "恭喜您考上了一本大学" << endl;
	}
	else
		cout << "很遗憾您未考上一本大学" << endl;
	system("pause");
	return 0;
}
/*练习题:三只小猪称体重*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//三只小猪ABC,请分别输入体重,并判断哪只小猪最重
	
	int weight_A = 0;
	cout << "请输入小猪A的体重:" << endl;
	cin >> weight_A;
	cout << "小猪A的体重为:" << weight_A << endl;
	int weight_B = 0;
	cout << "请输入小猪B的体重:" << endl;
	cin >> weight_B;
	cout << "小猪B的体重为:" << weight_B << endl;
	int weight_C = 0;
	cout << "请输入小猪C的体重:" << endl;
	cin >> weight_C;
	cout << "小猪C的体重为:" << weight_C << endl;
	if (weight_A > weight_B)
	{
		if (weight_A > weight_C)
			cout << "小猪A最重" << endl;
		else
			cout << "小猪C最重" << endl;
	}
	else 
	{
		if (weight_B > weight_C)
			cout << "小猪B最重" << endl;
		else
			cout << "小猪C最重" << endl;
	}
	

	system("pause");
	return 0;
}

三目运算符

表达式1 ?表达式2:表达式3
如果1为真,则执行2,返回2的结果
如果1为假,则执行3,返回3的结果

/*三目运算符*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//创建三个变量a b c
	//将a和b做比较,大的赋值给c
	int a = 20;
	int b = 10;
	int c = 0;
	c = (a > b ? a : b);
	cout << "c=" << c << endl;
	//三目运算符返回的是变量,可以继续赋值
	(a > b ? a : b) = 100;
	cout << "a=" << a << endl;//a=100
	cout << "b=" << b << endl;//b=10
	system("pause");
	return 0;
}

switch语句

/*switch语句*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//给电影打分
	cout << "请给电影进行打分:" << endl;
	int score = 0;
	cin >> score;
	cout << "您打的分数为:" << score << endl;
	switch (score)
	{
	case 10:
		cout << "您认为是经典电影" << endl;
		break;//退出当前分支
	case 9:
		cout << "您认为是经典电影" << endl;
		break;
	case 8:
		cout << "您认为是好电影" << endl;
		break;
	default:
		cout << "您认为是烂片" << endl;
		break;
	}
	//switch缺点 判断时候只能是整型或字符型
	//switch优点 结构清晰,执行效率高
	system("pause");
	return 0;
}

循环结构

/*while循环*/
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//打印0~9
	int num = 0;
	//在循环中避免出现死循环
	while (num < 10)
	{
		
		cout << num << " ";
		num++;
	}
	system("pause");
	return 0;
}
/*while循环练习案例:猜数字*/
#include <iostream>
#include <ctime>
using namespace std;

int main()
{
	//计算机生成1~100的数字,玩家猜,提示过大或过小,猜对恭喜玩家胜利并退出游戏
	//添加随机数种子,防止生成伪随机数
	srand((unsigned int)time(NULL));
	int num = rand() % 100 + 1;//rand() % 100生成0~99的随机数
	
	int val = 0;
	while (1)
	{
		cin >> val;
		if (val > num)
			cout << "过大" << endl;
		else if (val < num)
			cout << "过小" << endl;
		else
		{
			cout << "猜对了" << endl;
			break;
		}
	}	
	system("pause");
	return 0;
}
/*do while语句*/
#include <iostream>
#include <ctime>
using namespace std;

int main()
{
	//在屏幕中输出0~9的数字
	int num = 0;
	do
	{
		cout << num << " ";
		num++;
	} while (num < 10);
	//do while 会先执行一次循环语句
	system("pause");
	return 0;
}
/*水仙花数*/
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int main()
{
	//三位数,每个位上的数字的三次幂的和为它本身
	//用do...while语句求出所有三位数中的水仙花数
	int num = 100;
	do
	{
		int a = 0;
		a = num / 100;
		int b = 0;
		b = (num / 10) % 10;
		int c = 0;
		c = num % 10;
		int d = 0;
		d = a * a*a + b * b*b + c * c*c;
		if(d == num)
			cout << num << " ";
		
		num++;
		
	} while (num < 1000);
	//do while 会先执行一次循环语句
	system("pause");
	return 0;
}
/*for循环练习案例:敲桌子*/
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int main()
{
	//1~100,含7或是7的倍数,输出敲桌子,其余数字直接输出
	
	for (int num = 1; num <= 100; num++)
	{
		int a = num % 7;//7的倍数
		int b = num % 10;//个位有7
		int c = num / 10;//十位有7
		if (a == 0 || b == 7 || c == 7)
		{
			cout << "敲桌子" << " ";
		}
		else
			cout << num << " ";
	}
	
	system("pause");
	return 0;
}
/*嵌套循环*/
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int main()
{
	//打印10*10星图
	
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cout << "* ";
		}	
		cout << endl;
	}
	
	system("pause");
	return 0;
}
/*嵌套循环案例:乘法口诀表*/
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int main()
{
	//打印10*10星图
	
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			cout << i << "*" << j << "=" << i * j << " ";
		}	
		cout << endl;
	}
	
	system("pause");
	return 0;
}

跳转语句

break语句

在switch条件语句中,终止case并跳出switch
在循环语句中,跳出当前的循环语句
在嵌套循环中,跳出最近的内层循环

continue语句

在循环语句中,跳过本次循环中余下尚未执行的语句,继续执行下一次循环

goto语句

不推荐使用,影响代码结构

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值