0% found this document useful (0 votes)
134 views8 pages

Question No 3

The document describes generating C++ source code from a UML class diagram with three classes - Student, Marks, and Result. The Marks class inherits from Student, and Result inherits from Marks. The code is generated, modified to add a sports mark attribute and function, and then reverse engineered back into a UML class diagram. The output shows the code successfully calculates and displays the student details including a total score.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views8 pages

Question No 3

The document describes generating C++ source code from a UML class diagram with three classes - Student, Marks, and Result. The Marks class inherits from Student, and Result inherits from Marks. The code is generated, modified to add a sports mark attribute and function, and then reverse engineered back into a UML class diagram. The output shows the code successfully calculates and displays the student details including a total score.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

QUESTION no : 3

Define a class Student. The class Result inherits Marks and class Marks inherits Student. All the classes contain data members and member functions. Generate source code in C++ and update the code and execute. Add Sports Marks in the Marks class and Reverse Engineer.

AIM: To generate source code for the class diagram, modify the source code and reverse engineer ALGORITHM: Source Code Generators (Forward Engineering) In Rational Rose: 1. Define a class Student in Logical View

The class Result inherits Marks and class Marks inherits Student All the classes contain data members and member functions. Declare data members as public except for the class Result. Declare Return type as void for functions. 4. Select all the classes 5. Go to Tools -> ANSI C++ - > Convert from classic C++ This Screen will appear:
2. 3.

Click next.

Click ok. You will now have a component called converted classes.

6. Drag and drop Converted Classes component into all other classes in the class diagram. 7. Right click the component converted classes for the appropriate language, e.g. ANSI C++, select Generate Code ... 8. The Code Generation form comes up. Choose folder to save generated files

9. Open .cpp files and update code and execute. REVERSE ENGINEERING: In code, Declare attribute SportMar in Marks.h. In code, Declare function GetSportsMarks () in Marks.h and add the following coding in Marks.cpp. Draw a component diagram with 3 components student ,marks and result. Select each component , right click -> open specification. In general tab select language as ANSI C++. Select each component , right click ->ANSI C++-> open ANSI Specification Give location to save and click add files browse and choose corresponding header files and cpp files. Click ok. Select each component , right click ->ANSI C++->Reverse Engineer. Reverse engineered components will be available in the left panel logical view. Drag and drop in the right panel to generate the diagram.

UPDATED CODING STUDENT.H #ifndef STUDENT_H_INCLUDED_ACD912CE #define STUDENT_H_INCLUDED_ACD912CE #include<iostream.h> //##ModelId=53269EF6009C class Student { public: //##ModelId=53269F3C029F void GetData(); //##ModelId=53269F430242 void PutData();

//##ModelId=53269FF10232 int RegNo; }; void Student::GetData() { cout<<"Enter Register Number:"; cin>>RegNo; } void Student::PutData() { cout<<"RegisterNumber:"<<RegNo<<endl; } #endif /* STUDENT_H_INCLUDED_ACD912CE */ STUDENT.CPP #include "D:/lek/Student.h" #include<iostream.h> //##ModelId=53269F3C029F Student::GetData() { } //##ModelId=53269F430242 Student::PutData() { } MARKS.H #ifndef MARKS_H_INCLUDED_ACD933EA #define MARKS_H_INCLUDED_ACD933EA #include "D:/lek/Student.h" //##ModelId=53269EF803B9 class Marks : public Student { public: //##ModelId=53269F570148 void GetMarks(); //##ModelId=53269F5D0167 void PutMarks(); void GetSportsMarks();

//##ModelId=53269F4B01E4 int Subj1; //##ModelId=53269F50034B int Subj2; int SportMark; }; void Marks::GetMarks() { cout<<"Enter mark1:"; cin>>Subj1; cout<<"Enter mark2:"; cin>>Subj2; cout<<"Enter SportMark:"; cin>>SportMark; } void Marks::PutMarks() { PutData(); cout<<"Mark1:"<<Subj1<<endl; cout<<"Mark2:"<<Subj2<<endl; cout<<"SportsMark:"<<SportMark<<endl; }

#endif /* MARKS_H_INCLUDED_ACD933EA */ MARKS.CPP #include "D:/lek/Marks.h" #include "D:/lek/Student.h" #include<iostream.h> //##ModelId=53269F570148 Marks::GetMarks() { cout<<"Enter mark1:"; cin>>Subj1; cout<<"Enter mark2:"; cin>>Subj2; } //##ModelId=53269F5D0167 Marks::PutMarks()

{ PutData(); cout<<"Mark1:"<<Subj1<<endl; cout<<"Mark2:"<<Subj2<<endl; cout<<"SportsMark:"<<SportMark<<endl; } void Marks::GetSportsMarks() { cout<<"Enter Sports Mark:"; cin>>SportMark; }

RESULT.H #ifndef RESULT_H_INCLUDED_ACD9508A #define RESULT_H_INCLUDED_ACD9508A #include "D:/lek/Student.h" #include "D:/lek/Marks.h"

//##ModelId=53269EFA03C8 class Result : public Marks { public: //##ModelId=53269F730157 void display();

//##ModelId=53269F69003E int Total; }; RESULT.CPP #include "D:/lek/Student.h" #include "D:/lek/Marks.h" #include "D:/lek/Result.h" #include<iostream.h> #include<conio.h> //##ModelId=53269F730157 void Result::display() {

GetData(); GetMarks(); cout<<"RegNo:"<<RegNo<<endl; cout<<"Mark1:"<<Subj1<<endl; cout<<"Mark2:"<<Subj2<<endl; cout<<"SportMark:"<<SportMark<<endl; Total=Subj1+Subj2+SportMark; cout<<"Total:"<<Total<<endl; } void main() { clrscr(); Result r; r.display(); getch(); } CLASS DIAGRAM REVERSE ENGINEERED:

OUTPUT:
ENTER REGISTER NUMBER:111 ENTER MARK1:100 ENTER MARK2:99 ENTER SPORTS MARKS:98 REGNO:111 MARK1:100 MARK2:99 SPORT MARK:98 TOTAL:297

RESULT : The source code has been successfully generated for the class diagram and reverse engineered.

You might also like