google.com, pub-3534375712831849, DIRECT, f08c47fec0942fa0 CS201 Assignment 2 Solution Spring 2022 | Download solution in PDF from Website Free Assignment / GDB
Latest Updates
Loading...

CS201 Assignment 2 Solution Spring 2022 | Download solution in PDF from Website Free Assignment / GDB






Required Tools

  • Dev C++ 

Assignment Submission Instructions

You have to submit only “.cpp” file of your code on the assignments interface from your LMS account.

Assignment submitted in any other format will not be accepted and will be scaled with zero marks. No excuse will be accepted on submitting solution file in any other format.

For any query related to assignment, please contact cs201@vu.edu.pk


Problem Statement:

XYZ institute has collected data regarding covid-19 vaccinated students of age group 18-24yrs . On the basis of provided data a programmer can manage information in a way that it will be available to the Administration ONLY. Students’ details will include, Student Name, Vaccine Name, Student Age, and Number of doses taken.

 

Create a class Student as per the programming constructs given in class diagram below.

 

Student

-std_id[20]:char

-vac_name[10]:char

- age:int

- num_dose:int

 

+ setName(const char[])

+ setVaccine(const char[])

+ setAge(int)

+ setDose(int)

+ getName()

+ getVaccine();

+ getAge();

+ getDose();

 

 

Friend function of Student Class

display (Student std)


Task to be performed:

Ø  Create class objects std1, std2 and std3 of class Student.

Ø  Use default constructor to assign default data values to the class object std1.

Ø  Use parameterized constructor to assign data values to the class object std2.

Ø  Use Setter() and Getter() methods to assign and print values of the class object std3.

Ø  Use Friend function display() for objects std1 and std2 only.

Ø  You will print data values of object std3 using getName(), getVaccine(), getAge(), getDose() and getter() member functions.

Note:

Ø  You will ONLY use given data values in Table1 for the class Student objects std1, std2 and std3 respectively.

 

Student ID

Vaccine Name

Student Age

Number of doses

Enter your own VU studentID here

Sinovac

20

1

BC123456789

Sinopharm

21

2

MC123456789

Moderna

22

3

Table 1

 

Sample Output:





Solution:

#include<iostream>

#include<string.h>


using namespace std;


class Student{

private:

char std_id[20];

char vac_name[10];

int age;

int num_dose;

public:

Student();

Student(const char*,const char*, int, int);

void setName(const char*);

void setVaccine(const char*);

void setAge(int);

void setDose(int);

string getName();

string getVaccine();

int getAge();

int getDose();

void friend display(Student std){

cout<<"Student ID : "<<std.getName()<<endl;

cout<<"Age : "<<std.getAge()<<endl;

cout<<"Vaccination : "<<std.getVaccine()<<endl;

cout<<"Vaccined Dose : "<<std.getDose();

}

};

Student::Student(){

strcpy(std_id, "BS200201121");

strcpy(vac_name, "Sinovac");

age=20;

num_dose = 1;

}

Student::Student(const char* id, const char* vac, int age, int dose){

setName(id);

setVaccine(vac);

setAge(age);

setDose(dose);

}

void Student::setName(const char* id){

strcpy(std_id,id);

}

void Student::setVaccine(const char* vac){

strcpy(vac_name, vac);

}

void Student::setAge(int _age){

age = _age;

}

void Student::setDose(int dose){

num_dose = dose;

}

string Student::getName(){

return std_id;

}

string Student::getVaccine(){

return vac_name;

}

int Student::getAge(){

return age;

}

int Student::getDose(){

return num_dose;

}

int main(){

Student std1, std2("BC123456789", " Sinopharm", 21,2), std3;

std3.setName("MC123456789");

std3.setVaccine("Moderna");

std3.setAge(22);

std3.setDose(3);

cout<<"Printing std1 object values using display().........."<<endl;

display(std1);

cout<<"\nPrinting std2 object values using display().........."<<endl;

display(std2);

cout<<"\nPrinting std3 object values using getter method.........."<<endl;

cout<<"Student Id : "<<std3.getName()<<endl;

cout<<"Age : "<<std3.getAge()<<endl;

cout<<"Vaccination : "<<std3.getVaccine()<<endl;

cout<<"Vaccination Dose : "<<std3.getDose()<<endl;

return 0;

}


Download Question File and Solution

Download File Now 

 

Get Paid Services (Word Ready File)


Want more info, please press the below button




`

Post a Comment

0 Comments