Project #44488 - C++

Q1)

Multiple choice

in the  attchement 

------------------------------------------------------------------------------------

 

Q2)

The attached file (lab14.cpp) contains a program that includes a Date class, a Time class, and a main-function. This program should be separated into five  files and submitted to turnin. A primer on how to do this is below

 

Primer for breaking an application into multiple files.

 

 

 

Two rules that must never be broken:

 

  • Never, ever #include a source (.cpp) file
  • Never, ever use g++ to compile a header (.h) file

 

Very roughly speaking, there are three components of an application that should be divided into separate files:

 

  1. each class declaration is put into its own header (.h) file
  2. each class definition is put into its own source (.cpp) file
  3. other functions, including the main-function are put into a source (.cpp) file

 

Here is a sample application in a single file that includes one class. This application will be used as an example in this primer:

 

                 1  #include  <iostream>
2 #include <string>
3 using namespace std;
4
5 //Student CLASS DECLARATION
6 class Student {
7 public:
8 Student(string nm, string yr, float g); //constructor
9 void boost_grade();
10 void display();
11
12 private:
13 string name;
14 string year;
15 float gpa;
16 };
17
18 //Student CLASS DEFINITION
19 Student::Student(string nm, string yr, float g) //constructor
20 : name(nm), year(yr), gpa(g) //initialization list
21 {
22 }
23
24 void Student::boost_grade()
25 {
26 gpa+= 1.0;
27 if(gpa > 4.0)
28 gpa= 4.0;
29 }
30
31 void Student::display()
32 {
33 cout << "Student Record" << endl;
34 cout << "--------------" << endl;
35 cout << "Name: " << name << endl;
36 cout << "Academic Level: " << year << endl;
37 cout << "GPA: " << gpa << endl;
38 }
39
40 //OTHER FUNCTIONS, INCLUDING THE MAIN-FUNCTION
41 int main()
42 {
43 Student s( "Bobby Teenager", "Sophomore", 2.5);
44 s.boost_grade();
45 s.display();
46 }

 

Step 1, partition program into multiple files

 

The Student class declaration is on lines 5-16. These lines should go into a header file named after the class: Student.h

 

The Student class definition is on lines 18-38. These lines should go into a source file named after the class: Student.cpp

 

The other functions (if any), including main are on lines 40-46. These should go into a file with an application appropriate name. test_student.cpp

 

The easiest method for breaking test_student.cpp into multiple files is to simply make a copy for each needed file. Then, edit each copy, deleting unneded lines. For example, the above file is already named test_student.cpp. Use cp make copies for the other two files:

 

cp test_student.cpp Student.cpp

 

cp test_student.cpp Student.h

 

Edit each of the files deleting the portions that don't belong. So, for example, edit Student.cpp and delete all lines before line 18 and after line 38. 

 

 

 

Step 2, add preprocessor directives to each header file

 

Preprocessor directives must surround the contents of each header file (this example ony has one header file).  For Student.h the following should be added as the first two lines in the file:

 

             #ifndef   STUDENT_H 

 

             #define   STUDENT_H 

 

As shown provide the filename but use uppercase letters and replace periods with underscores. 

 

The last line in the header file should be:

 

             #endif 

 

Step 3, add #include statements in each file as required

 

In the above example each file needs the following #include statements:

 

  1. Student.h
    1. #include<string> because strings are used in this file
  2. Student.cpp
    1. #include"Student.h" because the functions of the Student class are defined here. Also, note the double quotes which specify "look for this file in the current directory"
    2. #include<iostream> because cout statements are used in this file
    3. #include<string> because strings are used in this file
  3. test_student.cpp
    1. #include"Student.h" because the Student class is used in this file. Again, note the double quotes which specify "look for this file in the current directory"

 

Step 4, compile the application by putting all .cpp files on the command line

 

g++ Student.cpp test_student.cpp -o student_app

 

Step 5, don't forget the two rules that must never be broken

 

  • Never, ever #include a source (.cpp) file
  • Never, ever use g++ to compile a header (.h) file

 

 

in the attehemnt

 

 

-----------------------------------------------------------------------------------------------

 

 

Q3)

Description

You are developers at a game company and have been asked to do some initial development for the resident game designers. The relevant documents for this project can be found in the attached file.

Process

The joust project will be analyzed and designed in class.  Each student will be responsible for coding their own solution.

Submission

Your .cpp, .h, and Makefile should be bundled together in a gzipped tarball for submission

tar czvf project2.tar.gz *.h *.cpp Makefile

Subject Computer
Due By (Pacific Time) 10/24/2014 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy