0% found this document useful (0 votes)
3 views5 pages

Lab 1 Template

The lab report focuses on fundamental concepts of C++ programming, including the structure of the main() function, preprocessor directives, and flowcharts. It includes answers to pre-lab questions and provides several programming exercises that involve calculating speeds, sums, and per-head income. The report demonstrates the implementation of these concepts through various C++ code examples.

Uploaded by

Daniel Mwembia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Lab 1 Template

The lab report focuses on fundamental concepts of C++ programming, including the structure of the main() function, preprocessor directives, and flowcharts. It includes answers to pre-lab questions and provides several programming exercises that involve calculating speeds, sums, and per-head income. The report demonstrates the implementation of these concepts through various C++ code examples.

Uploaded by

Daniel Mwembia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming Fundamentals

CSCI 1081

Lab 1 Report

1. Introduction
[Write a short ( 1- 3 paragraphs) describing what you did in this lab]

In this lab we answered and tested ourselves on the concepts we


covered in chapter 1 on c++. Introducing the main ideas the make
computers and how they are programmed. We answered questions
based on the flowcharts and how they operate. We also had questions
based on some fundamental programs that implement c++ for us as
beginners like int main()

2. Answer to Pre-lab questions


Answer the following questions before you proceed with the rest of the
lab.

a. What is the common name of the statements that start with the
hash (#) symbol at the top of the C++ program? What is the
purpose of the #include statement?

Answer

It is a preprocessor directive that puts the header files where the


#include directive appears

b. Explain the purpose and structure of the main() function in a C+


+ program.

Answer
It is where the program begins to execute and it is the starting
point of the code we will write for a particular program.

c. Can we write a C++ program outside of the main() function? If


yes, which programs can be written outside of the body of the
main() function? If no, why not?

Answer

No we can’t write program outside the main() function.


Except for global variables or return 0;

d. What is the purpose of the iostream statement? Provide two


example usages of the statement.

Answer

It allows us to get information from a program and


writing data into screen for c++

e. What is a flowchart, and what is its purpose? Who should use a


programming flowchart? What are the standard shapes used in a
program flowchart?

Answer

A visual process that simplifies and shows the steps and


decisions it takes to solve a complex task or algorithm.

3. Creating Your First Flowchart in Draw.io.

Design and implement the following program using a flowchart. Your


algorithm must be correct, and a program code implemented solely by
following the algorithm in this flow chart must run without error.
a. Write a program that takes the number of miles the user commutes
daily and how many minutes it takes him/her. Calculate the speed of
the journey in miles per minute. Display the speed. Paste your solution
below this line.
#include <iostream>

using namespace std;

int main()

{int n_milescommutes;

n_milescommutes =20;

Time_taken= 5;

mpm= n_milescommutes / Time_taken;

cout << “ miles per hour” << mpm << endl;

return 0; }

b. Write a program that takes the number of miles the user commutes
daily and how many minutes it takes him/her. Calculate the speed of
the journey in miles per hour, kilometers per hour, and meters per
second. Display the speed you calculated in the three units. Paste your
solution below this line. You must paste a single solution. Paste your
solution below this line.

#include <iostream>

using namespace std;

int main() {

distance_miles, time_minutes;

time_hours= time_minutes/ 60;

speed_mph= distance_miles/time_hours;

distance_km= distance_miles * 1.609;

speed_kph= distance_km/ time_hours;

distance_metre= distance_km * 1000;

time_seconds = time_hours * 3600;

speed_mps= distance_m/ time_seconds;

cout << “ Speed in mph” << speed_mph << “mph” <<endl;


cout << “speed in kph” << speed_kph << “km/h” <<endl;

cout << “speed in mps” << speed_mps << “m/s” <<endl;

return 0; }

c. Write a program that takes two numbers as inputs and outputs their
sum. Paste your solution below this line.

#include <iostream>

using namespace std;

int main() {

int number 1, number 2, sum;

sum= number 1 + number 2;

cout << “ sum=” << sum <<endl;

return 0; }

d. Suppose you want to write a C++ program that calculates and displays
the per-head income amount for a family. Ask the user how many
people are in the household and their total gross income. Find and
display the per-head income for the family. Paste your solution below
this line.

#include <iostream>

using namespace std;

int main() { int numpeople , total_income;

numpeople= 7, total_income = 65000;


cout << “number of people is” << numpeople <<endl;

cout << “ total income earned is” << total_income << “dollars” <<
endl;

per_Headincome= total_income / numpeople;

cout << “ the per head income is” << per_Headincome <<endl;

return 0; }

e. Write a C++ algorithm that asks the user for the radius of a circle,
calculates its area and circumference, and displays the results along
with some text. Paste your solution below this line.

#include <iostream>

using namespace std;

int main() {

double radius, area, circumference;

const double PI = 3.14 ;

cout << “ The radius is” << endl;

cin<< radius;

area = PI * radius * radius;

circumference= 2 * PI * radius;

cout << “ The area of the circle” <<area << endl;

cout<<”Circumference is “ << circumference <<endl;

return 0; }

You might also like