You are on page 1of 7

Assignment No.

2 Total Marks: 20

Semester: Spring 2022


Due Date: 19/8/2022
CS201 – Introduction to Programming

For Paid Assignment


Ready in MS Word
click here
https://api.whatsapp.co
m/send?phone=+92317
5751690

Instructions
Please read the following instructions carefully before submitting the assignment
solution:
It should be clear that your assignment will not get any credit/marks if:
o Assignment is submitted after due date.
o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).
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.
Lectures Covered: Lecture # 23 - 29

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 Friend function of Student Class
-vac_name[10]:char display (Student std)
- age:int
- num_dose:int

+ setName(const char[])
+ setVaccine(const char[])
+ setAge(int)
+ setDose(int)
+ getName()
+ getVaccine();
+ getAge();
+ getDose();

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 Sinovac 20 1
studentID here
BC123456789 Sinopharm 21 2
MC123456789 Moderna 22 3
Table 1

Sample Output:

NOTE: Student’s id is supposed values (not real) in above example.


You will print your own VU Id, otherwise you will get zero
marks.
Lectures Covered: Lecture # 23 - 29
Due Date: 19/8/2022

Solution:
For Paid Assignment
Ready in MS Word
click here
https://api.whatsapp.co
m/send?phone=+92317
5751690

#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;
}

You might also like