一.问题描述

输入OFF文件,其中OFF文件保存n个点的坐标,第一行为点的个数,从第二行开始,每一行为一个点的三个坐标,例如,cube.OFF文件如下:
8

0 0 0

1 0 0

0 1 0

1 1 0

0 0 1

1 0 1

0 1 1

1 1 1

写一个程序能读入OFF文件,并将输入的点的坐标输出到屏幕上,每行只输出一个点的坐标,要求OFF文件的名称由程序中输入。

 

二.设计思路

三.流程图

四.伪代码 

1

五.代码实现 

1#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
	ifstream file1("C:\\cube.off");
	int i,cnt=0,a[10000],b=0;
	while (file1 >> i) {
		a[b++] = i;
		if (i == a[0])continue;
		cnt++;
		if ((cnt - 1) % 3 == 0) cout << "(";
		cout << i;
		if (cnt % 3 != 0)cout << ",";
		if (cnt % 3 == 0)cout << ")" << endl;
	}
	file1.close();
	return 0;
}

 

posted on 2023-05-15 23:17  leapss  阅读(39)  评论(0)    收藏  举报