注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
在海投过简历后, HR发来作业。
要求如下:
The application 'buggy.cxx' performs the following functions:
a) It reads a list of ASCII words from STDIN, a word per input line, terminated by
the word 'end'.
b) It removes the duplicates, sorts the words alphabetically, and prints them with
the number of how many times each word was encountered.
c) Then it repeatedly asks the user to enter a word and tries to look it up in the
word list which was entered initially. It terminates when it encounters EOF.
The project has a number of bugs and design deficiencies. Please, fix all problems
that you can find and make all the improvements you deem necessary so that the
result satisfies your personal standards (what would you expect a well maintained
C++ project to look like? File structure? Class structure / encapsulation? Testing
tools? Build tools?).
code如下:
#include <thread>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
struct Word
{
char * data;
int count;
Word ( char * data_ ) :
data( ::str您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 }
else
std::printf( "'%s' was NOT found in the initial word list\n", w->data );
}
}
int main ()
{
try
{
readInputWords();
// Sort the words alphabetically
std::sort( s_wordsArray.begin(), s_wordsArray.end() );
// Print the word list
std::printf( "\n=== Word list:\n" );
for ( auto p : s_wordsArray )
std::printf( "%s %d\n", p->data, p->count );
lookupWords();
printf( "\n=== Total words found: %d\n", s_totalFound );
}
catch (std::exception & e)
{
std::printf( "error %s\n", e.what() );
}
return 0;
}
本人C++ 不是很熟, 忘大家给点意见 |