⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 ssd5 op6的答案
💻 CPP
字号:
// main.cpp -- driver program for "Sum of Its Parts"

#pragma warning(disable:4786)

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

#include "parts.h"

void load_definitions(char* filename) {

	ifstream inf(filename);
	string part, subpart;
	
	int quantity;
	
	while ( inf.good() ) {
		inf >> part >> quantity >> subpart;
		if ( !inf.good() ) return;
		add_part(part,quantity,subpart);
	};
}

void whatis_query(string const &x) {

	Part* xp = partContainer.lookup(x);
	cout << endl;
	xp->describe();
}

void howmany_query(string const &x, string const &y) {

	Part* xp = partContainer.lookup(x);
	Part* yp = partContainer.lookup(y);
	cout << endl << y << " has " << yp->count_howmany(xp) << " " << x << endl;
}

void process_queries(char* filename) {

	ifstream inf(filename);
	string query, x, y;
	
	while ( inf.good() ) {
		
		inf >> query >> x;
		
		if ( query == "howmany" )
			inf >> y;
    
		if ( !inf.good() ) return;
    
		if ( query == "howmany" )
			howmany_query(x,y);
		else if ( query == "whatis" )
			whatis_query(x);
		else {
			cerr << "*** Illegal query: " << query << endl;
			return;
		};
	};
}

int main(void) {

	load_definitions("definitions.txt");
	process_queries("queries.txt");
	return EXIT_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -