Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Raghuwarna_19/Command_Line_Arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

int main(int argc, char* argv[]) {
std::cout << "Number of arguments: " << argc << std::endl;

for (int i = 0; i < argc; ++i) {
std::cout << "Argument " << i << ": " << argv[i] << std::endl;
}

return 0;
}
31 changes: 31 additions & 0 deletions Raghuwarna_19/Error_Handling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <fstream>
#include <string>

void readFile(const std::string& filename) {
std::ifstream file;
file.open(filename);

if (!file.is_open()) {
throw std::runtime_error("Error: Unable to open file.");
}

std::string line;
while (std::getline(file, line)) {
std::cout << line << std::endl;
}

file.close();
}

int main() {
std::string filename = "example.txt";

try {
readFile(filename);
} catch (const std::exception& e) {
std::cerr << "Exception caught: " << e.what() << std::endl;
}

return 0;
}
33 changes: 33 additions & 0 deletions Raghuwarna_19/Extraction_Insertion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;

class ComplexNumber {
private:
double real;
double imaginary;

public:
ComplexNumber(double r = 0, double i = 0) : real(r), imaginary(i) {}

friend ostream& operator<<(ostream& os, const ComplexNumber& cn) {
os << cn.real << " + " << cn.imaginary << "i";
return os;
}

friend istream& operator>>(istream& is, ComplexNumber& cn) {
cout << "Enter real part: ";
is >> cn.real;
cout << "Enter imaginary part: ";
is >> cn.imaginary;
return is;
}
};

int main() {
ComplexNumber cn1;
cout << "Enter a complex number:" << endl;
cin >> cn1;
cout << "The complex number is: " << cn1 << endl;

return 0;
}
27 changes: 27 additions & 0 deletions Raghuwarna_19/File_Pointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <fstream>

int main() {
std::ofstream file("example.txt");

if (file.is_open()) {
file << "Hello, File Pointers!";
file.close();
} else {
std::cout << "Unable to open file";
}

std::ifstream readFile("example.txt");

if (readFile.is_open()) {
std::string content;
while (getline(readFile, content)) {
std::cout << content << std::endl;
}
readFile.close();
} else {
std::cout << "Unable to open file";
}

return 0;
}