{"id":20707907,"url":"https://github.com/code-help-tutor/cmpt135-a1","last_synced_at":"2026-04-28T03:06:51.848Z","repository":{"id":234136043,"uuid":"784579915","full_name":"code-help-tutor/cmpt135-a1","owner":"code-help-tutor","description":"cmpt135 a1 代写代做 编程辅导, code help, CS tutor, WeChat: cstutorcs Email: tutorcs@163.com","archived":false,"fork":false,"pushed_at":"2024-04-10T06:08:47.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T15:11:42.922Z","etag":null,"topics":["a1","cmpt135"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-help-tutor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-10T06:08:41.000Z","updated_at":"2024-04-10T06:08:51.000Z","dependencies_parsed_at":"2024-04-18T09:18:55.391Z","dependency_job_id":"7dda505e-2632-4ada-904c-53e4b1dee762","html_url":"https://github.com/code-help-tutor/cmpt135-a1","commit_stats":null,"previous_names":["code-help-tutor/cmpt135-a1"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/code-help-tutor/cmpt135-a1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-help-tutor%2Fcmpt135-a1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-help-tutor%2Fcmpt135-a1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-help-tutor%2Fcmpt135-a1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-help-tutor%2Fcmpt135-a1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-help-tutor","download_url":"https://codeload.github.com/code-help-tutor/cmpt135-a1/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-help-tutor%2Fcmpt135-a1/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32364117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a1","cmpt135"],"created_at":"2024-11-17T01:28:28.517Z","updated_at":"2026-04-28T03:06:51.828Z","avatar_url":"https://github.com/code-help-tutor.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assignment 1: Echo\n\nFor this assignment, please download the file [myecho.cpp](myecho.cpp) and put\nall your code into that file.\n\n## Part 1\n\n### Question 1\n\nWrite a function called `quote(s)` that returns a copy of the string `s`\nsurrounded by double quotes. If `s` already starts *and* ends with double quotes,\nthen return an unchanged copy.\n\nFor example, this:\n\n```cpp\ncout \u003c\u003c quote(\"hello\")      \u003c\u003c \"\\n\"\n     \u003c\u003c quote(\"goodbye\")    \u003c\u003c \"\\n\"\n     \u003c\u003c quote(\"\\\"Aloha!\\\"\") \u003c\u003c \"\\n\"\n     \u003c\u003c quote(\"toodles\\\"\")  \u003c\u003c \"\\n\"\n     \u003c\u003c quote(\"\\\"\")         \u003c\u003c \"\\n\" \n     \u003c\u003c quote(\"\")           \u003c\u003c \"\\n\";\n```\n\nShould print this:\n\n```\n\"hello\"\n\"goodbye\"\n\"Aloha!\"\n\"toodles\"\"\n\"\"\"\n\"\"\n```\n\nIn addition to implementing `quote`, also write a function called `test_quote()`\nthat *automatically* tests your `quote` function. Use `assert` or if-statements\nto do the testing, and test the above examples, as well as a few other examples\nthat you make up. Be thorough --- your function should work for all valid\ninputs, not just the ones in the examples.\n\n**Note** Due to the confusion caused by earlier incorrect examples for `quote`,\nhere is a test function you can use in your assignment to check the correctness\nof your `quote` function:\n\n```cpp\nvoid quote_test() {\n    cout \u003c\u003c \"testing quote ... \";\n    assert(quote(\"a\"      ) == \"\\\"a\\\"\"   );\n    assert(quote(\"ab\"     ) == \"\\\"ab\\\"\"  );\n    assert(quote(\"\\\"a\\\"\"  ) == \"\\\"a\\\"\"   );\n    assert(quote(\"\\\"ab\\\"\" ) == \"\\\"ab\\\"\"  );\n    assert(quote(\"a\\\"b\"   ) == \"\\\"a\\\"b\\\"\");\n    assert(quote(\"\\\"a\"    ) == \"\\\"\\\"a\\\"\" );\n    assert(quote(\"a\\\"\"    ) == \"\\\"a\\\"\\\"\" );\n    assert(quote(\"\"       ) == \"\\\"\\\"\"    );\n    assert(quote(\"\\\"\"     ) == \"\\\"\\\"\\\"\"  );\n    cout \u003c\u003c \"all tests passed\\n\";\n}\n```\n\n\n### Question 2\n\nWhen dealing with vectors of strings, it's convenient to print them with the\n`\u003c\u003c` operator. For example:\n\n```cpp\nvector\u003cstring\u003e v = {\"art\", \"booth\", \"C\"};\ncout \u003c\u003c v \u003c\u003c \"\\n\";  // prints: {\"art\", \"booth\", \"C\"}\n```\n\nTo make that work we must *overload* `operator\u003c\u003c` like this:\n\n```cpp\nstring to_string(const vector\u003cstring\u003e\u0026 v) {\n  //\n  // ... you write the body ...\n  //\n}\n\nostream\u0026 operator\u003c\u003c(ostream\u0026 out, \n                    const vector\u003cstring\u003e\u0026 v) \n{\n    return out \u003c\u003c to_string(v);\n}\n```\n\nImplement the `to_string(v)` function so that `operator\u003c\u003c` works correctly.\n`to_string(v)` takes a `vector\u003cstring\u003e` as input and returns a nicely formatted\n`string` as in the examples. The output of `to_string` should be the same format\nas C++ string vectors, so you could cut-and-paste the output directly into a C++\nprogram.\n\nHere are some more examples:\n\n```cpp\ncout \u003c\u003c vector\u003cstring\u003e{}               \u003c\u003c \"\\n\"\n     \u003c\u003c vector\u003cstring\u003e{\"a\"}            \u003c\u003c \"\\n\"\n     \u003c\u003c vector\u003cstring\u003e{\"a\", \"b\"}       \u003c\u003c \"\\n\"\n     \u003c\u003c vector\u003cstring\u003e{\"a\", \"b\", \"c\"}  \u003c\u003c \"\\n\";\n```\n\nThis prints:\n\n```\n{}\n{\"a\"}\n{\"a\", \"b\"}\n{\"a\", \"b\", \"c\"}\n```\n\nIn addition to implementing `to_string`, also write a function called\n`test_to_string()` that *automatically* tests your `to_string` function. Use\n`assert` or if-statements to do the testing, and test the above examples, as\nwell as a few other examples that you make up. Be thorough --- your function\nshould work for all valid inputs, not just the ones in the examples.\n\n\n## Part 2\n\nThe `echo` command is a standard shell command that prints the arguments passed\nto it. For example, here is the [Fish shell](https://fishshell.com/) echo\ncommand:\n\n```bash\n❯ echo Welcome to Linux!\nWelcome to Linux!\n\n❯ echo -s Welcome to Linux!\nWelcometoLinux!\n\n❯ echo Welcome to Linux! -s\nWelcome to Linux! -s\n```\n\nThe `-s` flag prints the arguments *without* a space between them. As the\nexample shows, it must be *first* to have any effect.\n\nIn the following questions, your task to implement a customized version of the\n`echo` utility. It works similarly, but *not identically*, to the Linux `echo`.\n\nEach question asks you to add a new feature, and you can do this is all in the\nsame program. \n\nPlease note the following:\n\n- *Case matters* in the input strings, e.g. `-s` and `-S` are treated as\n  *different* strings, and so `-S` would be an invalid flag.\n- A flag, like `-s`, is only treated as a flag if it is the *first* string\n  passed to your `myecho`. Otherwise, if it's not the first string, it's treated\n  like a regular word and printed normally.\n\n### Question 3\n\nImplement `myecho` so that when passed 0 or more strings, each separated by at\nleast once space, those strings are printed on the screen with exactly one space\nbetween them. For example:\n\n  ```bash\n  \u003e ./myecho Welcome to Linux!\n  Welcome to Linux!\n\n  ❯ ./myecho   Welcome   to       Linux!\n  Welcome to Linux!\n\n  ❯ ./myecho\n\n\n  ```\n\n\u003e The sample output uses the [Fish shell](https://fishshell.com/), and we\n\u003e recommend you use that. Otherwise, you might get slightly different-looking\n\u003e output. \n\n\n### Question 4\n\nTo the version of `./myecho` you wrote in the previous question, add support for\na `-h` flag that prints the help message given below and exits (ignoring any\nstrings that come after the `-h`).\n\nThe help message should look like this:\n\n```bash\n❯ ./myecho -h\nUsage: ./myecho [-runtests|-(hrs)] [string ...]\n  -runtests: run the tests\n             over-rides single-character flags\n         -h: print this help message\n             over-rides other single-character flags\n         -r: print the strings in reverse order\n         -s: no space between arguments\n         -q: quote the printed results\n   -rs, -sr: no space between arguments, in reverse order\n\n  Repeated single-character flags are allowed (and are ignored).\n  Unknown flags cause an error.\n\n\nExamples:\n  ❯ ./myecho -q\n  \"\"\n  ❯ ./myecho x y z\n  x y z\n  ❯ ./myecho -q x y z\n  \"x y z\"\n  ❯ ./myecho -sr x y z\n  zyx\n  ❯ ./myecho -h\n```\n\nPlease use this particular help message. The other options listed in it will be\nimplemented in the following questions.\n\n\n### Question 5\n\nTo the version of `./myecho` you wrote in the previous question, add support for\na `-runtests ` flag that calls the `test_quote()` and `test_to_string()`\nfunctions. Any strings after `-runtests` are ignored. \n\nThe tests should print their results, as shown in the examples.\n\nFor example:\n\n```bash\n❯ ./myecho -runtests\nrunning quote tests ... all passed\nrunning to_string tests ... all passed\n\n❯ ./myecho -runtests one two three\nrunning quote tests ... all passed\nrunning to_string tests ... all passed\n\n❯ ./myecho one two -runtests three\none two -runtests three\n\n❯ ./myecho -runtests -h one two three\nrunning quote tests ... all passed\nrunning to_string tests ... all passed\n\n❯ ./myecho -h -runtests a b\n... prints the help message ...\n```\n\nAs these examples show, `-h` and `-runtests` only have their special meaning if\nthey appear as the *first* string passed to `myecho`. If they appear later, they\nare treated as regular strings.\n\n### Question 6\n\nTo the version of `./myecho` you wrote in the previous question, add support for\nthe `-q` flag that prints a `\"` character (double quote) at the begin and end of\nthe printed result. For example:\n\n```bash\n❯ ./myecho -q\n\"\"\n\n❯ ./myecho x y z\nx y z\n\n❯ ./myecho -q x y z\n\"x y z\"\n\n\u003e ./myecho -qh z y z\n... prints the help message ...\n```\n\nNotice that in the quoted strings there is *no* space after the last string.\n\n### Question 7\n\nTo the version of `./myecho` you wrote in the previous question, add support for\nthe `-s` flag that prints the strings *without* a space between them. For\nexample:\n\n```bash\n❯ ./myecho -s Welcome to Linux!\nWelcometoLinux!\n\n❯ ./myecho   -s   Welcome   to       Linux!\nWelcometoLinux!\n\n❯ ./myecho   -qs   Welcome   to       Linux!\n\"WelcometoLinux!\"\n\n\u003e ./myecho -s\n\n\u003e ./myecho -sq\n\"\"\n```\n\nNote that `-s` is treated as a regular string if it is not the first string:\n\n```bash\n\u003e ./myecho Welcome to -s Linux!\nWelcome to -s Linux!\n```\n\n### Question 8\n\nTo the version of `./myecho` you wrote in the previous question, add support for\nthe `-r` flag that prints the strings in *reverse* order. For example:\n\n```bash\n❯ ./myecho -r Welcome to Linux!\nLinux! to Welcome\n\n\u003e ./myecho   -r   Welcome   to       Linux!\nLinux! to Welcome\n\n\u003e ./myecho   -r   Welcome   to       Linux!\nLinux! to Welcome\n\n\u003e ./myecho Welcome to -r Linux!\nWelcome to -r Linux!\n\n\u003e ./myecho -r\n\n```\n\nNote that `-r` is treated as a regular string if it is not the first string.\n\n\n### Question 9\n\nTo the version of `./myecho` you wrote in the previous question, add support for\nmultiple single-character flags. For example:\n\n```bash\n\u003e ./myecho -sr a b c\ncba\n\n\u003e ./myecho -rqs a b c\n\"cba\"\n\n\u003e ./myecho -sh Welcome to Linux!\n... help message printed...\n\n\u003e ./myecho -hq Welcome to Linux!\n... help message printed...\n```\n\nNote that the help message is *not* printed in quotes because of the `-q` flag.\nThe `-h` flag takes precedence over all other flags, and so the `-q` flag is\nignored.\n\nThe order of multiple single-character flags does not matter. Repeated\nsingle-character flags are allowed, but ignored. For example:\n\n```bash\n\u003e ./myecho -qssq Welcome to Linux!\n\"WelcometoLinux!\"\n\n\u003e ./myecho -hhshs Welcome to Linux!\n... help message printed ...\n```\n\nIf `-h` is one of the flags, it *always* takes precedence (and any other\nflags/strings are ignored).\n\nIf `-runtests` is the *first* string, then the tests are run and any following\nflags/strings are ignored. For example:\n\n```bash\n❯ ./myecho -runtests -s Welcome to Linux!\nrunning quote tests ... all passed\nrunning to_string tests ... all passed\n``` \n\nMixing `-runtests` with other single-character flags is not allowed and should\ncause an \"invalid flag\" error, e.g.:\n\n```bash\n❯ ./myecho -hruntests\nError, invalid flag: u\n\n... help message printed ...\n\n❯ ./myecho -runtestsh\nError, invalid flag: u\n\n... help message printed ...\n```\n\nAlso, if an invalid flag is passed, then print an error message, followed by the\nhelp message, and then immediately exit:\n\n```bash\n❯ ./myecho -S Welcome to Linux!\nError, unknown flag: -S\n... help message printed...\n\n❯ ./myecho -qQs Welcome to Linux!\nError, unknown flag: -Q\n... help message printed...\n```\n\n## Hints\n\n- Working with a `vector\u003cstring\u003e` is easier than working with a C-style array of\n  strings, and so a good first step is to convert the `argc` command-line inputs\n  into a `vector\u003cstring\u003e`. \n\n- You are not *required* to use `quote` and `\u003c\u003c` in the *implementation* of\n  `myecho`, but they can be useful for printing when debugging.\n\n- The logic for handling flags can get tricky, so make it as simple as possible,\n  even if you need to sacrifice some efficiency. For this assignment, code that\n  is easy to test and easy to read is more important than squeezing out every\n  last drop of performance (you can improve the performance later).\n\n- The file [test.sh](test.sh) contains a script that you can run like this:\n\n  ```bash\n  \u003e ./test.sh\n  ... lots of output ...\n  ```\n\n  Sample correct output is in the file [test.out](test.out). You can use this to\n  help test your program. For instance in BASH (the default shell on Ubuntu) you\n  can type this command to compare the output of your program with the correct\n\n  ```bash\n  \u003e ./test.sh \u003e out.txt\n  \u003e diff out.txt test.out\n  ... no output means your program produced the correct output ...\n  ```\n\n## Marking Scheme\n\nBefore we give your program any marks, it must meet the following **basic\nrequirements**:\n\n- It *compiles on Ubuntu Linux* using [the standard course makefile](makefile),\n  e.g.:\n\n  ```bash\n  $ make myecho \n  g++  -std=c++17 -Wall -Wextra -Werror -Wfatal-errors -Wno-sign-compare -Wnon-virtual-dtor -g   myecho.cpp   -o myecho\n  ```\n\n  If your program fails to compile, your mark for this assignment will be 0.\n\n- It has *no memory leaks*, according to `valgrind`, e.g.:\n\n  ```console\n  $ valgrind ./myecho one two three\n    \n  // ... lots of output ... \n  ```\n\n  A program is considered to have no memory leaks if:\n\n  - In the `LEAK SUMMARY`, `definitely lost`, `indirectly lost`, and\n    `possibly lost` are all 0.\n\n  - `ERROR SUMMARY` reports 0 errors.\n\n  - It is usually okay if **still reachable** reports a non-zero number of\n    bytes.\n\n  If `valgrind` reports any errors for your program, your mark for the\n  assignment will be 0.\n\n- **It includes the large comment section with student info, statement of\n  originality, and notes to the marker**, completely and correctly filled out.\n  If your submitted file does *not* have this, then we will assume your work is\n  not original, and your mark for the assignment will be 0.\n  \nIf your program meets all these basic requirements, then it will graded using\nthis marking scheme.\n\n#### **Overall source code readability: 5 marks**\n- All code is sensibly and consistently indented, and all lines are 100\n  characters in length, or less.\n- Whitespace is used to group related pieces of a code to make it easier for\n  humans to read. All whitespace should have a purpose.\n- Variable and function names are self-descriptive.\n- Appropriate features of C++ are used, as discussed in class and in the notes.\n  **Note** If you use a feature that we haven't discussed in class, **you must\n  explain it in a comment**, even if you think it's obvious.\n- Comments are used when needed to explain chunks of code whose purpose is not\n  obvious from the code itself. There should be *no* commented-out code from\n  previous versions.\n\n#### **Overall performance and memory usage: 2 marks**\n- No unnecessary work is done.\n- No unnecessary memory is used.\n\n#### **Source code correctness**\nTo get full marks, your functions must pass all the test cases for that\nquestion. The marker may use test cases not given in the assignment.\n\n- Question 1: **2 marks**, `quote` and `test_quote`\n- Question 2: **2 marks**, `to_string` and `test_to_string`\n- Question 3: **2 marks**\n- Question 4: **2 marks**\n- Question 5: **2 marks**\n- Question 6: **2 marks**\n- Question 7: **2 marks**\n- Question 8: **2 marks**\n- Question 9: **3 marks**\n\n#### Deductions\n- **-1 mark** (at least) if your file does not have the correct name\n- **a score of 0** if you accidentally submit a \"wrong\" non-working file, and\n  then *after the due date* submit the \"right\" file. If you can provide evidence\n  that you finished the assignment on time, then it may be marked (probably with\n  a late penalty).\n\n\n## Submitting Your Assignment\n\nPlease submit your assignment on [Canvas](canvas.sfu.ca) when it is done. Submit\njust your `myecho.cpp` file. Do **not** zip it, and do not submit any other\nfiles.\n\nYou can submit your file as many times as you like before the due date without\npenalty. Each re-submitted file gets automatically renamed by\n[Canvas](canvas.sfu.ca), e.g. if you submit `myecho.cpp` twice the second one\nwill be renamed to something like `myecho-2.cpp`.\n# cmpt135 a1\n\n# 程序代做代写 CS编程辅导\n\n# WeChat: cstutorcs\n\n# Email: tutorcs@163.com\n\n# CS Tutor\n\n# Code Help\n\n# Programming Help\n\n# Computer Science Tutor\n\n# QQ: 749389476\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-help-tutor%2Fcmpt135-a1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-help-tutor%2Fcmpt135-a1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-help-tutor%2Fcmpt135-a1/lists"}