NATIONAL UNIVERSITY OF TECHNOLOGY
Main I.J.P Road, Sector I-12 Islamabad
Instructor Name: Ma’am Saman
Course: Data Structures
Batch: CS 2022
Assignment: 01
Submitted by: Israr Qayyum
Student ID: F22605004
Question 1
Code:
#include <iostream>
using namespace std;
int main() {
double amount, taxPercent;
cout << "Enter the amount: ";
cin >> amount;
cout << "Enter the tax percent: ";
cin >> taxPercent;
double salesTax = amount * (taxPercent / 100.0);
cout << "Sales Tax: " << salesTax << endl;
return 0;
Output:
Question 2
Code:
#include <iostream>
using namespace std;
int main() {
int years;
cout << "Enter the number of years: ";
cin >> years;
int minutes = years * 365 * 24 * 60;
int seconds = years * 365 * 24 * 60 * 60;
cout << "Number of Minutes: " << minutes << endl;
cout << "Number of Seconds: " << seconds << endl;
return 0;
Output:
Question 3
Code:
#include <iostream>
using namespace std;
int main() {
int rows, cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
int originalMatrix[rows][cols];
cout << "Enter the matrix elements row by row:\n";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << "Enter element at position (" << i + 1 << ", " << j + 1 << "): ";
cin >> originalMatrix[i][j];
int transposeMatrix[cols][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposeMatrix[j][i] = originalMatrix[i][j];
cout << "Transpose of the matrix:\n";
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
cout << transposeMatrix[i][j] << " ";
cout << endl;
return 0;
Output:
Question 4
Code:
#include <iostream>
using namespace std;
class Employee {
protected:
string name;
string jobTitle;
string dateOfJoining;
public:
Employee(const string& name, const string& jobTitle, const string& dateOfJoining)
: name(name), jobTitle(jobTitle), dateOfJoining(dateOfJoining) {
void displayInfo() {
cout << "Name: " << name << endl;
cout << "Job Title: " << jobTitle << endl;
cout << "Date of Joining: " << dateOfJoining << endl;i
};
class Teacher : public Employee {
protected:
string qualification;
public:
Teacher(const string& name, const string& jobTitle, const string& dateOfJoining, const string&
qualification)
: Employee(name, jobTitle, dateOfJoining), qualification(qualification) {
void displayInfo() {
Employee::displayInfo();
cout << "Qualification: " << qualification << endl;
};
class RegularTeacher : public Teacher {
protected:
double monthlySalary;
public:
RegularTeacher(const string& name, const string& dateOfJoining, const string& qualification,
double monthlySalary)
: Teacher(name, "Regular Teacher", dateOfJoining, qualification),
monthlySalary(monthlySalary) {
void displayInfo() {
Teacher::displayInfo();
cout << "Monthly Salary: $" << monthlySalary << endl;
};
class VisitingTeacher : public Teacher {
protected:
double payRate;
int hoursWorked;
public:
VisitingTeacher(const string& name, const string& dateOfJoining, const string& qualification,
double payRate, int hoursWorked)
: Teacher(name, "Visiting Teacher", dateOfJoining, qualification), payRate(payRate),
hoursWorked(hoursWorked) {
void displayInfo() {
Teacher::displayInfo();
cout << "Pay Rate: $" << payRate << " per hour" << endl;
cout << "Hours Worked in a Month: " << hoursWorked << " hours" << endl;
};
class Manager : public Employee {
protected:
int totalExperience;
public:
Manager(const string& name, const string& dateOfJoining, int totalExperience)
: Employee(name, "Manager", dateOfJoining), totalExperience(totalExperience) {
void displayInfo() {
Employee::displayInfo();
cout << "Total Experience: " << totalExperience << " years" << endl;
};
int main() {
RegularTeacher regularTeacher("Usman", "2023-05-15", "Masters in Education", 4500.0);
VisitingTeacher visitingTeacher("Ahmed", "2022-03-10", "Bachelor in English", 25.0, 120);
Manager manager("Mohsin", "2021-09-20", 15);
cout << "Teacher Information:" << endl;
regularTeacher.displayInfo();
cout << "\nVisiting Teacher Information:" << endl;
visitingTeacher.displayInfo();
cout << "\nManager Information:" << endl;
manager.displayInfo();
return 0;
Output: