From 377c42ca0335021fdae31c66a7d27d913ea24bc6 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 9 Jan 2025 12:56:08 -0800 Subject: [PATCH] initial commit --- .envrc | 1 + .gitignore | 4 +++ cs010b_work.c | 12 ++++++++ flake.lock | 27 ++++++++++++++++++ flake.nix | 61 +++++++++++++++++++++++++++++++++++++++++ meson.build | 10 +++++++ src/chapter_1/lab_1.cpp | 53 +++++++++++++++++++++++++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 cs010b_work.c create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 meson.build create mode 100644 src/chapter_1/lab_1.cpp diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9690ec8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +result +.direnv +build +.cache diff --git a/cs010b_work.c b/cs010b_work.c new file mode 100644 index 0000000..4d3d7e0 --- /dev/null +++ b/cs010b_work.c @@ -0,0 +1,12 @@ +#include + +#define PROJECT_NAME "cs010b-work" + +int main(int argc, char **argv) { + if(argc != 1) { + printf("%s takes no arguments.\n", argv[0]); + return 1; + } + printf("This is project %s.\n", PROJECT_NAME); + return 0; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cd9dd2e --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1736344531, + "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9aa1880 --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in + { + packages = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.callPackage ( + { + stdenv, + meson, + ninja, + }: + stdenv.mkDerivation { + pname = "cs010b-work"; + version = "unstable"; + + src = ./.; + + nativeBuildInputs = [ + meson + ninja + ]; + } + ) { }; + } + ); + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + + packages = with pkgs; [ + clang-tools_19 + mesonlsp + ]; + }; + } + ); + }; +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..51fddf7 --- /dev/null +++ b/meson.build @@ -0,0 +1,10 @@ +project( + 'cs010b-work', + 'cpp', + version: '0.1', + default_options: ['warning_level=3', 'cpp_std=c++23'], +) + +lab_1 = executable('lab_1', 'src/chapter_1/lab_1.cpp', install: true) + +test('lab 1', lab_1) diff --git a/src/chapter_1/lab_1.cpp b/src/chapter_1/lab_1.cpp new file mode 100644 index 0000000..0b0c835 --- /dev/null +++ b/src/chapter_1/lab_1.cpp @@ -0,0 +1,53 @@ +#include +#include +using namespace std; + +bool inOrder(const vector &nums); + +int main() { + + vector nums1(5); + nums1.at(0) = 5; + nums1.at(1) = 6; + nums1.at(2) = 7; + nums1.at(3) = 8; + nums1.at(4) = 3; + + if (inOrder(nums1)) { + cout << "First vector is in order" << endl; + } else { + cout << "First vector is not in order" << endl; + } + + vector nums2(5); + + // Fill second vector with 5 integers entered by the user + + // Output whether second vector is in order or not in order + for (int i = 0; i < 5; i++) { + cin >> nums2.at(i); + } + + if (inOrder(nums2)) { + cout << "Second vector is in order" << endl; + } else { + cout << "Second vector is not in order" << endl; + } + + return 0; +} + +// Define your inOrder function here +bool inOrder(const vector &nums) { + if (nums.size() < 2) { + return true; + } + + for (int i = 0; i < nums.size() - 1; i++) { + if (nums[i] > nums[i + 1]) { + return false; + } + } + + return true; +}