Skip to content
This repository has been archived by the owner on Feb 24, 2019. It is now read-only.

0.2 Hello World (iteration statements, pointers, make) #14

Closed
emlun opened this issue Sep 18, 2014 · 1 comment
Closed

0.2 Hello World (iteration statements, pointers, make) #14

emlun opened this issue Sep 18, 2014 · 1 comment
Assignees
Milestone

Comments

@emlun
Copy link
Collaborator

emlun commented Sep 18, 2014

#0.2 Hello World (iteration statements, pointers, make)

hello, world is a classic program that dates back to 1974, first published in
a paper titled Programming in C: A tutorial. The program has one simple
purpose; to print "hello, world".

Since the typical implementation is very trivial, your task is to write a more
versatile alternative, having the following semantics:

$ ./hello
Hello, world!
$ ./hello "DD2387"
Hello, DD2387!
$ ./hello "KTH" 3
Hello, KTH KTH KTH!
$ ./hello "Malcom X" NaN
error: 2nd argument must be an integral greater than zero!
$ ./hello kth dd2387 3
error: Too many arguments!

Note: This assignment is not an exercise in object oriented programming (OOP),
but a mere introduction to the fundamental parts of C++.

0.2.1 Requirements

  • The main-function shall be written in a file called main.cpp.

  • You shall implement a function which is responsible for printing the hello
    world string
    , which shall be defined in a separate .cpp file (Translation
    Unit).

  • The separate .cpp shall have a corresponding .h-header that contains a
    forward declaration for the function therein. This header is to be#included
    by main.cpp.

  • The definition of your print-function shall be compiled seperately, and later
    linked with main.cpp.

  • Correct output from your program should be printed through std::cout,
    whereas error diagnostics should be printed through std::cerr.

  • The implementation shall pass the tests done by invoking the following
    command:

    /info/DD2387/labs/lab1/0.2_hello_world/hw_verifier

0.2.2 Hints

  • Use an argument named argc to main to get the number of arguments passed
    to your application. Remember that the name of the executable counts to this
    number.
  • Use an argument named argv to main to get access to the individual
    parameters passed to your application.
  • std::atoi from <cstdlib> can be used to convert a char const * to an
    integer. If the function is unable to interpret the data as an integer, it
    will return 0.

0.2.3 Questions

  • What is the purpose of std::cout, std::cerr, and std::clog,
    respectively?
@emlun emlun self-assigned this Sep 18, 2014
@emlun emlun added this to the Lab1 milestone Sep 18, 2014
@emlun
Copy link
Collaborator Author

emlun commented Sep 18, 2014

2bbbfc3

  • cout is a stream that prints output to standard output (typically the
    terminal the program is invoked from). It is meant for the main output from a
    program. For instance, a program that copies files might print progress
    information to cout.
  • cerr is a stream that prints to standard error (also typically the terminal
    the program is invoked from). It is meant for error output, for instance a
    program that copies files might print warnings and error information such as
    permission issues to cerr.
  • clog is meant for log output, and is by default connected to standard
    error. For instance, a program might print fine-grained debugging
    information to clog.

024c88d
00ff3a6
cdc1f7a
cb6b046

@emlun emlun closed this as completed Sep 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant