Passer au contenu principal
SciNet
  • Accueil
  • Tous les cours
  • Calendrier
  • Certificats
  • SciNet
    Site principal Documentation my.SciNet
  • CCDB
  • Plus
Fermer
Activer/désactiver la saisie de recherche
Français
English Français
Vous êtes connecté anonymement
Connexion
SciNet
Accueil Tous les cours Calendrier Certificats SciNet Replier Déplier
Site principal Documentation my.SciNet
CCDB
Tout déplier Tout replier
  1. Tableau de bord
  2. PHY1610 - Winter 2021
  3. 1. C++ and Functions

1. C++ and Functions

Conditions d’achèvement
Consulter
Remettre un travail
Recevoir une note
Ouvert le : vendredi 1 janvier 2021, 00:00
À rendre : jeudi 21 janvier 2021, 23:59

Write a C++ program that generates a table of data.

This table should have three columns, one column with x double precision values ranging from -5 to 5, a second column with values y=sin(2x), and a third column with values z=cos(3x). In particular, your program should:

  • Contain at least two functions (besides "int main"), called "f" and "g". The function "f" should take x as an argument and return the value of sin(2x), while the function "g" should that take x as an argument and return cos(3x).
  • The program should take 101 evenly spaced x-values from the interval [-5,5] (including the end points).
  • It should use the functions f and g to compute the values of those functions for those 101 x-values.
  • It should write out the x, f, and g values in tabular form (i.e. three-column ascii text), either to a file called "lissajous.txt". Don't try to add lines to the table, just use spaces and newlines to format the text.

A few hints as to what coding style we are looking for:

  • Try to avoid duplicating the specific values for this assignment (i.e., -5, 5, 101, "lissajous.txt"). E.g. storing them, once, in a variable, and use that variable.
  • Give your variables understandable names.
  • Indent your code properly. Mostly, that means that you should indent consistently and in such a way that all code in the same block has the same indentation.
  • Be sure to comment your code!
  • In general: try and write a code that your future self could still read and understand it in, say, 1 year.

Compile and run your code using g++ with the -std=c++14 flag, and capture the output. Submit, by 21 January 2021 at 11:59 PM, the following files:

  1. a text file describing what you did and how you compiled the program, and how you ran it,
  2. code of the program,
  3. output file produced by the program.
    You can use "redirection" to store the output of your program in a text file. For instance, by running your program in the following way in the terminal
    ./myProgram > output.txt
    in this case the ">" operator will redirect the output of "myProgram" to the file named "output.txt".

All files should be PLAIN text files.
Doc, docx, xls, xlsx, ... files are NOT plain text files. Even .rtf, or, "rich text format" are NOT plain text files.
Use the "Assignment Dropbox" on the course website to upload your work. Remember the late penalty policy: you can submit upto seven days late, but you will get a half point taken off for each day you submitted late. Also note that if you submit the different parts of your work at different times, the last submission date is taken as the submission of the whole.

Contacter l’assistance du site
Vous êtes connecté anonymement (Connexion)
Résumé de conservation de données


All content on this website is made available under the Creative Commons Attribution 4.0 International licence, with the exception of all videos which are released under the Creative Commons Attribution-NoDerivatives 4.0 International licence.
Fourni par Moodle