adding cs142 code

This commit is contained in:
dm
2016-04-06 20:45:34 -07:00
parent 552d456d53
commit 8e52ce1982
174 changed files with 14064 additions and 0 deletions
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
CPPFLAGS=-Wall -g -std=c++0x
all: person-test person.o
person-test: person-test.cc person.o
person.o: person.cc person.h
clean:
@rm -fv person-test *.o
+17
View File
@@ -0,0 +1,17 @@
#include <iostream>
using std::cout;
using std::endl;
#include "person.h"
int main(int argc, char * argv[])
{
person p;
p.populate_data();
cout << p << endl;
cout << p.as_string() << endl;
person p2("derek mcquay", 21);
cout << p2 << endl;
}
+25
View File
@@ -0,0 +1,25 @@
#include "person.h"
void person::populate_data() {
cout << "enter name: ";
getline(cin, name);
cout << "enter age: ";
cin >> age;
}
string person::as_string() const {
ostringstream stm;
stm << "name: "
<< name
<< ", age: "
<< age;
return stm.str();
}
ostream & operator<<(ostream & os, const person & e) {
os << e.as_string();
return os;
}
+28
View File
@@ -0,0 +1,28 @@
#include <string>
#include <iostream>
#include <ostream>
#include <sstream>
using namespace std;
#pragma once
class person
{
private:
string name;
int age;
public:
person(){};
person(const string name, int age): name(name), age(age){};
string as_string() const;
void populate_data();
// you can define and declare in a header too:
inline int dummy_function() { return 42; };
// this is what allows us to do cout << my_person;
friend ostream & operator<<(ostream & os, const person & e);
};
+17
View File
@@ -0,0 +1,17 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.9~svn20110310 //
CPPFLAGS Makefile /^CPPFLAGS=-Wall -g -std=c++0x$/;" m
age person.h /^ int age;$/;" m class:person
as_string person.cc /^string person::as_string() const$/;" f class:person
dummy_function person.h /^ inline int dummy_function() { return 42; };$/;" f class:person
main person-test.cc /^int main(int argc, char * argv[])$/;" f
name person.h /^ string name;$/;" m class:person
operator << person.cc /^ostream & operator<<(ostream & os, const person & e)$/;" f
person person.h /^ person(){};$/;" f class:person
person person.h /^ person(const string name, int age): name(name), age(age){};$/;" f class:person
person person.h /^class person$/;" c
populate_data person.cc /^void person::populate_data()$/;" f class:person