Skip to content

Commit

Permalink
CRUD operation on Array (#61)
Browse files Browse the repository at this point in the history
* CRUD operation on Array

* CRUD operation on Array
  • Loading branch information
chaudharykapil authored Oct 21, 2022
1 parent a168165 commit 2734df3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\mingw\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
46 changes: 46 additions & 0 deletions CPP/Array/Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<iostream>
using namespace std;
void CreateArray(int *arr,int n){
for(int i = 0;i<n;i++){
cout << "Enter Element" << i+1 << " : ";
cin >> arr[i];
}

}

void PrintArray(int *arr,int n){
for(int i=0;i<n;i++){
cout << arr[i] << ", ";
}
cout << "\n";
}

void UpdateElemet(int *arr,int n,int i){
if(i>=n){
cout << "Invalid Index";
return;
}
cout << "Enter new Element : ";
cin >> arr[i];
}
int DeteteElemet(int *arr,int n,int i){
for(int x = i;x<n-1;x++){
arr[x] = arr[x+1];
}
return --n;
}

int main(){
int n;
cout << "Enter the number of elements in array: ";
cin >> n;
int arr[n];
CreateArray(arr,n);
PrintArray(arr,n);
UpdateElemet(arr,n,2);
PrintArray(arr,n);
n = DeteteElemet(arr,n,3);
PrintArray(arr,n);
return 0;

}
Binary file added CPP/Array/Array.exe
Binary file not shown.
Binary file added CPP/Array/a.exe
Binary file not shown.

0 comments on commit 2734df3

Please sign in to comment.