First Lab Report

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

National University of Science and

Technology

School of Mechanical and Manufacturing


Engineering

Lab Report # 01

CS-114 Fundamentals of Programming

Course Instructor: Dr. Shahbaz Khan

Introduction:

Name: Zoraiz Abbas

CMS ID: 454752

Date: 27-06-2024
Task 2:
Make changes to your first program as shown in code listing 2. Compile, build, and run the
modified program.

Output:

Task 3:

Add three more C++ statements to your program. The first statement should introduce you by
printing something like I am Shahbaz Khan. on the console screen. Replace Shahbaz Khan
with your name. The second statementshould say something about your #include using
namespace std; int main() { cout << "Hello, Computer Programming Class of 2024!" <<
endl; cout << "Welcome to Comput er Programming!" << endl; cout << "I hope you will
enjoy learning it." << endl; return 0; } 4 background in programming by printing a statement
like This is the first time I heard the name C++. You can be innovative here and choose words
of your choice. The third statement should say something about your excitement or otherwise
about this course by printing a statement as I look forward to learning programming.

Output:
Task 4:
Remove ≪ endl from all the statements. Save your modified source code and then compile,

the effect of ≪ endl on the way the text is printed on the console screen?
build, and run it. How doesthe output differ from the previous output? What do you think is

Output:

Explanation:
 The ‘endl’ is the manipulator in C++ which is used to insert a newline character in
output.In previous program we use ‘endl’ and the every string is written on separate
line but in this we donot use ‘endl’ and strings are written on same line .As we
remove ‘endl’ from the code the sentences are written on the same line.

Task 5:
Print your date of birth on the console screen using something similar to
the following two statements. What is the difference between the output
that you see on the console screen as a result of these two statements?
cout<<"01122001"<<<01122001<<endl;

Output:

Explanation:

First Statement: cout <<"01122001"<< endl;

 This statement prints the date of birth as a string . The output will be exactly
01122001.

Second Statement: cout << 01122001 << endl;


 This statement attempts to print the date of birth as an integer. But the number
01122001 is interpreted as an octal number because it starts with a 0. The output will
be the decimal equivalent of the octal number .

Task 6 :
Add the following C++ statement to your code exactly the way it appears
below and then try to compile, build, and run your code. What happens
when you try that? Can you try to explain why? cout<<<endl

Output:

Explanation:

 In C++ anything that needs to be printed as text must be enclosed in double quotation
marks so that it can be recognized as a string. Without the quotation marks, the
compiler will look for a variable or a constant named Good and bye, which are not
defined and hence causing an error.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy