All pastes #2283 Raw Edit

thing.cpp

public cpp v1 · immutable
#2283 ·published 2004-11-24 00:18 UTC
rendered paste body
// CS227 - Intro to Programming// Section G1// Homework assignment #11// http://www.cs.iastate.edu/~cs227/Assign/hw11/hw11.html//// Author://   Kevin Godby <godbyk@cs.iastate.edu>//// Play around with anachronistic C-strings#include "thing.h"#include <iostream>using namespace std;void show (thing T){	// POST: the thing displayed (in any readable format)	//       output cursor at start of new line	cout << "W: [" << T.W << "] Nums: ";	cout << T.Nums[0];	for (int i = 1; i < T.nsz; i++) {		cout << ", " << T.Nums[i];	}	cout << endl;}                  void mix (thing& T, const char S[]){	// TODO: Test maximums -- i.e., try to break me.	// TODO: Optimize		unsigned int Tpos = 0, Spos = 0;	char newString[81];		int i = 0;	size_t size  = sizeof (S) / sizeof (S[0]);	cerr << "DEBUG: S           = '" << S << "'" << endl;	cerr << "DEBUG: sizeof(S)   = " << size << endl;	while (Tpos < sizeof(T.W) && Spos < sizeof(S)) {		newString[i] = T.W[Tpos];		Tpos++;		newString[++i] = S[Spos];		Spos++;		i++;	}		// Exhausted one or both, append remainder	while (Tpos < sizeof(T.W)) {		newString[i] = T.W[Tpos];		Tpos++;		i++;	}		while (Spos < sizeof(S)) {		newString[i] = S[Spos];		Spos++;		i++;	}		int max = sizeof(newString);	if (max > 40) max = 40;			for (i = 0; i <= max; i++) {		T.W[i] = newString[i];	}		T.W[i+1] = '\0';	}void addNums (thing& T, int K[], int ksz){	// PRE: T.nsz set to size of T.Nums; ksz size of K	// POST: K added to end of Nums, up to 30}thing getCombined (thing T1, thing T2){	// PRE: T1, T2 set-up properly	// POST: return value has T1+T2 (added to end) truncated as needed}