0% found this document useful (0 votes)
23 views4 pages

Usman Lab O5

Uploaded by

Shani Warraich
Copyright
© © All Rights Reserved
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)
23 views4 pages

Usman Lab O5

Uploaded by

Shani Warraich
Copyright
© © All Rights Reserved
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/ 4

Name: Muhammad Usman Khawar

CMS:410780

Department of Computing
CS 212: Object Oriented Programming
Lab05

Date: 9th October, 2023

Instructor: Mehreen Tahir

Lab Engineer: Mehwish Kiran


Task# 01

Header 1

#include<iostream>
#include<string>
using namespace std;

class Gradebook{
public:
Gradebook(string);
void setcourseName(string);
string getcourseName();
void display_message();
private:
string courseName;
};
Source 1

#include <iostream>
#include <string>
#include "Gradebook.h"
using namespace std;

Gradebook::Gradebook(std::string name) { courseName = name; }


void Gradebook::setcourseName(std::string name) {
courseName = name;
}
string Gradebook::getcourseName() {
return courseName;
}
void Gradebook::display_message() {
cout << "Welcome to the grade book for: " << courseName << "!\n";
}

Source 2
#include<iostream>
#include<string>
#include "Gradebook.h"
using namespace std;

int main(){
Gradebook gradebook_1("CS101 Fundamentals of Computer programming");
Gradebook gradebook_2("CS201 Object Oriented Programming");
cout << "Grade book 1 created for course " << gradebook_1.getcourseName() << "!!!\
n";
gradebook_2.display_message();
return 0;

}
Output

Task# 02

Header 2

#include <iostream>
using namespace std;

//Creating the class


class Conversion{
double data;
public:
Conversion(double);
void setData(double);
double getData();
void length();
void weight();
void temperature();
};
void display();

Source 2

#include <iostream>
#include "Conversion.h"
using namespace std;

void display(){
cout << "--------------------------------------------------\n";
cout << "Welcome to the unit conversion app\n";
cout << "Enter 1 to convert length\n";
cout << "Enter 2 to convert weight\n";
cout << "Enter 3 to convert temperature\n";
cout << "--------------------------------------------------\n";
}
Conversion::Conversion(double d) {
data = d;
}
void Conversion::setData(double d) {
data = d;
}
double Conversion::getData() {
return data;
}

void Conversion::length() {
cout << "The length given is: " << data << " feet\n";
cout << "The converted length is: " << data / 3.2840 << " meters\n";
}
void Conversion::weight() {
cout << "The weight given is: " << data << " pounds\n";
cout << "The converted weight is: " << data*0.4535 << " kilograms\n";
}
void Conversion::temperature() {
cout << "The temperature given is: " << data << " Fahrenheit\n";
cout << "The converted temperature is: " << (data - 32) * 5 / 9 << " meters\n";
}

Source 2

#include <iostream>
#include "Conversion.h"
using namespace std;

int main(){
int input;
float num;
display();
cin >> input;
cout << "Enter the number to be converted:\n";
cin >> num;
Conversion d(num);
if (input == 1){
d.length();
}if (input == 2){
d.weight();
}if (input == 3){
d.temperature();
}
return 0;
}

Output

You might also like