CS304 Assignment 2 Solution and Discussion


  • Cyberian's Gold

    Re: CS304 Assignment 2 Solution and Discussion

    Assignment No. 02
    Semester: Spring 2020
    CS304- Object Oriented Programming

    Total Marks: 20
    Due Date: 16/06/2020

    Uploading instructions:
    • Your assignment should be in .CPP format (Any other formats like scan images, PDF, zip, doc, rar and bmp etc. will not be accepted).
    • Save your assignment with your ID (e.g. bc000000000.CPP).
    • No assignment will be accepted through email.

    Rules for Marking:
    It should be clear that your assignment will not get any credit if:
    • The assignment is submitted after due date.
    • The submitted assignment does not open, execute or file is corrupted.
    • Your assignment is copied from internet, handouts or from any other student.
    (Strict disciplinary action will be taken in this case).
    Lectures Covered:
    This assignment covers Lecture # 7-15.
    Problem Statement

    In Pakistan, universities have adopted the semester system for the purpose of education. In semester system, two types of formal exams (i.e. Mid Term Exam and Final Term Exam) are generally conducted in every semester. Each exam is composed of certain number of questions which can be of two types: multiple choice questions (MCQs) and descriptive questions.
    Keeping in mind the above scenario, consider the following class diagram showing the composition relationship between Exam and Question classes.
    8e1b1d68-b0fd-46e3-b1e6-6a6ffb7cd801-image.png

    Now, you are required to write a C++ program for above for above class diagram.
    Solution Guidelines:
    • Carefully analyze the given class diagram and write code according to classes, attributes, functions and relationship mentioned in class diagram.
    • In Exam class, data member NoOfQuestions will have some fixed value. It is set to 2 to generate the sample output.
    • As one Exam is composed of many questions, so here you have to use the concept of array of objects. Size of array will be based on value of Number of questions. It is set to 2 to generate the sample output.
    • In Question class, all getter functions should be constant.

    Sample Output:
    57df3c4f-f64a-47d7-a4dc-7a46b7435220-image.png

    Best of luck!
    NOTE: Do not put any query on MDB about this assignment, if you have any query then email at [email protected].
    Furthermore, if any student found cheating from any other student or from online forums then he/she will be awarded ZERO right away and strict disciplinary action will be taken against the student.
    Deadline: Your assignment must be uploaded/submitted on or before 16th June 2020.


  • Cyberian's Gold

    #include<iostream>
    using namespace std;
    
    class Question
    {
    	private : 
    		int QuestionID;
    		string QuestionType;
    		int QuestionMarks;
    	
    	public :
    		Question()
    		{
    			cout<<"Enter Question ID : ";
    			cin>>QuestionID;
    			cout<<"Enter Question Type : ";
    			cin>>QuestionType;
    			cout<<"Enter Question Marks : ";
    			cin>>QuestionMarks;
    		}
    		void setQueID(int id)  
    		{
    			QuestionID=id;
    		}
    		
    		void setQueType(string type)  
    		{
    			QuestionType=type;
    		}
    		void setQueMarks(int marks)	 
    		{
    			QuestionMarks=marks;
    		}
    		int getQueID() const 
    		{
    			return QuestionID;
    		}
    		string getQueType() const 
    		{
    			return QuestionType;
    		}
    		int getQueMarks() const 
    		{
    			return QuestionMarks;
    		}
    			
    };
    
    class Exam
    {
    	private :
    		string ExamType;
    		string CourseCode;
    		static const int NoOfQuestions=2;
    		Question *questions[NoOfQuestions];
    	
    	public :
    		Exam(string EType, string CCode)
    		{
    			ExamType=EType;
    			CourseCode=CCode;
    			for(int i=0; i<NoOfQuestions; i++)
    			{
    				cout<<"\n***** Enter Data of Question No. "<<i+1<<" *****\n";
    				questions[i] = new Question();
    			}
    		}
    		void DisplayInfo()
    		{
    			cout<<"----------------------------\n";
    			cout<<"**** Displaying Exam Information ****";
    			cout<<"\n----------------------------";
    			cout<<"\nExam Type : "<<ExamType;
    			cout<<"\nCourse Code : "<<CourseCode;
    			cout<<"\nTotal No of Questions for Exam : "<<NoOfQuestions;
    			
    			cout<<"\n----------------------------\n";
    			cout<<"**** Displaying Question Information ****";
    			cout<<"\n----------------------------";
    			for(int i=0; i<NoOfQuestions; i++)
    			{
    				cout<<"\nQuestion No. : "<<i+1;
    				cout<<"\nQuestion Id : "<<questions[i]->getQueID();
    				cout<<"\nQuestion Type : "<<questions[i]->getQueType();
    				cout<<"\nQuestion Marks : "<<questions[i]->getQueMarks();
    				cout<<"\n----------------------------";
    			}
    		}
    	
    };
    
    main()
    {
    	
    	cout<<"\n\t\tCS304 Assignment No. 2 Solution \n";
    	cout<<"\nPlease Subscribe Cyberian Youtube Channel to get Solutions of all Programming Assignments\n\n";
    	string type, code;
    	cout<<"Enter Exam Type : ";
    	getline(cin, type);
    	cout<<"Enter Course Code : ";
    	getline(cin, code);
    	
    	Exam exm1(type,code);
    	
    	exm1.DisplayInfo();
    }
    

  • Cyberian's Gold

    Please share idea solution



Quiz 100% Result Quiz 100% Result
| |