SlideShare a Scribd company logo
Enid M. Cruz-Colón
COMP 3010-030
HW 1: Compiler Toolchain
Problem 1
(a) The name of the executable program created by the compiler if the programmer does not
specify one is a.out.
(b) To compile a program and rename the executable file with a name other than the default
name, a.out, the command is:
g++ -o <new_name>.out <sourcecode_name>.cpp
Problem 2
The -Wall command line enables error warnings from the compiler when compiling your source
code.
The -c command line compiles a source code into an object file, not yet executable.
With the command g++ -o MyFirstProgram MyFirstSource.o we accomplish to change the
object code into machine code and store it in an executable program.
Problem 3
To change the program for it to greet the user with Hello, I inserted the following line, right
after the int number_of_pods, peas_per_pod, total_peas; line:
cout << “Hellon”;
To change the program for it to output Goodbye at the end, I inserted the following line, right
before the return 0; line:
cout << “Goodbyen”;
Problem 4
When replacing the “*” operator in the computation with a “/” and entering 0 for the number of
peas per pod, the compiler gives the following error: Floating point exception (core dumped). It
gives an error because the program is dividing the number of pods by peas per pod and you cannot
divide by 0.
Problem 5
When replacing the “/” operator in the computation with the “+” operator, the compiler does not
issue any errors, but the program gives a wrong answer.
Problem 6
(a) Error: Extra space between < and iostream.
Message: MyFirstSource.cpp:3:21: fatal error: iostream: No such file or directory
#include < iostream>
(b) Error: Omit < symbol in the #include directive.
Message: MyFirstSource.cpp:3:12: error: #include expects "FILENAME" or
<FILENAME>
#include iostream>
^
MyFirstSource.cpp: In function ‘int main()’:
MyFirstSource.cpp:8:3: error: ‘cout’ was not declared in this scope
cout << "Hellon";
^
MyFirstSource.cpp:11:3: error: ‘cin’ was not declared in this scope
cin >> number_of_pods;
^
(c) Error: Omit int from int main().
Message: MyFirstSource.cpp:5:10: warning: ISO C++ forbids declaration of ‘main’
with no type [-Wreturn-type]
main()
^
(d) Error: Misspell the word main.
Message: /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crt1.o: In function
`_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
(e) Error: Omit (.
Message: MyFirstSource.cpp:5:9: error: expected initializer before ‘)’ token
int main)
^
Error: Omit both ( and ).
Message: MyFirstSource.cpp:6:1: warning: extended initializer lists only available
with -std=c++11 or -std=gnu++11
{
^
MyFirstSource.cpp:7:3: error: expected primary-expression before ‘int’
int number_of_pods, peas_per_pod, total_peas;
^
MyFirstSource.cpp:7:3: error: expected ‘}’ before ‘int’
MyFirstSource.cpp:7:3: error: expected ‘,’ or ‘;’ before ‘int’
MyFirstSource.cpp:8:3: error: ‘cout’ does not name a type
cout << "Hellon";
^
MyFirstSource.cpp:9:3: error: ‘cout’ does not name a type
cout << "Press return after entering a number.n";
^
MyFirstSource.cpp:10:3: error: ‘cout’ does not name a type
cout << "Enter the number of pods:n";
^
MyFirstSource.cpp:11:3: error: ‘cin’ does not name a type
cin >> number_of_pods;
^
MyFirstSource.cpp:12:3: error: ‘cout’ does not name a type
cout << "Enter the number of peas in a pod:n";
^
MyFirstSource.cpp:13:3: error: ‘cin’ does not name a type
cin >> peas_per_pod;
^
MyFirstSource.cpp:14:3: error: ‘total_peas’ does not name a type
total_peas = number_of_pods + peas_per_pod;
^
MyFirstSource.cpp:15:3: error: ‘cout’ does not name a type
cout << "If you have ";
^
MyFirstSource.cpp:16:3: error: ‘cout’ does not name a type
cout << number_of_pods;
^
MyFirstSource.cpp:17:3: error: ‘cout’ does not name a type
cout << " pea podsn";
^
MyFirstSource.cpp:18:3: error: ‘cout’ does not name a type
cout << "and ";
^
MyFirstSource.cpp:19:3: error: ‘cout’ does not name a type
cout << peas_per_pod;
^
MyFirstSource.cpp:20:3: error: ‘cout’ does not name a type
cout << " peas in each pod, thenn";
^
MyFirstSource.cpp:21:3: error: ‘cout’ does not name a type
cout << "you have ";
^
MyFirstSource.cpp:22:3: error: ‘cout’ does not name a type
cout << total_peas;
^
MyFirstSource.cpp:23:3: error: ‘cout’ does not name a type
cout << " peas in all the pods.n";
^
MyFirstSource.cpp:24:3: error: ‘cout’ does not name a type
cout << "Goodbyen";
^
MyFirstSource.cpp:25:3: error: expected unqualified-id before ‘return’
return 0;
^
MyFirstSource.cpp:26:1: error: expected declaration before ‘}’ token
}
^
(f) Error: Misspell cin.
Message: MyFirstSource.cpp: In function ‘int main()’:
MyFirstSource.cpp:11:3: error: ‘cn’ was not declared in this scope
cn >> number_of_pods;
^

More Related Content

What's hot (20)

PDF
PyCon lightning talk on my Toro module for Tornado
emptysquare
 
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
KEY
Debugging Your PHP Cake Application
Jose Diaz-Gonzalez
 
PPTX
C to perl binding
Shmuel Fomberg
 
PDF
Python meetup: coroutines, event loops, and non-blocking I/O
Buzzcapture
 
PDF
C++ Programming - 2nd Study
Chris Ohk
 
DOCX
Cs project
Dhairya Pant
 
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
PDF
Rcpp11
Romain Francois
 
PDF
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
jspha
 
PPTX
Intro to C++
Ahmed Farag
 
PPTX
C program to write c program without using main function
Rumman Ansari
 
TXT
Unix
Shohan Ahmed
 
PDF
1 c introduction
suresh rathod
 
DOCX
C++ file
Mukund Trivedi
 
ODP
Incredible Machine with Pipelines and Generators
dantleech
 
PPTX
Stop Programming in JavaScript By Luck
sergioafp
 
PDF
C++ Programming - 3rd Study
Chris Ohk
 
PDF
clap: Command line argument parser for Pharo
ESUG
 
DOCX
Basic Programs of C++
Bharat Kalia
 
PyCon lightning talk on my Toro module for Tornado
emptysquare
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
Debugging Your PHP Cake Application
Jose Diaz-Gonzalez
 
C to perl binding
Shmuel Fomberg
 
Python meetup: coroutines, event loops, and non-blocking I/O
Buzzcapture
 
C++ Programming - 2nd Study
Chris Ohk
 
Cs project
Dhairya Pant
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
jspha
 
Intro to C++
Ahmed Farag
 
C program to write c program without using main function
Rumman Ansari
 
1 c introduction
suresh rathod
 
C++ file
Mukund Trivedi
 
Incredible Machine with Pipelines and Generators
dantleech
 
Stop Programming in JavaScript By Luck
sergioafp
 
C++ Programming - 3rd Study
Chris Ohk
 
clap: Command line argument parser for Pharo
ESUG
 
Basic Programs of C++
Bharat Kalia
 

Similar to Lab 1: Compiler Toolchain (20)

PDF
Classes and Errors.pdf
rajaratna4
 
PDF
Learning Rust with Advent of Code 2023 - Princeton
Henry Schreiner
 
PPTX
Namespaces
zindadili
 
PPTX
Hypercritical C++ Code Review
Andrey Karpov
 
DOCX
C++ program: All tasks .cpp
Khalid Waleed
 
PPTX
Common Programming Errors
Nicole Ynne Estabillo
 
PPT
Lecture16
elearning_portal
 
PDF
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
PVS-Studio
 
DOCX
C++ program: Numbers .cpp
Khalid Waleed
 
PPT
C++ basics
husnara mohammad
 
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
PPT
C tutorial
Diwakar_singh1989
 
PDF
c interview progs.pdf
pooja82042
 
PDF
Class xi sample paper (Computer Science)
MountAbuRohini
 
PPTX
Hello world! Intro to C++
DSCIGDTUW
 
PDF
DeVry GSP 115 All Assignments latest
Atifkhilji
 
PDF
C++ L05-Functions
Mohammad Shaker
 
PDF
Rust LDN 24 7 19 Oxidising the Command Line
Matt Provost
 
PPTX
Cpp Homework Help
C++ Homework Help
 
Classes and Errors.pdf
rajaratna4
 
Learning Rust with Advent of Code 2023 - Princeton
Henry Schreiner
 
Namespaces
zindadili
 
Hypercritical C++ Code Review
Andrey Karpov
 
C++ program: All tasks .cpp
Khalid Waleed
 
Common Programming Errors
Nicole Ynne Estabillo
 
Lecture16
elearning_portal
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
PVS-Studio
 
C++ program: Numbers .cpp
Khalid Waleed
 
C++ basics
husnara mohammad
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
C tutorial
Diwakar_singh1989
 
c interview progs.pdf
pooja82042
 
Class xi sample paper (Computer Science)
MountAbuRohini
 
Hello world! Intro to C++
DSCIGDTUW
 
DeVry GSP 115 All Assignments latest
Atifkhilji
 
C++ L05-Functions
Mohammad Shaker
 
Rust LDN 24 7 19 Oxidising the Command Line
Matt Provost
 
Cpp Homework Help
C++ Homework Help
 
Ad

More from enidcruz (8)

PDF
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz
 
PDF
Lab6: I/O and Arrays
enidcruz
 
PDF
Lab5: Functions 2
enidcruz
 
PDF
Lab4: Functions
enidcruz
 
PDF
Lab3: More Flow of Control
enidcruz
 
PDF
My First Source Code
enidcruz
 
PDF
Comp 3010 Syllabus
enidcruz
 
PDF
Foto-ensayo VIEQUES
enidcruz
 
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz
 
Lab6: I/O and Arrays
enidcruz
 
Lab5: Functions 2
enidcruz
 
Lab4: Functions
enidcruz
 
Lab3: More Flow of Control
enidcruz
 
My First Source Code
enidcruz
 
Comp 3010 Syllabus
enidcruz
 
Foto-ensayo VIEQUES
enidcruz
 
Ad

Recently uploaded (20)

PDF
GUGC Research Overview (December 2024)
Ghent University Global Campus
 
PDF
High-speedBouldersandtheDebrisFieldinDARTEjecta
Sérgio Sacani
 
PPTX
Cerebellum_ Parts_Structure_Function.pptx
muralinath2
 
DOCX
Analytical methods in CleaningValidation.docx
Markus Janssen
 
PPT
Experimental Design by Cary Willard v3.ppt
MohammadRezaNirooman1
 
PPTX
770043401-q1-Ppt-pe-and-Health-7-week-1-lesson-1.pptx
AizaRazonado
 
PPTX
LESSON 2 PSYCHOSOCIAL DEVELOPMENT.pptx L
JeanCarolColico1
 
PDF
Service innovation with AI: Transformation of value proposition and market se...
Selcen Ozturkcan
 
PDF
Plant growth promoting bacterial non symbiotic
psuvethapalani
 
PDF
The emergence of galactic thin and thick discs across cosmic history
Sérgio Sacani
 
PPTX
Ghent University Global Campus: Overview
Ghent University Global Campus
 
PDF
Global Congress on Forensic Science and Research
infoforensicscience2
 
PDF
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
DOCX
Paper - Suprasegmental Features (Makalah Presentasi)
Sahmiral Amri Rajagukguk
 
PDF
Integrating Lifestyle Data into Personalized Health Solutions (www.kiu.ac.ug)
publication11
 
PPTX
CNS.pptx Central nervous system meninges ventricles of brain it's structure a...
Ashwini I Chuncha
 
PDF
Pharmakon of algorithmic alchemy: Marketing in the age of AI
Selcen Ozturkcan
 
PPTX
Neuroinflammation and microglial subtypes
KanakChaudhary10
 
PDF
soil and environmental microbiology.pdf
Divyaprabha67
 
PDF
A High-Caliber View of the Bullet Cluster through JWST Strong and Weak Lensin...
Sérgio Sacani
 
GUGC Research Overview (December 2024)
Ghent University Global Campus
 
High-speedBouldersandtheDebrisFieldinDARTEjecta
Sérgio Sacani
 
Cerebellum_ Parts_Structure_Function.pptx
muralinath2
 
Analytical methods in CleaningValidation.docx
Markus Janssen
 
Experimental Design by Cary Willard v3.ppt
MohammadRezaNirooman1
 
770043401-q1-Ppt-pe-and-Health-7-week-1-lesson-1.pptx
AizaRazonado
 
LESSON 2 PSYCHOSOCIAL DEVELOPMENT.pptx L
JeanCarolColico1
 
Service innovation with AI: Transformation of value proposition and market se...
Selcen Ozturkcan
 
Plant growth promoting bacterial non symbiotic
psuvethapalani
 
The emergence of galactic thin and thick discs across cosmic history
Sérgio Sacani
 
Ghent University Global Campus: Overview
Ghent University Global Campus
 
Global Congress on Forensic Science and Research
infoforensicscience2
 
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
Paper - Suprasegmental Features (Makalah Presentasi)
Sahmiral Amri Rajagukguk
 
Integrating Lifestyle Data into Personalized Health Solutions (www.kiu.ac.ug)
publication11
 
CNS.pptx Central nervous system meninges ventricles of brain it's structure a...
Ashwini I Chuncha
 
Pharmakon of algorithmic alchemy: Marketing in the age of AI
Selcen Ozturkcan
 
Neuroinflammation and microglial subtypes
KanakChaudhary10
 
soil and environmental microbiology.pdf
Divyaprabha67
 
A High-Caliber View of the Bullet Cluster through JWST Strong and Weak Lensin...
Sérgio Sacani
 

Lab 1: Compiler Toolchain

  • 1. Enid M. Cruz-Colón COMP 3010-030 HW 1: Compiler Toolchain Problem 1 (a) The name of the executable program created by the compiler if the programmer does not specify one is a.out. (b) To compile a program and rename the executable file with a name other than the default name, a.out, the command is: g++ -o <new_name>.out <sourcecode_name>.cpp Problem 2 The -Wall command line enables error warnings from the compiler when compiling your source code. The -c command line compiles a source code into an object file, not yet executable. With the command g++ -o MyFirstProgram MyFirstSource.o we accomplish to change the object code into machine code and store it in an executable program. Problem 3 To change the program for it to greet the user with Hello, I inserted the following line, right after the int number_of_pods, peas_per_pod, total_peas; line: cout << “Hellon”; To change the program for it to output Goodbye at the end, I inserted the following line, right before the return 0; line: cout << “Goodbyen”; Problem 4 When replacing the “*” operator in the computation with a “/” and entering 0 for the number of peas per pod, the compiler gives the following error: Floating point exception (core dumped). It gives an error because the program is dividing the number of pods by peas per pod and you cannot divide by 0. Problem 5 When replacing the “/” operator in the computation with the “+” operator, the compiler does not issue any errors, but the program gives a wrong answer. Problem 6 (a) Error: Extra space between < and iostream. Message: MyFirstSource.cpp:3:21: fatal error: iostream: No such file or directory #include < iostream> (b) Error: Omit < symbol in the #include directive.
  • 2. Message: MyFirstSource.cpp:3:12: error: #include expects "FILENAME" or <FILENAME> #include iostream> ^ MyFirstSource.cpp: In function ‘int main()’: MyFirstSource.cpp:8:3: error: ‘cout’ was not declared in this scope cout << "Hellon"; ^ MyFirstSource.cpp:11:3: error: ‘cin’ was not declared in this scope cin >> number_of_pods; ^ (c) Error: Omit int from int main(). Message: MyFirstSource.cpp:5:10: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] main() ^ (d) Error: Misspell the word main. Message: /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status (e) Error: Omit (. Message: MyFirstSource.cpp:5:9: error: expected initializer before ‘)’ token int main) ^ Error: Omit both ( and ). Message: MyFirstSource.cpp:6:1: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 { ^ MyFirstSource.cpp:7:3: error: expected primary-expression before ‘int’ int number_of_pods, peas_per_pod, total_peas; ^ MyFirstSource.cpp:7:3: error: expected ‘}’ before ‘int’ MyFirstSource.cpp:7:3: error: expected ‘,’ or ‘;’ before ‘int’ MyFirstSource.cpp:8:3: error: ‘cout’ does not name a type cout << "Hellon"; ^ MyFirstSource.cpp:9:3: error: ‘cout’ does not name a type cout << "Press return after entering a number.n"; ^ MyFirstSource.cpp:10:3: error: ‘cout’ does not name a type cout << "Enter the number of pods:n"; ^
  • 3. MyFirstSource.cpp:11:3: error: ‘cin’ does not name a type cin >> number_of_pods; ^ MyFirstSource.cpp:12:3: error: ‘cout’ does not name a type cout << "Enter the number of peas in a pod:n"; ^ MyFirstSource.cpp:13:3: error: ‘cin’ does not name a type cin >> peas_per_pod; ^ MyFirstSource.cpp:14:3: error: ‘total_peas’ does not name a type total_peas = number_of_pods + peas_per_pod; ^ MyFirstSource.cpp:15:3: error: ‘cout’ does not name a type cout << "If you have "; ^ MyFirstSource.cpp:16:3: error: ‘cout’ does not name a type cout << number_of_pods; ^ MyFirstSource.cpp:17:3: error: ‘cout’ does not name a type cout << " pea podsn"; ^ MyFirstSource.cpp:18:3: error: ‘cout’ does not name a type cout << "and "; ^ MyFirstSource.cpp:19:3: error: ‘cout’ does not name a type cout << peas_per_pod; ^ MyFirstSource.cpp:20:3: error: ‘cout’ does not name a type cout << " peas in each pod, thenn"; ^ MyFirstSource.cpp:21:3: error: ‘cout’ does not name a type cout << "you have "; ^ MyFirstSource.cpp:22:3: error: ‘cout’ does not name a type cout << total_peas; ^ MyFirstSource.cpp:23:3: error: ‘cout’ does not name a type cout << " peas in all the pods.n"; ^ MyFirstSource.cpp:24:3: error: ‘cout’ does not name a type cout << "Goodbyen"; ^ MyFirstSource.cpp:25:3: error: expected unqualified-id before ‘return’ return 0; ^ MyFirstSource.cpp:26:1: error: expected declaration before ‘}’ token } ^
  • 4. (f) Error: Misspell cin. Message: MyFirstSource.cpp: In function ‘int main()’: MyFirstSource.cpp:11:3: error: ‘cn’ was not declared in this scope cn >> number_of_pods; ^