MET CS 563 Spring 2010 Assignment 1: Fundamentals DUE: Wed, 02/27/2010 Total Points: 100 Important Note: We ask you to strictly follow the following naming convention for your assignment files. <last_name>_<first_name>_A<assignment number>­<problem number> e.g. Zlateva_Tanya_A1­1.cpp is the name of a source file for Assignment 1, Problem 1 of Tanya Zlateva. Each file should start with a comment that should look as follows: /** @file <The name of your file> @author <Your first and last name> @date <the date of submission> @course cs563 @assignment/problem number A1.1 */ 1. Quadratic formula (50 points). Write a program that prompts the user for 3 integers a, b, and c, and then calculates the roots for the polynomial: ax 2 + bx + c Using the explicit formula for the quadratic equation = −b ± b 2 − 4ac 2a requires computation of the square root. C++ has no operator for the square root but provides a function sqrt(x) in the cmath library. To be able to use the library you must add an include statement similar to the include statement for the iostream library: #include <cmath> at the top of the file. Note on User­Interface: A minimal user interface pattern requires that the program: a) tells what it does by printing a screen message, e.g. "Welcome to quadratic formula calculator! This program calculates roots for polynomials of the form ax^2 + bx + c" b) prompts for user input, e.g. "Please enter a:”, etc. c) verifies the input by printing it on the screen, e.g. "a is 10" d) outputs result with explanation “The roots for the polynomial 10 x ^2 + 5 x + 3 are …” MET CS 563 Spring 2010 Page 1 of 2 2. Mean median, smallest (largest) (50 points). Write a program that reads in floating point numbers from the screen until it encounters EOF and • computes the mean of the sequence; • finds smallest number After you test your program modify it to read the input from a file "data.txt". To read data from a file you must include the file stream library fstream and define and open a file stream object (here infile) as follows #include <fstream> //similar to #include <iostream> ifstream infile; //input file stream object infile.open("data.txt"); The statement for reading values from a file has the same form as reading with cin, e.g. infile >> price; //same as cin >> price; and ifstream objects can call the same functions as cin objects, e.g. infile.fail(); infile.eof(); etc. When work with file stream object is completed the file must be cloased (usually at the end of the program) infile.close(); (For more see [Ho 09], Ch. 9.1) Files to turn in file <last_name>_<first_name>_A1-1.cpp <last_name>_<first_name>_A1-2.cpp contents source for problem 1 source for problem 2 MET CS 563 Spring 2010 Page 2 of 2