0% found this document useful (0 votes)
19 views6 pages

C++ Assignment 1

The document is a programming assignment from Kanpur Institute of Technology for the Object Oriented System Design course, focusing on C++ solutions. It includes multiple tasks such as printing colors of shapes using enumeration, finding files with specific extensions, calculating the area of a rectangle with default arguments, and performing multiplication using function overloading. Each task is accompanied by code snippets and their respective outputs.

Uploaded by

singhsamar0026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

C++ Assignment 1

The document is a programming assignment from Kanpur Institute of Technology for the Object Oriented System Design course, focusing on C++ solutions. It includes multiple tasks such as printing colors of shapes using enumeration, finding files with specific extensions, calculating the area of a rectangle with default arguments, and performing multiplication using function overloading. Each task is accompanied by code snippets and their respective outputs.

Uploaded by

singhsamar0026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

KANPUR INSTITUTE OF TECHNOLOGY

(An Autonomous Institute of AKTU, Lucknow)

A- 1, UPSIDC Industrial Area, Rooma, Kanpur-208001 (U.P.) India

OBJECT ORIENTED SYSTEM DESIGN


WITH C++
(BCS-054)

Department of Computer Science & Engineering


Session 2025-26

Branch: Computer Science


Year: 3rd
Semester:5th
Submitted by:
Name: Samar Pratap
Singh

Roll No- 2301650100088


Section- B

Submitted to: Ms. Saba Nehal


1. WAP in C++ to print the colour of shapes(Circle,square
and diamond) using the enumeration.

➢ Solution:
#include <iostream>

using namespace std;

enum Color { RED, GREEN, BLUE };

struct Shape {

string name;

Color color;

};

void printColor(Color c) {

switch (c) {

case RED: cout << "Red"; break;

case GREEN: cout << "Green"; break;

case BLUE: cout << "Blue"; break;

default: cout << "Unknown"; break;

int main() {

Shape circle = {"Circle", RED};

Shape square = {"Square", GREEN};

Shape diamond = {"Diamond", BLUE};

cout << circle.name << " color is ";

printColor(circle.color);

cout << endl;

cout << square.name << " color is ";


printColor(square.color);

cout << endl;

cout << diamond.name << " color is ";

printColor(diamond.color);

cout << endl;

return 0;

OUT PUT:

• Circle color is Red

• Square color is Green

• Diamond color is Blue

2. WAP in C++ to find the file which is saved on your system


using enum.

➢ Solution:

#include <iostream>
#include <filesystem>
#include <string>
using namespace std;
namespace fs = std::filesystem;

// Enum for file type categories


enum FileType {
TEXT,
IMAGE,
PDF,
OTHER
};

// Function to guess file type from extension


FileType getFileType(const string& filename) {
if (filename.ends_with(".txt")) return TEXT;
else if (filename.ends_with(".jpg") || filename.ends_with(".png")) return IMAGE;
else if (filename.ends_with(".pdf")) return PDF;
else return OTHER;
}

int main() {
string searchFile;
cout << "Enter file name to search (with extension): ";
cin >> searchFile;

string path = "."; // current directory


bool found = false;

for (const auto& entry : fs::recursive_directory_iterator(path)) {


if (entry.path().filename() == searchFile) {
cout << "File found at: " << entry.path() << endl;

FileType type = getFileType(searchFile);


switch(type) {
case TEXT: cout << "File type: TEXT file\n"; break;
case IMAGE: cout << "File type: IMAGE file\n"; break;
case PDF: cout << "File type: PDF file\n"; break;
default: cout << "File type: OTHER\n"; break;
}
found = true;
break;
}
}

if (!found) {
cout << "File not found in the directory." << endl;
}

return 0;
}

INPUT:
Enter file name to search (with extension): notes.txt
OUT PUT:
File found at: ./notes.txt
File type: TEXT file
3. WAP in C++ to find the area of a rectangle using default arguments.
➢ Solution:

#include <iostream>
using namespace std;
int area(int length = 10, int breadth = 5)
{
return length * breadth;
}
int main()
{
cout << "Area with default values: " << area() << endl;
cout << "Area with length = 15 (default breadth): " << area(15) << endl;
cout << "Area with length = 12 and breadth = 8: " << area(12, 8) << endl;
return 0;
}

OUT PUT

• Area with default values: 50


• Area with length = 15 (default breadth): 75
• Area with length = 12 and breadth = 8:

4. WAP in C++ to print the multiplication of 2 integers using function


overloading.

➢ Solution:
#include <iostream>
using namespace std;

int multiply(int a, int b) {


return a * b;
}

float multiply(float a, float b) {


return a * b;
}

float multiply(int a, float b) {


return a * b;
}

float multiply(float a, int b) {


return a * b;
}

int main() {
int a = 55, b = 14;
float x = 36.05f, y = 24.088f;

cout << "Multiplication of 55 and 14 (int): " << multiply(a, b) << endl;
cout << "Multiplication of 36.05 and 24.088 (float): " << multiply(x, y) << endl;
cout << "Multiplication of 55 and 24.088 (int, float): " << multiply(a, y) << endl;
cout << "Multiplication of 36.05 and 14 (float, int): " << multiply(x, b) << endl;

return 0;
}

OUT PUT:

• Multiplication of 55 and 14 (int): 770


• Multiplication of 36.05 and 24.088 (float): 869.574
• Multiplication of 55 and 24.088 (int, float): 1324.84
• Multiplication of 36.05 and 14 (float, int): 504.7

You might also like