0mambia / programming-assignment

0 stars 0 forks source link

students details #1

Open 0mambia opened 10 months ago

0mambia commented 10 months ago

include

// Structure to represent a student struct Student { char registrationNumber[20]; char firstName[50]; char secondName[50]; float introToProgramming; float networking; float accounting; float operatingSystem; float computerApplications; };

// Function to calculate the average grade float calculateAverage(struct Student *student) { return (student->introToProgramming + student->networking + student->accounting + student->operatingSystem + student->computerApplications) / 5.0; }

int main() { // Creating an instance of the Student structure struct Student student;

// Getting input from the user
printf("Enter Registration Number: ");
scanf("%s", student.registrationNumber);

printf("Enter First Name: ");
scanf("%s", student.firstName);

printf("Enter Second Name: ");
scanf("%s", student.secondName);

printf("Enter Grade for Introduction to Programming: ");
scanf("%f", &student.introToProgramming);

printf("Enter Grade for Networking: ");
scanf("%f", &student.networking);

printf("Enter Grade for Accounting: ");
scanf("%f", &student.accounting);

printf("Enter Grade for Operating System: ");
scanf("%f", &student.operatingSystem);

printf("Enter Grade for Computer Applications: ");
scanf("%f", &student.computerApplications);

// Displaying the student details
printf("\nStudent Details:\n");
printf("Registration Number: %s\n", student.registrationNumber);
printf("Name: %s %s\n", student.firstName, student.secondName);
printf("Introduction to Programming: %.2f\n", student.introToProgramming);
printf("Networking: %.2f\n", student.networking);
printf("Accounting: %.2f\n", student.accounting);
printf("Operating System: %.2f\n", student.operatingSystem);
printf("Computer Applications: %.2f\n", student.computerApplications);

// Calculating and displaying the average grade
float average = calculateAverage(&student);
printf("Average Grade: %.2f\n", average);

return 0;

}

0mambia commented 10 months ago

compiler-is a program that translates a source program written in some high-level programming language into machine code for some computer architecture

source code - programming statements that are created by a programmer with a text editor or a visual programming tool and then saved in a file .

object code-refers to a compiled file which is produced when the source code is compiled with a C compiler

linkers-is a utility program that takes the object files produced by the assembler and compiler and the other code to join them into a single executable file.

using an example that is a program to add 2 numbers explain the compilation process of a c program:Here's the program:

include

int main() { // Declare variables to store two numbers int num1, num2;

// Prompt the user to enter two numbers
printf("Enter the first number: ");
scanf("%d", &num1);

printf("Enter the second number: ");
scanf("%d", &num2);

// Calculate the sum of the two numbers
int sum = num1 + num2;

// Display the result
printf("The sum is: %d\n", sum);

return 0;

} Now, compilation process step by step:

  1. The first step is to write your C code in a text editor or an integrated development environment (IDE). 2.The preprocessor is the first stage of compilation. It processes directives that start with #. In the given program, the #include directive tells the preprocessor to include the contents of the stdio.h header file. This file provides input/output functions. 3.Compilation: The actual compilation step translates the preprocessed code into assembly code. The -S flag is used to generate assembly code. 4.Assembly: The assembly code is then translated into machine code by the assembler. 5.Linking: Finally, the object file is linked with other necessary object files and libraries to create an executable file.
  2. After the compilation process is complete, you can run the executable

explain difference between a compiler and an interpreter;

Compiler: Compilers translate the entire source code of a program into machine code or an intermediate code before execution. This results in the creation of an executable file that can be run independently of the original source code. Interpreter: Interpreters, on the other hand, translate the source code line by line or statement by statement and execute it immediately. There is no separate compilation step, and the source code is not translated into an independent executable.

Compiler: The compiled code is executed directly by the computer's hardware. The entire program is translated before execution, and the user interacts with the compiled executable. Interpreter: The interpreter reads and executes the source code line by line during runtime. The program is not translated into machine code beforehand, and the user interacts with the interpreter during the execution.

Compiler: Compiled code generally tends to be more efficient in terms of execution speed because the translation is done beforehand, and the machine code is optimized for the target platform. Interpreter: Interpreted code may have a performance overhead because the translation occurs during runtime. However, modern interpreters often include just-in-time (JIT) compilation to improve performance.

Compiler: Once a program is compiled, it can be run independently of the compiler. Users only need the compiled executable to execute the program. Interpreter: The interpreter is required to execute the program. The source code needs to be available, and the interpreter must be present on the system where the program is run.

Compiler: Compiled code is generally less portable, as it is specific to the target architecture. To run on a different platform, the source code might need to be recompiled. Interpreter: Interpreted code is often more portable since the interpreter can be platform-independent. However, the interpreter itself needs to be available for each platform.

Compiler: Debugging compiled code can be more challenging because the relationship between the source code and the machine code is not always straightforward. Debug information might be generated to aid in debugging. Interpreter: Interpreters often provide better support for debugging since they execute the source code directly. Debugging tools can work with the original source code, simplifying the process.

list all main categories of operators available in C programming. The main categories of operators in C are:

  1. Arithmetic Operators:

    • + (Addition)
    • - (Subtraction)
    • * (Multiplication)
    • / (Division)
    • % (Modulus, gives the remainder of a division)
  2. Relational Operators:

    • == (Equal to)
    • != (Not equal to)
    • < (Less than)
    • > (Greater than)
    • <= (Less than or equal to)
    • >= (Greater than or equal to)
  3. Logical Operators:

    • && (Logical AND)
    • || (Logical OR)
    • ! (Logical NOT)
  4. Assignment Operators:

    • = (Assignment)
    • += (Addition assignment)
    • -= (Subtraction assignment)
    • *= (Multiplication assignment)
    • /= (Division assignment)
    • %= (Modulus assignment)
    • &= (Bitwise AND assignment)
    • |= (Bitwise OR assignment)
    • ^= (Bitwise XOR assignment)
    • <<= (Left shift assignment)
    • >>= (Right shift assignment)
  5. Increment and Decrement Operators:

    • ++ (Increment by 1)
    • -- (Decrement by 1)
  6. Bitwise Operators:

    • & (Bitwise AND)
    • | (Bitwise OR)
    • ^ (Bitwise XOR)
    • ~ (Bitwise NOT)
    • << (Left shift)
    • >> (Right shift)
  7. Conditional (Ternary) Operator:

    • ? : (Conditional operator)
  8. sizeof Operator:

    • sizeof (Returns the size of a data type or variable in bytes)
  9. Comma Operator:

    • , (Separates expressions in a statement, evaluates from left to right)
  10. Pointer Operators:

    • * (Dereference operator, also used for declaring pointers)
    • & (Address-of operator)