Semester 1 Labs and Workshop | BTech CSE Practical Guide
Semester 1 - Page 6: Labs and Workshop. A general practical revision guide with 18 numbered topics, answered viva questions, checked examples and three complete C17 programs. It is not an official experiment list or machine operating procedure. Your assigned lab manual and instructor safety instructions determine what you may do.
Topic map
- Manual, scope and safety before the experiment
- Lab record and reproducibility
- Algorithm, flowchart and test plan
- C build steps and diagnostics
- Input, number classification and arithmetic limits
- Loops, functions, recursion and prime testing
- Arrays, matrices, searching and sorting
- Strings, pointers, records and files
- Mean, spread and measurement uncertainty
- Resolution, zero correction and significant figures
- Simple pendulum: length, period and gravity
- Graphs, slopes and model checks
- Other physics experiments: match the prescribed manual
- Low-voltage circuit measurement and meter connections
- Workshop drawings, dimensions and fit checks
- Tools, rotating machinery and supervised work
- Robotics practical: roles, ratings and test conditions
- Viva, debugging and submission integrity
1. Manual, scope and safety before the experiment
The assigned lab manual determines assessed experiments, equipment, procedure and record format. This page is a general first-semester guide, not an approved operating procedure. Read hazards, prerequisites, emergency arrangements and permitted materials before starting. Obtain instructor approval for electrical, chemical or mechanical work. Never work on live mains from a web example or operate a machine without training. Stop when equipment, readings or behaviour differ from the expected safe state.
Answer: The approved local manual and instructor safety instructions. Resolve the difference before starting work.
2. Lab record and reproducibility
A useful record contains aim, theory, apparatus or software version, method, raw observations, calculations, actual output, result, limitations and references. Record conditions and units. Keep raw values unchanged and show corrections separately. A worked illustration is not evidence that you performed an experiment. Missing data must be marked missing, not replaced with a theory value. Record failures and fixes because they explain what was actually tested.
Answer: They allow the calculations to be checked and prevent rounded or interpreted values from being mistaken for observations.
3. Algorithm, flowchart and test plan
State the problem and valid input range before coding. Write an algorithm or pseudocode with clear branches and stopping conditions. A flowchart uses conventional input/output, process and decision symbols with labelled paths. Plan normal, boundary and invalid tests before relying on a successful run. Include expected behaviour, then compare actual results. A test that passes only for one convenient value is not enough to establish a general claim.
Answer: A test plan states cases and expected behaviour in advance. Sample output records what actually happened for specified inputs.
4. C build steps and diagnostics
C source is preprocessed, compiled and linked into an executable. Syntax errors, linker errors, runtime failures and wrong answers require different investigation. Use warnings as evidence to inspect, not something to silence blindly. The programs below use C17 and strict warnings. Run each as a separate file. Compiler success does not prove absence of undefined behaviour or logic errors; inspect contracts and test paths.
Answer: A compiler error prevents translation; a logic error may compile and run but produce the wrong behaviour.
5. Input, number classification and arithmetic limits
Check whether input conversion succeeded before using a value. State the accepted domain and guard division by zero. Signed integer overflow is not a safe wraparound rule in C. Floating-point results have finite precision and may be non-finite. For even or odd classification, n%2==0 detects even numbers, including negative even values. Do not assume that an arbitrary out-of-range numeric token is safely rejected by scanf; robust general parsing requires a bounded line and range-checked conversion.
Answer: Failed conversion may leave objects without the intended new value. Using them can produce invalid behaviour or misleading results.
6. Loops, functions, recursion and prime testing
Choose loops with clear bounds and write function preconditions. Recursion requires a base case and progress toward it; avoid deep unbounded recursion. Test factorial zero and overflow limits, Fibonacci base cases, digit operations and GCD as appropriate to the assignment. A prime test rejects values below 2 and checks possible divisors up to the square root. For positive integers, d<=n/d avoids the possible overflow of d*d. Existing C core notes provide the checked prime, GCD and factorial implementations.
Answer: The multiplication can overflow before the comparison. A mathematically correct bound needs a machine-safe implementation.
7. Arrays, matrices, searching and sorting
Validate count before indexing; for n elements, legal indices are 0 through n-1. Define what an empty input means before finding a minimum or maximum. Matrix addition needs equal dimensions; multiplication needs compatible inner dimensions. Linear search works on unsorted input; binary search needs the stated ordering. A sorting test should check ordering and preservation of the input elements, including duplicates. Do not hide the accepted size limit.
Answer: There is no first element or maximum to read for an empty array unless the interface defines a separate empty-case result.
8. Strings, pointers, records and files
A C string needs a terminating null character. Use bounded input and document truncation or rejection. Pass unsigned-char values to character classification functions when reading arbitrary byte values. Pointer access needs a valid live object and correct bounds. Structures group records; dynamic allocation requires size checks, failure handling and release. File work requires checking open, read, write and close outcomes as relevant. Practise these with the complete tested C core programs rather than copying fragments without contracts.
Answer: It may be dangling, out of bounds, misaligned or otherwise not point to a valid object for that operation.
9. Mean, spread and measurement uncertainty
Repeat measurements to examine variation, but repetition does not remove every bias. The sample mean is sum/n; sample standard deviation uses n-1 for n>1. For independent repeated readings under suitable conditions, uncertainty of the mean from repeatability is s/√n. Instrument calibration, resolution and other effects may add uncertainty. Type A and Type B describe evaluation methods, not a simple synonym for random and systematic error. Do not report only the preferred theoretical answer.
Answer: No. A shared systematic effect may remain in every trial and must be assessed separately.
10. Resolution, zero correction and significant figures
Resolution is an instrument reading increment; accuracy is agreement with a reference, and precision concerns repeated agreement. Inspect zero and calibration under the approved method. Define signed zero error so that corrected reading=observed reading-zero error. Vernier and micrometer least-count methods depend on instrument design; use the actual scale and manual. Round the final reported value to a precision justified by uncertainty, keeping guard digits in intermediate calculation.
Answer: Premature rounding can shift the final value. Round the reported result based on its justified uncertainty and units.
11. Simple pendulum: length, period and gravity
For a simple pendulum at small amplitude, T≈2Ļ√(L/g). Measure L from pivot to bob center and use the prescribed small-angle release without a push. Time N complete oscillations and use T=t/N. State timing and length uncertainties, air resistance and pivot effects. The formula assumes a suitable simple-pendulum model and small-angle approximation. A long-amplitude swing or an incorrectly measured length can invalidate the simple inference.
Answer: A similar start/stop timing error is spread over a larger total interval when computing period, though other errors still remain.
12. Graphs, slopes and model checks
Label axes, units and conditions. Use a table for raw values and a graph to test the model. A best-fit line uses all relevant points under a chosen fitting method; do not join noisy points and call that a fit. State whether the intercept is constrained and why. For pendulum data, T² versus L has ideal slope 4ϲ/g. A result should include the fit method and uncertainty where available. Outliers require a documented reason before exclusion.
Answer: The model and measurement process must justify that constraint. An unexamined offset can hide a systematic effect.
13. Other physics experiments: match the prescribed manual
First-year physics labs may include dimensional measurement, optical or electrical experiments, resonance, material properties and instrument calibration. The exact list varies. For every experiment, identify measured quantities, governing relation, calibration, graph or calculation and uncertainty sources. Follow the specified setup, not an invented universal list. Laser or high-voltage equipment requires the approved safety route. Do not look into beams or open protected equipment to obtain a reading.
Answer: Read the approved aim, theory, equipment limits and safety instructions, then ask the instructor about any unclear condition before operating it.
14. Low-voltage circuit measurement and meter connections
Use only the instructor-approved low-voltage setup. Verify wiring with the source off, meter mode, terminals, polarity and range before power is applied. A voltmeter measures across the element, in parallel; an ammeter measures branch current, in series. Never connect a current-mode meter directly across a source. Real meters load a circuit; component tolerance and source behaviour matter. Turn power off before changing connections and discharge stored energy as instructed.
Answer: Its path must carry the branch current being measured. Across a source it can create a low-resistance fault path.
15. Workshop drawings, dimensions and fit checks
A workshop record links the drawing, material, allowed tolerances, tools, procedure and inspection. Read real dimensions rather than measuring a resized screenshot. Check projection convention and identify reference surfaces. Record the approved process and actual fit or measurement. A plan to cut or drill is not a reason to omit a tool-specific safety check. An acceptable-looking part may still fail dimensional tolerance.
Answer: Manufactured dimensions vary; tolerances define the allowed range needed for function, fit and inspection.
16. Tools, rotating machinery and supervised work
Only trained permitted users should operate workshop machines. Use the approved guards, eye protection and material limits. Secure hair and loose clothing and remove jewellery under the local rules. Gloves can create entanglement hazards around rotating machinery; follow the machine-specific instruction rather than treating gloves as universally safe PPE. Keep hands away from moving tools and stop the machine before the permitted inspection or adjustment. Never remove guards or improvise a repair from these notes.
Answer: Rotating parts can catch gloves and pull the hand in. PPE must match the machine-specific risk and approved procedure.
17. Robotics practical: roles, ratings and test conditions
Separate sensor, controller, motor driver, actuator and power supply in the diagram. A controller pin is not a motor supply. Check voltage, current and mechanical limits through the approved low-voltage plan. Record sensor readings and the control rule before movement. Define track, lighting, load, trial count and success criterion. A closed-loop design measures output but still needs timing, gain and stability checks. Stop safely when behaviour is unexpected.
Answer: Many optical sensors depend on ambient light, so unrecorded changes may explain a different result and prevent reproducibility.
18. Viva, debugging and submission integrity
Explain the governing rule, preconditions, error cases, units and limitations in your own words. Show actual compile/run or measurement evidence when asked. A clean report does not justify fabricated results. Cite borrowed code or figures, state your own contribution and remove secrets or personal data from public submissions. Keep source files and raw records so a result can be checked. A failure is useful when its cause and next test are honestly explained.
Answer: State that it was not performed. An example calculation or simulated result must be labelled as such rather than presented as a measurement.
Three complete C17 lab programs
Run one file at a time. Each was compiled with gcc -std=c17 -Wall -Wextra -Wpedantic -Werror file.c -o program. There are 21 checked runs across the normal, boundary and rejection cases. The numeric examples require representable input tokens; the calculator is an ordinary classroom finite-double exercise, not a complete hostile-input parser.
Calculator with checked conversion and zero divisor
Input format is number, operator, number, such as 8 / 2. Supported operators are +, -, * and /. Floating-point results have implementation limits; extreme-input handling is not a claim of a portable arbitrary-precision parser.
#include <stdio.h>
#include <math.h>
int main(void) {
double a, b, result;
char op;
if (scanf("%lf %c %lf", &a, &op, &b) != 3 ||
!isfinite(a) || !isfinite(b)) {
puts("Invalid input");
return 1;
}
switch (op) {
case '+': result = a + b; break;
case '-': result = a - b; break;
case '*': result = a * b; break;
case '/':
if (b == 0.0) {
puts("Division by zero");
return 1;
}
result = a / b;
break;
default: puts("Invalid operator"); return 1;
}
if (!isfinite(result)) {
puts("Result outside finite range");
return 1;
}
printf("Result: %.3f\n", result);
return 0;
}
Checked first run input: 8 / 2
Result: 4.000
| Test | Observed outcome | Exit code |
|---|---|---|
| 8 / 2 | Result: 4.000 | 0 |
| 8 / 0 | Division by zero | 1 |
| 8 + 2 | Result: 10.000 | 0 |
| 8 ? 2 | Invalid operator | 1 |
| bad | Invalid input | 1 |
| nan + 2 | Invalid input | 1 |
| 1e308 * 1e308 | Result outside finite range | 1 |
Bounded array sum, mean, minimum and maximum
Input is count followed by that many numbers. Count must be a representable int from 1 to 20; values must be finite with magnitude at most 1000000. The bound keeps the sum finite in the tested implementation.
#include <stdio.h>
#include <math.h>
int main(void) {
int n;
double a[20], sum = 0.0, low, high;
if (scanf("%d", &n) != 1 || n < 1 || n > 20) {
puts("Invalid count");
return 1;
}
for (int i = 0; i < n; ++i) {
if (scanf("%lf", &a[i]) != 1 || !isfinite(a[i]) ||
fabs(a[i]) > 1000000.0) {
puts("Invalid value");
return 1;
}
sum += a[i];
}
low = high = a[0];
for (int i = 1; i < n; ++i) {
if (a[i] < low) low = a[i];
if (a[i] > high) high = a[i];
}
printf("sum=%.3f mean=%.3f min=%.3f max=%.3f\n",
sum, sum / n, low, high);
return 0;
}
Checked first run input: 3 2 4 6
sum=12.000 mean=4.000 min=2.000 max=6.000
| Test | Observed outcome | Exit code |
|---|---|---|
| 3 2 4 6 | sum=12.000 mean=4.000 min=2.000 max=6.000 | 0 |
| 0 | Invalid count | 1 |
| 21 | Invalid count | 1 |
| 3 -2 0 2 | sum=0.000 mean=0.000 min=-2.000 max=2.000 | 0 |
| 1 7 | sum=7.000 mean=7.000 min=7.000 max=7.000 | 0 |
| 2 3 bad | Invalid value | 1 |
| 1 inf | Invalid value | 1 |
Bounded line vowel count
Text-line exercise: accepts up to 79 characters before newline or end-of-file. Handles empty line and spaces, rejects longer lines. Embedded null bytes and arbitrary binary streams are outside this text-input contract.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
char line[80];
int ch, vowels = 0;
if (!fgets(line, sizeof line, stdin)) {
puts("No line");
return 1;
}
if (!strchr(line, '\n') && !feof(stdin)) {
ch = getchar();
if (ch != '\n' && ch != EOF) {
while ((ch = getchar()) != '\n' && ch != EOF) { }
puts("Line too long");
return 1;
}
}
line[strcspn(line, "\n")] = '\0';
for (size_t i = 0; line[i] != '\0'; ++i) {
int c = tolower((unsigned char)line[i]);
if (c == 'a' || c == 'e' || c == 'i' ||
c == 'o' || c == 'u') ++vowels;
}
printf("vowels=%d\n", vowels);
return 0;
}
Checked first run input: Hello World
vowels=3
| Test | Observed outcome | Exit code |
|---|---|---|
| Hello World | vowels=3 | 0 |
| empty line | vowels=0 | 0 |
| AEIOU | vowels=5 | 0 |
| short | vowels=1 | 0 |
| 79 characters | vowels=0 | 0 |
| 80 characters | Line too long | 1 |
| empty stream | No line | 1 |
Illustrative pendulum record and checked calculation
These are invented practice periods for calculation, not a record of an experiment. Assumed length is 1.00 m and each total time covers 20 oscillations. Do not submit this table as your observations.
| Trial | Length (m) | N | Total time (s) | T (s) | g (m/s²) |
|---|---|---|---|---|---|
| 1 | 1.00 | 20 | 40.20 | 2.01 | 9.7716 |
| 2 | 1.00 | 20 | 40.60 | 2.03 | 9.5800 |
| 3 | 1.00 | 20 | 39.80 | 1.99 | 9.9690 |
| 4 | 1.00 | 20 | 40.40 | 2.02 | 9.6751 |
| 5 | 1.00 | 20 | 40.00 | 2.00 | 9.8696 |
Mean period=2.01 s. Sample standard deviation=0.015811 s. Repeatability standard uncertainty of the mean=0.007071 s under independent-repeat assumptions. Gravity calculated from the mean period=9.7716 m/s². Mean of separately calculated gravity values is not exactly the same because the formula is nonlinear. Length and instrument effects are not included in the repeatability figure.
Final submission checklist
- Correct manual and approved safety procedure, aim and apparatus/software details.
- Raw readings or source code with actual execution evidence.
- Units, input limits, normal/boundary/rejection cases and justified precision.
- Calculations or graphs checked against the raw record.
- Limitations, uncertainty and failed tests honestly reported.
- Real references and own contribution identified; no passwords or private data.
Lab resources
- C Programming Lab File
- Lab Files
- Online Compiler: choose C and run each file separately.
- Semester 2 Labs
Further study and related notes
Use your assigned lab manual for the experiment list and procedure. Read the full topic explanations in the semester notes:
Comments
Post a Comment