0% found this document useful (0 votes)
25 views6 pages

Importance of CP Lab in Programming

This document provides instructions for a computer programming lab assignment. It includes 4 tasks to complete involving explaining computer architecture, drawing flowcharts, and writing 2 simple C++ programs. Students are instructed to complete the tasks alone without help and submit handwritten solutions for the first part. The document demonstrates how to write, compile, debug and test C++ programs using the Turbo C IDE.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Importance of CP Lab in Programming

This document provides instructions for a computer programming lab assignment. It includes 4 tasks to complete involving explaining computer architecture, drawing flowcharts, and writing 2 simple C++ programs. Students are instructed to complete the tasks alone without help and submit handwritten solutions for the first part. The document demonstrates how to write, compile, debug and test C++ programs using the Turbo C IDE.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Programming

Fall 2011

Lab-01,02
(Due Monday, October 31, 2011)

Objective
The objective of this lab is to Provide understanding about fundamental concepts. Provide understanding of basic computer architecture. Provide practice for flow charts. Get familiar with Turbo C IDE. To explore its debugging capabilities. Understanding its customization (& relevant settings).

Important
This lab is to be done alone. Absolutely no cooperation is allowed. NOT Consulting your lecture notes is not required though highly recommended.

Happy Coding!

Institute of Management Sciences (formerly Pak-AIMS)

Computer Programming

Fall 2011

Part 1
Task 1
Why do we prefer software based solutions over hardware based solutions? Write your answer in points.

Task 2
Draw the diagram of basic computer organization and explain each component in a single line or two.

Task 3
Draw a flow chart of the following problems

Problem A
Convert a decimal number to binary. For example, if user inputs 132, you should display 1000 0100.

Problem B
Accept a number from user and prints its table. For example, if user enters 10, you should display 10 x 1 = 10 10 x 2 = 20 10 x 3 = 30 10 x 4 = 40 10 x 5 = 50 10 x 6 = 60 10 x 7 = 70 10 x 8 = 80 10 x 9 = 90 10 x 10 = 100

Problem C
Draw a flowchart of the logical steps needed to produce a printed listing of all students over the age of 20 in a class. The input record contains the age of students. Assume a sentinel value of 99 for the age field of the trailer record.

Problem D
A set of examination papers which have been graded with scores from 0 to 100 is to be searched to find how many of them are above 90. The total has to be printed. Assume a suitable sentinel value for the trailer record.

Institute of Management Sciences (formerly Pak-AIMS)

Computer Programming

Fall 2011

Part 2
First Program
Download Turbo C IDE from the wiki (Download Link). Extract it and go to TurboC\BIN directory and launch [Link]. This file ([Link]) contains the IDE in which we will be writing our C++ programs. Go to File menu and click New (Shortcut: Alt + F, N). A new file will be opened where you can write code. Type in the following program in that newly opened file

#include <iostream.h> int main() { cout << Hello World!; return 0; }

Make sure you save your typed program periodically by clicking File menu and clicking Save (Shortcut: F2). Name the file as [Link] o When saving for the first time, Turbo C IDE will ask you a location where it will save the file for you. By default it saves the file to the current directory (usually the BIN directory that contains [Link] file). Make sure you remember the path. Go to Compile menu and click Compile (Shortcut: Alt + F9). It will successfully compile the code. If it reports any errors, double check the program, specially the inverted commas around Hello World! They are double inverted commas (located near Enter key) and not two single commas. After removing the errors (if any) compile again by pressing (Alt + F9 or by Compile menu). Once you have compiled the code successfully, you can now link it by going to Compile menu and clicking Link menu item. If you typed everything correctly, you will get a success here as well. Now, all the steps have been completed that we discussed from Algorithm to Executable lecture and Turbo C has made an executable file for us. We can now execute the program. Turbo C will name the executable after our source code file (the one that we gave while saving the file). In this case, it will generate the executable under [Link]. Compilation + Linking + Execution can be done in a single step by going to Run menu and selecting Run menu item (shortcut: Ctrl + F9). Go to Window menu and select User Screen option (shortcut: Alt + F5) to view the output.

Institute of Management Sciences (formerly Pak-AIMS)

Computer Programming

Fall 2011

Second Program
Go to TurboC\BIN directory and launch [Link]. This file ([Link]) contains the IDE in which we will be writing our C++ programs. Go to File menu and click New (Shortcut: Alt + F, N). A new file will be opened where you can write code. Type in the following program in that newly opened file

#include <iostream.h> int main() { int num1 = 10; int num2 = 20; int sum = num1 + num2; cout << sum; return 0; }

Make sure you save your typed program periodically by clicking File menu and clicking Save (Shortcut: F2). Name the file as [Link] o When saving for the first time, Turbo C IDE will ask you a location where it will save the file for you. By default it saves the file to the current directory (usually the BIN directory that contains [Link] file). Make sure you remember the path. Go to cout << sum; line and press (Ctrl + F8). It will turn the background color of that line to red. We just inserted a breakpoint. Now whenever this line will be going to execute, execution will be halted and you will be brought back to the IDE window so that you can inspect the values in the variables and make sure everything is according to the expectations. o Breakpoints provide great flexibility to track bugs. Go to Run menu and selecting Run menu item (shortcut: Ctrl + F9). You will see that before executing the line (where we inserted a break point), youre brought back to the IDE. (Note the changed color of the line background. It shows which line is currently being executed). Move your cursor to num1 variable and press Alt+F4 (shortcut for inspect). A window will open telling you the data type of the variable and its current value (which will be 10). Press escape to close the window. Now move your cursor to num2 variable and press Alt+F4 (shortcut for inspect). A window will open telling you the data type of the variable and its current value (which will be 20). Press escape to close the window. Finally move your cursor to sum variable and press Alt+F4 (shortcut for inspect). A window will open telling you the data type of the variable and its current value (which will be a garbage value). This is because sum is not assigned a value yet.

Institute of Management Sciences (formerly Pak-AIMS)

Computer Programming

Fall 2011

Press F8 (shortcut for step over) and the current line will be executed in a single step. Now move your cursor again to sum and press Alt+F4. Now it will show you the value 30 instead of the garbage value. This is because the line has been executed so now sum has the value which was assigned to it. Press Ctrl+F9 to execute the remaining program in a single go. (You can stop debugging anytime by pressing Ctrl+F2. You can also use watch windows in order to watch multiple variables simultaneously. Re-run the program by pressing Ctrl+F9 and you will be again brought back to the IDE before the execution of int sum = num1 + num2; Go to Window menu and click Watch menu item. Make sure your windows are cascaded. (Go to Window menu and click Cascade Windows) so that we can see multiple windows at a time. In the watch window you can press Enter key and write variables num1, num2 and sum. Now execute the program in the same way as you did before (by pressing F8 to execute one line at a time). You will see that the value in the sum variable changes the moment int sum = num1 + num2; is executed. Keep exploring your IDE. It will greatly help you in writing good quality programs and will save lots of precious time as well.

Institute of Management Sciences (formerly Pak-AIMS)

Computer Programming

Fall 2011

Submission Instructions
1. For this particular lab, you are required to submit handwritten (no printouts are not allowed) solution of the problems in Part 1. 2. Clearly mention your subject and roll number.

End

Institute of Management Sciences (formerly Pak-AIMS)

Common questions

Powered by AI

The challenges of using an outdated IDE like Turbo C include the lack of support for current programming standards and limitations in features compared to modern tools, potentially leading to a steeper learning curve and less effective teaching of contemporary practices. However, benefits include teaching fundamental programming concepts with minimal distraction from advanced features, fostering an environment focused on code understanding and logic development. It also instills respect for legacy systems and enhances problem-solving skills in constrained environments .

Experience with setting breakpoints and inspecting variable states teaches novice programmers effective debugging by providing a clear strategy for isolating and resolving issues. This practice trains them to track the flow of execution and logic in a controlled manner, allowing for detailed examination of program state, which is crucial for understanding the behavior of code under different conditions. It also instills a systematic approach to troubleshooting, enhancing their ability to preemptively identify and manage bugs .

To compile and execute a C++ program in Turbo C IDE, open the IDE and create a new file to write your code. Save the file, ensuring it has the .cpp extension. Compile the code using the Compile menu or the Alt + F9 shortcut. If compilation is error-free, proceed to link the program, which generates an executable. Finally, execute the program via the Run menu or the Ctrl + F9 shortcut, and view the output in the User Screen window .

Setting a breakpoint in debugging is crucial as it pauses program execution at a specific line, allowing the developer to inspect variable states and program flow at that exact moment. This halting offers insight into whether the program proceeds as expected and helps identify anomalies in logic or data. Once the issue is identified, it can be corrected or further narrowed down, enhancing the effectiveness of debugging .

Software-based solutions are favored over hardware-based solutions because they are generally more flexible, easier to update, and cost-efficient in comparison to hardware. Software can be modified and improved without changing physical components, allowing for more rapid development and deployment of new features. Additionally, hardware modifications often require physical changes, are more expensive, and result in greater resource expenditure .

Coding in IDEs like Turbo C encourages novice programmers to develop debugging skills by providing structured tools like breakpoints, step execution, and variable inspections, which facilitate hands-on learning. As students frequently encounter and resolve errors during program execution, they gain experience in problem diagnosis and solution implementation, which sharpens their ability to identify and correct bugs in other environments and promotes self-sufficiency in overcoming programming challenges .

The main components of basic computer organization include the Central Processing Unit (CPU), Memory Unit, Input Unit, Output Unit, and Storage Unit. The CPU, often referred to as the brain of the computer, performs arithmetic and logical operations. The Memory Unit stores data and instructions needed for processing. The Input Unit allows data to enter the system. The Output Unit communicates results and data to the outside world. Lastly, the Storage Unit retains data for long-term access .

Flowcharts in program design improve the development process by providing a visual representation of the workflow, which aids understanding and clarity. They facilitate communication among developers, educators, and learners by illustrating how data flows and decisions are made within the program. In educational settings, flowcharts help students grasp complex logical sequences and problem-solving strategies, making abstract concepts tangible and easier to understand, thereby improving learning outcomes .

Turbo C IDE provides debugging capabilities such as setting breakpoints, which halt program execution at a specified line to inspect variables and program flow. This helps identify logical errors and ensure variables contain expected values at runtime. The IDE also offers step execution, allowing line-by-line code traversal, which aids in isolating and correcting errors incrementally. Watch windows further enhance the process by enabling simultaneous monitoring of multiple variable values, supporting quicker error detection and resolution .

A flowchart for identifying students over the age of 20 would start with a Start block, followed by a process block that retrieves student age data one by one. A decision block checks if the age exceeds 20. If true, the decision block leads to a process that adds the student to a result list before looping back to fetch the next student. If false, it directly loops back. The process repeats until a sentinel value (like 99) is met, ending the loop. The result is then printed, and the flowchart concludes with an End block .

You might also like