Skip to content

Commit

Permalink
"Updated variable naming conventions in multiple files, including C a…
Browse files Browse the repository at this point in the history
…nd JavaScript code, and modified MongoDB schema definitions in Express.js models."
  • Loading branch information
Code-With-Abhishek-Kumar committed Sep 7, 2024
1 parent 1ce34b3 commit 3af1189
Show file tree
Hide file tree
Showing 19 changed files with 984 additions and 14 deletions.
30 changes: 30 additions & 0 deletions C/03_Day_Variable/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ When programming in C, adhering to proper variable naming conventions is essenti
- While there is no strict limit on variable name length, most compilers support up to 31 characters for variable names (though modern compilers may support longer names). It's good practice to use meaningful and concise names.
- **Best Practice:** Keep names reasonably short but descriptive.






## Naming Convention

1. **camelCase**

- Start with lowercase letter. Capitalize the first letter of each subsequent word.

- Example : `myVariableName`


2. **snake_case**


- Start with an lowercase letter . Separate words with underscore.

- Example : `my_variable_name`



Keep a Good and Short Name

- Choose names that are descriptive but not too long. It should make it easy to understand the variable's purpose.


- Example : `age` , `first_name` , `isMarried`;

## Best Practices for Naming Variables

1. **Use Descriptive Names:**
Expand Down
6 changes: 6 additions & 0 deletions C/04_Format Specifiers/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"*.ejs": "html",
"stdio.h": "c"
}
}
Binary file added C/04_Format Specifiers/StartedCode/index
Binary file not shown.
47 changes: 47 additions & 0 deletions C/04_Format Specifiers/StartedCode/index.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>

int main() {
// Defining variables of different types
int age = 30; // Integer variable
float height = 5.9; // Floating-point variable
char initial = 'A'; // Character variable
char name[] = "Alice"; // String variable

// Displaying an integer value
printf("Age: %d\n", age); // %d format specifier displays an integer

// Displaying a floating-point value with one decimal place
printf("Height: %.1f meters\n", height); // %.1f format specifier displays a float with one decimal place

// Displaying a single character
printf("Initial: %c\n", initial); // %c format specifier displays a single character

// Displaying a string
printf("Name: %s\n", name); // %s format specifier displays a string

// Demonstrating unsigned integer
unsigned int score = 150; // Unsigned integer variable
printf("Score: %u\n", score); // %u format specifier displays an unsigned integer

// Demonstrating hexadecimal format
int hexValue = 255; // Integer variable
printf("Hexadecimal: %x\n", hexValue); // %x format specifier displays an integer in hexadecimal format

// Demonstrating scientific notation for floating-point numbers
float largeNumber = 123456.789; // Floating-point variable
printf("Large Number: %e\n", largeNumber); // %e format specifier displays a float in scientific notation

// Demonstrating pointer format
int *ptr = &age; // Pointer to integer
printf("Address of age: %p\n", (void*)ptr); // %p format specifier displays the memory address of the pointer

// Demonstrating width and precision
float preciseValue = 3.14159; // Floating-point variable
printf("Precise Value: %.3f\n", preciseValue); // %.3f format specifier displays a float with three decimal places

// Demonstrating width with padding
int number = 42; // Integer variable
printf("Number with width: %5d\n", number); // %5d format specifier displays an integer with a minimum width of 5, padded with spaces

return 0;
}
120 changes: 120 additions & 0 deletions C/04_Format Specifiers/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# C Format Specifiers

In many programming languages (like Python, Java, and C++), you use print functions to display the value of a variable. However, in C, things are a bit different.

In C programming, format specifiers are used in functions like `printf` and `scanf` to control the format of input and output. These specifiers tell the function how to interpret or display the data. They are crucial because C does not have higher-level features for formatted input and output like some other languages do.



**C programming mein, format specifiers `printf` aur `scanf` jese functions mein use kiye jaate hain taaki input aur output ka format control kiya ja sake. Ye specifiers batate hain ki data ko kaise samjha ya dikhaya jayega. Ye zaroori hote hain kyunki C mein formatted input aur output ke liye high-level features nahi hote jaise kuch dusri programming languages mein hote hain.**




<table>
<thead>
<tr>
<th>Format Specifier</th>
<th>Description</th>
<th>Example Syntax</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>%c</strong></td>
<td>For character type</td>
<td><code>printf("%c", 'A');</code></td>
</tr>
<tr>
<td><strong>%d</strong></td>
<td>For signed integer type</td>
<td><code>printf("%d", -123);</code></td>
</tr>
<tr>
<td><strong>%e</strong> or <strong>%E</strong></td>
<td>For scientific notation of floats</td>
<td><code>printf("%e", 123.456);</code></td>
</tr>
<tr>
<td><strong>%f</strong></td>
<td>For float type</td>
<td><code>printf("%f", 3.14);</code></td>
</tr>
<tr>
<td><strong>%g</strong> or <strong>%G</strong></td>
<td>For float type with the current precision</td>
<td><code>printf("%g", 0.000123);</code></td>
</tr>
<tr>
<td><strong>%i</strong></td>
<td>For signed integer type (same as <strong>%d</strong>)</td>
<td><code>printf("%i", -123);</code></td>
</tr>
<tr>
<td><strong>%ld</strong> or <strong>%li</strong></td>
<td>For long integer type</td>
<td><code>printf("%ld", 1234567890L);</code></td>
</tr>
<tr>
<td><strong>%lf</strong></td>
<td>For double type</td>
<td><code>printf("%lf", 3.1415926535);</code></td>
</tr>
<tr>
<td><strong>%Lf</strong></td>
<td>For long double type</td>
<td><code>printf("%Lf", 3.14159265358979L);</code></td>
</tr>
<tr>
<td><strong>%lu</strong></td>
<td>For unsigned int or unsigned long</td>
<td><code>printf("%lu", 123456789UL);</code></td>
</tr>
<tr>
<td><strong>%lli</strong> or <strong>%lld</strong></td>
<td>For long long integer type</td>
<td><code>printf("%lld", 123456789012345LL);</code></td>
</tr>
<tr>
<td><strong>%llu</strong></td>
<td>For unsigned long long</td>
<td><code>printf("%llu", 123456789012345ULL);</code></td>
</tr>
<tr>
<td><strong>%o</strong></td>
<td>For octal representation</td>
<td><code>printf("%o", 255);</code></td>
</tr>
<tr>
<td><strong>%p</strong></td>
<td>For pointer type</td>
<td><code>printf("%p", (void *)&num);</code></td>
</tr>
<tr>
<td><strong>%s</strong></td>
<td>For string type</td>
<td><code>printf("%s", "Hello, world!");</code></td>
</tr>
<tr>
<td><strong>%u</strong></td>
<td>For unsigned int</td>
<td><code>printf("%u", 123456);</code></td>
</tr>
<tr>
<td><strong>%x</strong> or <strong>%X</strong></td>
<td>For hexadecimal representation</td>
<td><code>printf("%x", 255);</code></td>
</tr>
<tr>
<td><strong>%n</strong></td>
<td>Prints nothing but stores the number of characters printed so far into an integer variable</td>
<td><code>printf("Count: %n", &count);</code></td>
</tr>
<tr>
<td><strong>%%</strong></td>
<td>Prints the % character</td>
<td><code>printf("Percentage: %%");</code></td>
</tr>
</tbody>
</table>

17 changes: 17 additions & 0 deletions C/06_Day_Data_Type/Starter Code/dataType.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>


int main(){
/**
* Declares and initialise an integer variable.
*/

int a = 12;

/**
* use %d if you want to print a number
*/

float out;
printf("%d" , a);
}
Binary file added C/06_Day_Data_Type/Starter Code/readme.md
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { Schema , model} from "mongoose";


const categorySchema = new Schema({
name: {
cName: {
type: String,
required: true,
unique: true,
lowercase: true,
},
description: {
cDescription: {
type: String,
required: true,
unique: true,
lowercase: true,
},
photo: {
cPhoto: {
type: String,

},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import mongoose, { Schema, model } from "mongoose";

const orderItemSchema = new Schema({
productId: {
type: mongoose.Schema.ObjectId,
ref: "product",
},
quantity: {
type: Number,
require: true,
},
});

let OrderModel = new Schema(
{
oPrice: {
type: Number,
require: true,
},

oItems: {
type: [orderItemSchema],
},
address:{
type:String,
require:true,
},

status:{
type: String,
enum: ['Pending' , 'Cancelled' , 'Delivered'],
default: 'Pending',

},

customer: {
type: mongoose.Schema.ObjectId,
ref: "user",
},
},
{ timestamps: true }
);

export const Category = model("Category", OrderModel);
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,50 @@ import mongoose, { Schema, model } from "mongoose";


let productSchema = new Schema({
name:{
Pname:{
type: String,
require: true,
lowercase : true,
},

description:{
pColor:{
type: String,
require: true,
lowercase : true,
},


pDescription:{
type: String,
require: true,
lowercase : true,
},

price:{
pPrice:{
type: Number,
require: true,
lowercase : true,
},

stock:{
pStock:{
type: Number,
default : 1,
},

discount:{
pDiscount:{
type: Number,
require: true,
lowercase : true,
},


category:{
pCategory:{
type: Schema.Types.ObjectId,
ref: 'category',
require: true,

},
photo:{
pImage:{
type: String,

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Schema , model} from "mongoose";

const userSchema = new Schema(
{
username: {
userName: {
type: String,
required: true,
unique: true,
Expand Down
Loading

0 comments on commit 3af1189

Please sign in to comment.