首页 > 其他分享 >cpp: Two-level pointer and double dimensional array

cpp: Two-level pointer and double dimensional array

时间:2023-06-30 21:22:35浏览次数:40  
标签:level int double Two ++ allstr rowNum include append

/*****************************************************************//**
 * \file   ConsoleTextFileDemoApp.cpp  c++ 14
 * \brief   
 * 
 * 
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
// ConsoleTextFileDemoApp.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//https://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new
//geovindu Geovin Du
#define _UNICODE

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <windows.h>
#include <string>
#include <string.h>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <codecvt>
#include <assert.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <io.h>
#include <vector>

using namespace std;

/// <summary>
/// 打印二维数组 
/// </summary>
/// <param name="p"></param>
/// <param name="rowNum">行</param>
/// <param name="coluNum">列</param>
void PrintPtr(int** p, int rowNum, int coluNumn)
{
	for (int i = 0; i < rowNum; i++)
	{
		for (int j = 0; j < coluNumn; j++)
			cout << p[i][j] << "	";
		cout << endl;
	}
}
/// <summary>
/// 
/// </summary>
/// <param name="arry"></param>
/// <param name="row"></param>
void PrintAr2(int arry[][9], int row)
{
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < 9; j++)
			cout << arry[i][j] << "	";
		cout << endl;
	}
}

/// <summary>
/// 打印二维数组 
/// </summary>
/// <param name="p"></param>
/// <param name="rowNum"></param>
/// <param name="coluNum"></param>
void print_p(int** p, int rowNum, int coluNum)
{
	cout << "\n------------------------" << endl;
	for (int i = 0; i < rowNum; i++)
	{
		for (int j = 0; j < coluNum; j++)
		{
			cout << p[i][j] << " ";
		}
		cout << endl;
	}
}

/// <summary>
/// 
/// </summary>
/// <param name="p"></param>
/// <param name="RowSize"></param>
/// <param name="LineSize"></param>
void print_array(int* p, int RowSize, int LineSize)
{
	int i, j;
	for (i = 0; i < RowSize; i++)
	{
		for (j = 0; j < LineSize; j++)
			printf("%d ", *(p + i * LineSize + j));
		printf("\n");
	}
}

/// <summary>
/// 初始化二维数组,即给指针p分配内存。这里注意要使用引用 
/// </summary>
/// <param name="p"></param>
/// <param name="rowNum"></param>
/// <param name="coluNum"></param>
void init_p(int**& p, int* rowNum, int* coluNum)
{
	cin >> *rowNum >> *coluNum;
	p = new int* [*rowNum];
	for (int i = 0; i < *rowNum; i++)
	{
		p[i] = new int[*coluNum];
	}
}

int main(void)
{
    std::cout << "Hello World! 涂聚文! \n";

    //string duname;
    //cout << "输入姓名:" << endl;
    //cin >> duname;
    //cout << "name:" << duname << endl;
	int sudoku[9][9] = {
	{0, 0, 0, 0, 0, 9, 0, 5, 0},
	{0, 0, 8, 0, 0, 0, 0, 7, 9},
	{0, 0, 1, 5, 0, 2, 0, 0, 0},
	{3, 0, 0, 0, 1, 0, 5, 0, 7},
	{2, 0, 4, 0, 0, 7, 0, 0, 0},
	{0, 0, 0, 6, 0, 0, 2, 0, 0},
	{0, 0, 0, 0, 7, 0, 3, 4, 0},
	{1, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 3, 0, 0, 5, 6, 0, 0, 0}
	};

	int** p = new int* [9];
	for (int i = 0; i < 9; i++)
		p[i] = new int[10];
	for (int i = 0; i < 9; i++)
	{
		for (int j = 0; j < 9; j++)
			p[i][j] = sudoku[i][j];
	}
	cout << "传递数组名" << endl;
	PrintAr2(sudoku, 9);
	cout << "传递指针" << endl;
	PrintPtr(p, 9, 9);

	int i, j;
	print_array((int*)sudoku, 9, 9);
	cout << "***********" << endl;
	for (i = 0; i <9; i++)
	{
		for (j = 0; j < 9; j++)
			printf("%d ", *(*(sudoku + i) + j));
		printf("\n");
	}

	wstring allstr;
	wstring sname;
	wstring stuID;//学号
	int num;//编号
	double english;//英语成绩
	double math;//数学成绩
	double cpp;//C++成绩
	int location = 0;//位置编号
	int flag = 0;//标记是否有对应的编号

	wcout << L"请输入新增学生的信息" << endl;
	wcout << L"姓名\t" << "学号\t" << "英语\t" << "数学\t" << "C++\t" << endl;
	wcin.imbue(locale("chs"));//获取的是中文
	wcout.imbue(locale("chs"));
	wcin >> sname >> stuID >> english >> math >> cpp;

	//allstr = sname + ' ' + stuID;
	allstr.append(sname); //C++ wstring::append
	allstr.append(L"\t");
	allstr.append(stuID);
	allstr.append(L"\t");
	allstr.append(to_wstring(english));
	allstr.append(L"\t");
	allstr.append(to_wstring(math));
	allstr.append(L"\t");
	allstr.append(to_wstring(cpp));

	wcout << allstr << endl;
    system("pause");
    return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#define UNICODE

  

标签:level,int,double,Two,++,allstr,rowNum,include,append
From: https://www.cnblogs.com/geovindu/p/17517844.html

相关文章

  • vulnhub靶场:doubletrouble
    靶场地址:doubletrouble:1~VulnHubkali:172.88.6.144靶场:172.88.6.89靶场2:172.88.6.91arp-scan-l  nmap-A-sV-T4-p-172.88.6.89 访问ip 使用dirsearch对目标站点进行Web目录爬取dirsearch-uhttp://172.88.6.89/-e*   将图片下载好,放到kali中,自......
  • 浮点数-Float-Double转二进制在线工具
    浮点数-Float-Double转二进制Float转二进制,Double转浮点数-Float-Double转二进制https://tooltt.com/floatconverter/在线单双精度(Float,Double)浮点数转二进制浮点数,是属于有理数中某特定子集的数的数字表示,在计算机中用以近似表示任意某个实数。具体的说,这个实数由一......
  • Dual Path Network(DPN)
    论文地址:https://arxiv.org/pdf/1707.01629.pdf模型及代码:github.com/cypw/DPNs本文认为:1)ResNet通过这种跨层参数共享和保留中间特征的方式,特征re-use,ResNet将输出与输入相加,形成一个残差结构,可以有效的降低特征上冗余度,重复利用已有特征,但缺点在于难以利用高层信息再发掘底层特......
  • Visualizing and Understanding Convolutional Networks
    《VisualizingandUnderstandingConvolutionalNetworks》 MatthewDZeiler,RobFergus(ECCV2014) 论文:http://t.cn/RyYKQ8z视频: http://t.cn/RyYKQ87------------------------------------------------------------------------------------------------------一、相关......
  • 【五期邹昱夫】CCF-B(IEEE Access'19)Badnets: Evaluating backdooring attacks on deep
    "Gu,Tianyu,etal."Badnets:Evaluatingbackdooringattacksondeepneuralnetworks."IEEEAccess7(2019):47230-47244."  本文提出了外包机器学习时选择值得信赖的提供商的重要性,以及确保神经网络模型安全地托管和从在线存储库下载的重要性。并展示了迁移学习场......
  • 【五期邹昱夫】CCF-B(RAID'18)Fine-Pruning: Defending Against Backdooring Attacks on
    "Liu,Kang,BrendanDolan-Gavitt,andSiddharthGarg."Fine-pruning:Defendingagainstbackdooringattacksondeepneuralnetworks."ResearchinAttacks,Intrusions,andDefenses:21stInternationalSymposium,RAID2018,Heraklion,Crete,......
  • Codeforces 1648F - Two Avenues
    为啥会有人觉得这是板子题啊/tuu先对图边双连通分量缩个点,然后考虑对两条边分情况讨论:两个桥边,显然答案就是经过这两个桥的路径数量之和,排序取前两大的即可。一个桥边加一个非桥边,答案是经过那个桥边的路径数量,显然桥边数量\(\ge2\)肯定不用考虑这种情况,桥边数量\(=1\)另......
  • Maven构建项目后项目报Error错误Java compiler level does not match the version of
     Maven构建项目后项目报Error错误JavacompilerleveldoesnotmatchtheversionoftheinstalledJavaprojectfac 项目->右键->Properties->ProjectFacets->修改facets中Java版本(下拉箭头出)为要用的版本Maven构建项目需注意1.项目右键->Properties->buildpath->jdk2.项......
  • CF1144G Two Merged Sequences
    CF1144GTwoMergedSequences题意现在给你一个长度为\(n\)的序列你要把它拆成一个严格递增序列和一个严格递减序列如果不可行输出\(NO\)如果可行输出\(YES\)并输出每个数属于递增序列还是递减序列题解感觉脑子瓦特了,感觉这个\(dp\)的状态设计是比较自然的。首先我们考......
  • F5APM第七期Network Access模式配置
    F5APM第七期NetworkAccess模式配置’......