首页 > > 详细

辅导留学生C设计、C++编程解析、调试C++、C++讲解、辅导C++编程

Other Requirements
Regardless of how much work you put into the assignment, your program will receive a low score for correctness if you violate these requirements:

Your class definition, declarations for the two required non-member functions, and the implementations of any functions you choose to inline must be in a file named PeopleList.h, which must have appropriate include guards. The implementations of the functions you declared in PeopleList.h that you did not inline must be in a file named PeopleList.cpp. Neither of those files may have a main routine (unless it’s commented out). You may use a separate file for the main routine to test your PeopleList class; you won’t turn in that separate file.

Except to add a destructor, copy constructor, assignment operator, and dump function (described below), you must not add functions to, delete functions from, or change the public interface of the PeopleList class. You must not declare any additional struct/class outside the PeopleList class, and you must not declare any public struct/class inside the PeopleList class. You may add whatever private data members and private member functions you like, and you may declare private structs/classes inside the PeopleList class if you like. The source files you submit for this project must not contain the word friend. You must not use any global variables whose values may be changed during execution.

If you wish, you may add a public member function with the signature void dump() const. The intent of this function is that for your own testing purposes, you can call it to print information about the map; we will never call it. You do not have to add this function if you don’t want to, but if you do add it, it must not make any changes to the map; if we were to replace your implementation of this function with one that simply returned immediately, your code must still work correctly. The dump function must not write to cout, but it’s allowed to write to cerr.

Your code must build successfully (under both g32 and either clang++ or Visual C++) if linked with a file that contains a main routine.

You must have an implementation for every member function of PeopleList, as well as the non-member functions combine and search. Even if you can’t get a function implemented correctly, it must have an implementation that at least builds successfully. For example, if you don’t have time to correctly implement PeopleList::remove or search, say, here are implementations that meet this requirement in that they at least build successfully:

12345678910
 bool PeopleList::remove(const std::stringamp; fname, cont std::stringamp; lname)#123;  return false;  // not correct, but at least this compiles#125;void search(const std::stringamp; fsearch, const std::stringamp; lsearch,            const PeopleListamp; p1, PeopleListamp; result)#123;  // does nothing; not correct, but at least this compiles#125;
 

You’ve probably met this requirement if the following file compiles and links with your code. (This uses magic beyond the scope of CS 32.)
123456789101112131415161718192021222324252627282930
 #include "PeopleList.h"#include lt;type_traitsgt;#define CHECKTYPE(f, t) #123; auto p = (t)(f); (void)p; #125;static_assert(std::is_default_constructiblelt;PeopleListgt;::value,         "Map must be default-constructible.");static_assert(std::is_copy_constructiblelt;PeopleListgt;::value,         "Map must be copy-constructible.");void ThisFunctionWillNeverBeCalled()#123;    CHECKTYPE(amp;PeopleList::operator=,          PeopleListamp; (PeopleList::*)(const PeopleListamp;));    CHECKTYPE(amp;PeopleList::empty,              bool (PeopleList::*)() const);    CHECKTYPE(amp;PeopleList::size,               int  (PeopleList::*)() const);    CHECKTYPE(amp;PeopleList::add,                bool (PeopleList::*)(const std::stringamp;, const std::stringamp;, const InfoTypeamp;));    CHECKTYPE(amp;PeopleList::change,             bool (PeopleList::*)(const std::stringamp;, const std::stringamp;, const InfoTypeamp;));    CHECKTYPE(amp;PeopleList::addOrChange,        bool (PeopleList::*)(const std::stringamp;, const std::stringamp;, const InfoTypeamp;));    CHECKTYPE(amp;PeopleList::remove,             bool (PeopleList::*)(const std::stringamp;, const std::stringamp;));    CHECKTYPE(amp;PeopleList::contains,           bool (PeopleList::*)(const std::stringamp;, const std::stringamp;) const);    CHECKTYPE(amp;PeopleList::lookup,             bool (PeopleList::*)(const std::stringamp;, const std::stringamp;, InfoTypeamp;) const);    CHECKTYPE(amp;PeopleList::get,                bool (PeopleList::*)(int, const std::stringamp;, const std::stringamp;, InfoTypeamp;) const);    CHECKTYPE(amp;PeopleList::swap,               void (PeopleList::*)(PeopleListamp;));    CHECKTYPE(combine,  bool (*)(const PeopleListamp;, const PeopleListamp;, PeopleListamp;));    CHECKTYPE(search, void (*)(const std::stringamp;, const std::stringamp;, const PeopleListamp;, PeopleListamp;));#125;int main()#123;#125;
 

the linkig must succeed. When the resulting executable is run, it must write Passed all tests to cout and nothing else to cout.

If we successfully do the above, then make no changes to PeopleList.h other than to change the typedefs for PeopleList so that InfoType specifies int, recompile PeopleList.cpp, and link it to a file containing
12345678910111213141516171819202122232425
 #include "PeopleList.h"#include lt;stringgt;#include lt;iostreamgt;#include lt;cassertgt;using namespace std;void test()#123;    PeopleList m;    assert(m.add("Fred", "Mertz", 52));    assert(m.add("Ethel", "Mertz", 49));    assert(m.size() == 2);    string first, last;    int a;    assert(m.get(0, first, last, a)  amp;amp;  a == 49);    string s1;    assert(m.get(1, first, last, a)  amp;amp;           (first == "Fred"  amp;amp;  a == 52));#125;int main()#123;    test();    cout lt;lt; "Passed all tests" lt;lt; endl;#125;
 

the linking must succeed. When the resulting executable is run, it must write Passed all tests to cout and nothing else to cout.

During execution, if a client performs actions whose behavior is defined by this spec, your program must not perform any undefined actions, such as dereferencing a null or uninitialized pointer.

Your code in PeopleList.h and PeopleList.cpp must not read anything from cin and must not write anything whatsoever to cout. If you want to print things out for debugging purposes, write to cerr instead of cout. cerr is the standard error destination; items written to it by default go to the screen. When we test your program, we will cause everything written to cerr to be discarded instead - we will never see that output, so you may leave those debugging output statements in your program if you wish.

Turn it in
There will be a link on CCLE that will enable you to turn in your source files and report. You will turn in a zip file containing these files:

PeopleList.h. When you turn in this file, the typedefs must specify string as the InfoType.

PeopleList.cpp. Function implementations should be appropriately commented to guide a reader of the code.

On the class website there will also be questions for you to provide the following:

a description of the design of your implementation and why you chose it. (A couple of sentences will probably suffice, perhaps with a picture of a typical List and an empty List. Is your list circular? Does it have a dummy node? What’s in your nodes?)

A brief description of notable obstacles you overcame.

pseudocode for non-trivial algorithms (e.g., PeopleList::remove and combine).

a list of test cases that would thoroughly test the functions. Be sure to indicate the purpose of the tests. For example, here’s the beginning of a presentation in the form of code:

The tests were performed on a map from strings to doubles

123456
 // default constructorPeopleList m;// For an empty list:assert(m.size() == 0);      // test sizeassert(m.empty());          // test emptyassert(!m.remove("Ricky", "Ricardo"));  // nothing to erase
 

Even if you do not correctly implement all the functions, you must still list test cases that would test them. Don’t lose points by thinking “Well, I didn’t implement this function, so I won’t bother saying how I would have tested it if I had implemented it
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!