Thursday, February 7, 2019

C++ Homeworks #2

Homework 2-1: Variations from Homework 1-1
Read one data and convert to another format.

// Practice I/O
Read from command line.
Read from user input.
Read from file.

// Practice loops
Read multiple input data set until quit.

// Practice conditionals
Output different phrases depending on the temperatures.

// Practice handling run time errors.
Using Exceptions.
Using conditionals.

// Practice date time printing
// Practice using <string>
Homework 2-2: Big O
Calculate the minimum n that will make 
     2 to the power of n become greater than 100 * n squared.
           For some n, 2n > 100 * n 2
Calculate the minimum n that will make n squared greater than 1000 * (n log n)
Homework 2-3: Calculate this.
6/22
111 % 8
55 / 2.25
33 + 4 % 5
77 * 9 % 8
77 % 9 * 8
77 % 8 * 9
x = -55 * i++ - 7 % 8;

// logical
// Take a input integer and output result of the following logical expressions
x < 20 && x >= -3
!x && x >= 33
x >= 33 && !x
x++ == 5 || x == 9
Homework 2-4: Random numbers
#include <stdlib.h>                   // Prototypes of srand() and rand()
#include <iostream>
#include <iomanip>                    // using setw(n) for cout

// Print "Please enter a number between 0 and n"
// cin >> seed;                       // use the number as seed
// srand ( seed )                     // seeds the random number generator
// x = rand() % n + 1                 // generate the random number
// Print out the random number
      

No comments:

Post a Comment