0% found this document useful (0 votes)
29 views7 pages

Andi Zylali Lab 01

The document contains 10 questions from a C++ programming lab assignment. Each question provides sample code for students to complete a programming task, such as outputting text patterns, performing calculations, and prompting users for input. Students are asked to write C++ code that includes headers, declares variables, performs calculations, handles user input/output, and returns values. The tasks involve basic programming concepts like loops, conditional statements, functions, and mathematical operations.

Uploaded by

ferit
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)
29 views7 pages

Andi Zylali Lab 01

The document contains 10 questions from a C++ programming lab assignment. Each question provides sample code for students to complete a programming task, such as outputting text patterns, performing calculations, and prompting users for input. Students are asked to write C++ code that includes headers, declares variables, performs calculations, handles user input/output, and returns values. The tasks involve basic programming concepts like loops, conditional statements, functions, and mathematical operations.

Uploaded by

ferit
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/ 7

“Bedër” University College

2023 – 2024 Academic Year


Department of Economic and Business

EMS121: Introduction to C++ Programming Spring Semester

Lab - 01
Name, Surname: Andi Zylali

Lab 01 - Question 1

Write a program that produces the following output:

******************************
* Programming Assignment 01 *
* EMS121 C++ Programming *
* Author: ???? *
******************************

In your program, substitute ??? with your own name. If necessary, adjust the positions and the number of the stars to
produce a rectangle.

1 /*
2 Lab 01 - Question 1:
3 Write a program that produces the following output:
4 */
5 #include <iostream>
6 using namespace std;
7
8 int main()
9 {
10 cout <<"******************************"<<endl;
11 cout <<"* Programming Assignment 01 *"<<endl;
12 cout <<"* EMS121 C++ Programming *"<<endl;
13 cout <<"* Author: Andi Zylali *"<<endl;
14 cout <<"******************************"<<endl;
15
16 return 0;
17 }

Lab 01 - Question 2

Write a C++ program that produces the following output:

// Online C++ compiler to run C++ program online


1
#include <iostream>
using namespace std;

int main() {
cout <<"CCCCCCCCC ++ ++"<<endl;
cout <<"CC ++ ++"<<endl;
cout <<"CC +++++++++++++++ +++++++++++++++"<<endl;
cout <<"CC +++++++++++++++ +++++++++++++++"<<endl;
cout <<"CC ++ ++"<<endl;
cout <<"CCCCCCCCC ++ ++"<<endl;

return 0;
}

Lab 01 - Question 3

Consider the following program segment:

//include <iostream>
//using namespace statement

int main()

{
//variable declaration
//executable statements
//return statement
}

a) Write a C++ statement that includes the header file iostream.


b) Write a C++ statement that allows you to use cin, cout, and endl without the prefix std:: .
c) Write C++ statement(s) that declare the following variables: num1, num2, num3, as int type and
average as float type.
d) Write C++ statements that store 125 into num1, 28 into num2, and -25 into num3.
e) Write a C++ statement that stores the average of num1, num2, and num3 into average.
f) Write C++ statement(s) that output the values of num1, num2, num3, and average.
g) Compile and run your program.

1 /* Lab 01 - Question 3:*/


2
3 #include <iostream>
4 using namespace std;
5
6 int main()
7 {
8 int num1, num2, num3;
9 float average;
10 num1=125;

2
11 num2=28;
12 num3=-25;
13 average = (num1+num2+num3)/3;
14 cout<<"The numbers are: "<<num1
15 <<", "<<num2<<", "<<num3<<endl;
16 cout<<"The average is: "<<average<<endl;
17
18 return 0;
19 }
20

Lab 01 - Question 4

Repeat Assignment 01 - Question 3 by declaring num1, num2, and num3, and average of type double.
Store 75.35 into num1, -35.56 into num2, and 15.76 into num3.

#include <iostream>

using namespace std;

int main()
{
double num1, num2, num3;
double average;
num1=75.35;
num2=-35.56;
num3=17.76;
average = (num1+num2+num3)/3;
cout<<"The numbers are: "<<num1
<<", "<<num2<<", "<<num3<<endl;
cout<<"The average is: "<<average<<endl;

return 0;

}
Lab 01 - Question 5

Write a C++ program which calculates the perimeter of the circle, if the radius r is known. And π is declared
as constant, π = 3.14.

include <iostream>

using namespace std;

int main()
{
const float π = 3.14; // Declare π as a constant

float radius, perimeter;

cout << "Enter your radius here: ";


cin >> radius;

perimeter = 2 * π * radius; // Calculate the perimeter

cout << "The perimeter of your circle is: " << perimeter << endl;
3
return 0;
}

Lab 01 - Question 6

Write a C++ program which calculates the area of the ellipse, if the radius r1 and r2 are known.

#include <iostream>

using namespace std;

const double π = 3.14; // Value of π

double calculateEllipseArea(double r1, double r2) {


return π * r1 * r2;
}

int main() {
double radius1, radius2;
cout << "Enter your fist radius here: ";
cin >> radius1;
cout << "Enter your second radius here: ";
cin >> radius2;
double area = calculateEllipseArea(radius1, radius2);

cout << "The area of your ellipse is: " << area << endl;

return 0;
}

Lab 01 - Question 7

Write a C++ program that prompts the user to input the elapsed time for an event in seconds. The program
then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9,630
seconds, then the output is 2:40:30.)

#include <iostream>

using namespace std;

int main() {
int seconds, hours, minutes;
std::cout << "Enter your elapsed time in seconds here pleas: ";
std::cin >> seconds;
hours = seconds / 3600; // 1 hour = 3600 seconds
minutes = (seconds % 3600) / 60; // 1 minute = 60 seconds
seconds = seconds % 60; // remaining seconds
std::cout << "Elapsed time: " << hours << ":" << minutes << ":" << seconds << std::endl;

return 0;
}

4
Lab 01 - Question 8

To make a profit, a local store marks up the prices of its items by a certain percentage. Write a C++ program
that reads the original price of the item sold, the percentage of the marked-up price, and the sales tax rate.
The program then outputs the original price of the item, the percentage of the mark-up, the store’s selling
price of the item, the sales tax rate, the sales tax, and the final price of the item. (The final price of the item
is the selling price plus the sales tax.)

#include <iostream>

using namespace std;

int main()
{
double originalPrice, markupPercentage, salesTaxRate;

// Read input from the user


cout << "Pleas enter the original price of your item here: ";
cin >> originalPrice;
cout << "Pleasa enter the markup percentage here: ";
cin >> markupPercentage;
cout << "Pleas enter the sales tax rate here: ";
cin >> salesTaxRate;
// Calculate the selling price
double markupAmount = originalPrice * (markupPercentage / 100);
double sellingPrice = originalPrice + markupAmount;
// Calculate the sales tax
double salesTax = sellingPrice * (salesTaxRate / 100);
// Calculate the final price
double finalPrice = sellingPrice + salesTax;
// Output the results
cout << "Original Price: $" << originalPrice << endl;
cout << "Markup Percentage: " << markupPercentage << "%" << endl;
cout << "Selling Price: $" << sellingPrice << endl;
cout << "Sales Tax Rate: " << salesTaxRate << "%" << endl;
cout << "Sales Tax: $" << salesTax << endl;
cout << "The final Price is : $" << finalPrice << endl;
return 0;
}

5
Lab 01 - Question 9

A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local
grocery store. The cost of producing one liter of milk is $0.38, and the profit of each carton of milk is $0.27.
Write a program that does the following:
a. Prompts the user to enter the total amount of milk produced in the morning.
b. Outputs the number of milk cartons needed to hold milk. (Round your answer to the nearest integer.)
c. Outputs the cost of producing milk.
d. Outputs the profit for producing milk.

#include <iostream>
using namespace std;

int main() {
int total_amount, total_no_cartons, total_cost, profit;

cout << "Pleas enter the total amount of milk you produce in the morning: ";
cin >> total_amount;
total_no_cartons = total_amount / 3.78;
cout << "The number of milk cartons needed to hold your amout of milk is: " << total_no_cartons <<
endl;
total_cost = total_amount * 0.38;

cout << "The cost of producing today's milk is: " << total_cost << endl;
profit = total_no_cartons * 0.27;
cout << "The profit for producing milk is: " << profit << endl;

return 0;
}

Lab 01 - Question 10

A piece of wire is to be bent in the form of a rectangle to put around a picture frame. The length of the
picture frame is 1.5 times the width. Write a C++ program that prompts the user to input the length of the
wire and outputs the length and width of the picture frame.

6
#include <iostream>
using namespace std;

int main()
{
double wireLength, frameLength, frameWidth;

// Prompt the user inputs the length of the wire


cout << "Pleas enter the length of your wire here: ";
cin >> wireLength;
// Calculate the length and width of the picture frame
frameLength = wireLength / 3.5; // Assuming the wire is bent into a rectangle in the form of a frame
frameWidth = frameLength / 1.5;
// Output the
length and
width of the
picture frame
cout << "The
Length of
your picture
frame is : "
<<
frameLength
<< endl;
cout << "The
Width of your picture frame is : " << frameWidth << endl;

return 0;
}

Notes:
Presor si jeni?Njdese sespe eshte dhe vone…
Sapo mbarova ushtrrimet dhe kisha vetem nje problem.Nuk e di pse kodet nuk me dalin ne formatin e duhur
kur I bej paste ne Word por ndoshat vjen si pasoj se nuk po perdor nje c++ compiler online:
https://www.onlinegdb.com/online_c++_compiler
Por mendova qe ti bashkangjis dhe fotot !
Ne pritje te feedbackut tuaj.

You might also like