Usman Lab O5
Usman Lab O5
CMS:410780
Department of Computing
CS 212: Object Oriented Programming
Lab05
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;
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;
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