initial commit

This commit is contained in:
Youwen Wu 2025-01-09 12:56:08 -08:00
commit 377c42ca03
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
7 changed files with 168 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
result
.direnv
build
.cache

12
cs010b_work.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdio.h>
#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;
}

27
flake.lock Normal file
View file

@ -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
}

61
flake.nix Normal file
View file

@ -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
];
};
}
);
};
}

10
meson.build Normal file
View file

@ -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)

53
src/chapter_1/lab_1.cpp Normal file
View file

@ -0,0 +1,53 @@
#include <iostream>
#include <vector>
using namespace std;
bool inOrder(const vector<int> &nums);
int main() {
vector<int> 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<int> 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<int> &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;
}