|
CS201 ASSIGNMENT NO. 2 SPRING 2022 |
CS201 ASSIGNMENT NO. 2 SPRING 2022 || 100% RIGHT SOLUTION|| INTRODUCTION TO PROGRAMMING || BY VuTech
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
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
-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:
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
//visit: www.vutechofficial.blogspot.com for more updates
//For solution file, Link is available in description.
#include<iostream>
#include<string.h>
using namespace std;
class Student {
private:
char std_id[40];
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<<" Vaccinated Doses: "<<std.getDose();
}
};
Student::Student(){
strcpy(std_id, " Enter your own VU studentID here "); //ENTER YOUR VUID
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<<"\nPrinitng 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 Doses: " <<std3.getDose()<<endl;
return 0;
}