From 4483699cc8cc937cb27040cfbd809b8a90029391 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 5 Aug 2024 20:57:13 +0200 Subject: more exercises --- 3p6-v2.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 3p6-v2.cpp (limited to '3p6-v2.cpp') diff --git a/3p6-v2.cpp b/3p6-v2.cpp new file mode 100644 index 0000000..31a8cef --- /dev/null +++ b/3p6-v2.cpp @@ -0,0 +1,33 @@ +#include +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.6 v1 + * + * Stupid pointer version of this exercise because i wanted to. + * Though i will say, i definitely say we should be using the range for. So much simpler. + * This version is also way too hard to read especially compared to the other characters. + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +int main () { + + string Xer; + cout << "Enter a string" << endl; + cin >> Xer; + decltype(&Xer[0]) Character; // make pointer + for(decltype(Xer.size()) Index = 0 ; Index != Xer.size() ; Index++ ) { // When index is same as Xer.size() we stop the loop + Character = &Xer[Index]; // Point towards address of character in index + *Character = 'X'; // replace it with X + } + + cout << Xer << endl; + return 0; +} -- cgit v1.2.3