C++ PROGRAMMING ASSIGNMENTS

  1. (DUE:    OVERDUE)
    Write a program which derives a letter grade from a score as follows:

                input:            A score with integer value between 0 and 100 inclusive.

                calculate:      A letter grade determined as follows:

                              score                             grade        
                        90-->100                               A
                        80--> 89                                B
                        70--> 79                                C
                        60--> 69                                D
                          0--> 59                                F

                output:        The score together with the corresponding letter grade.

Please use the switch statement to solve this problem.   It might help to know that  C and C++ provide / and % for div and mod operations respectively.  Note that the divide operator, /, is overloaded since it serves both float and int type variables.

  1. (DUE:    OVERDUE)

Write a program that counts the number of upper and lower case letters, respectively,  in the file, text.txt.  Send your output to a file.

  1. (DUE:    OVERDUE)

(a)  Write a program that reads in a vector of integers and sorts them.  You may choose your favorite sorting algorithm.  Please use integers.txt for  input and send your output to a data file.  Also, please incorporate the following functions:

                void read_in (ifstream & in, vector<int> & v);
                void sort (vector<int> & v);
                void write_out (ofstream & out, const vector<int> & v);

If you've forgotten all those sorting algorithms, here's pseudocode for the simple bubble sort:

                for i=n downto 2    //n=the number of items in the list
                            for j=1 to i-1
                                           if a[j]> a[j+1]
                                                            swap (a[j], a[j+1])

NOTE:  The above algorithm assumes the list:     a[1], a[2], ..., a[n]

(b)  Write a sort template, which incorporates the swap template we wrote in class (2/26).  Also, write templates for the read_in () and write_out () functions.  Then write a program that uses your templates to
                (a)   sort a list of integers (integers.txt)
                (b)   sort a list of strings (strings.txt)

  1. (DUE:    OVERDUE)

Add auxiliary operators << and >> to employee.cpp, and test with the revised employee_driver.cpp, using the input file employee.txt.  HINT:  You may have to add accessor methods to the employee class.

  1. (DUE:    OVERDUE)

Complete the definition of the complex class described in the lecture of 4/2.  It may help to begin with the header and implementation files we developed there, complex.h and complex.cpp.  In particular, update that version of the complex class by overloading the arithmetic and I/O operators.  Use the driver program, complexDriver.cpp and input file, infile.txt, to test your improved version of the complex class.

 

    EXTRA CREDIT (DUE by midnight Friday, 4/11)

In the 4/9 class, we discussed the implementation of the linked list class.  By the end of class we had implemented several of the class methods in smallLinked.cpp.   However, the implementation of the remove_rear() method eluded us.  Give me a working version, using my driver program and I'll give you extra credit.

 

  1. (DUE:    OVERDUE)

Write a program which implements an RPN calculator.   That is, input would consist of a string of characters consisting of numbers (0 to 9) and operators (+, -, *, /, =).  The computer would then output the result.  (See lecture notes for 4/2)  Please use my data file for testing your program.  It includes several RPN expressions, one per line.

  1. (DUE:    OVERDUE)

Create a template class list<T> to represent a generic list.  Modify the driver program from 4/16 to accommodate linked lists of int, double, and string respectively.   Of course, the averaging code will apply only to the int and double versions.

  1. (DUE:    5/14)

NOTE:  This will be counted as a take-home section of the final quiz.

Using the Shape hierarchy of classes, create and test a Square class as a derived class of the Rectangle class.

Back to CSC 076N Home Page