0% found this document useful (0 votes)
9 views10 pages

MECHANICAL ENGINEERING Assi Lab 4

I JUST want to read and research on this book

Uploaded by

alihamza3661213
Copyright
© © All Rights Reserved
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)
9 views10 pages

MECHANICAL ENGINEERING Assi Lab 4

I JUST want to read and research on this book

Uploaded by

alihamza3661213
Copyright
© © All Rights Reserved
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
You are on page 1/ 10

______________________

MECHANICAL ENGINEERING

CAD
ASSIGNMRNT # 1

SUBMITTED TO

Dr. Fakhre Alam Khan

SUBMITTED BY
NAME: Danyal Hussain
SEMESTER: 1st
ETEA ID: 1452
SECTION: “B”
Class no: 28
OBJECTIVE:
• To learn different ideas and problem solving techniques.
• To familiar with the different terminologies in c++ language.
• To write different condition programs.

TITLE:
• Write down algorithm, make flowchart and coding for all problems)
• Q1.
Write a program that inputs a value and type of conversion. The program should
then display the output
after conversion. The program should include the following conversions:
1 cm = 0.394 inches
1 liter = 0.264 gallons,
1 kilometer = 0.622 miles
1 kilogram = 2.2 pounds
Make sure that the program accepts only valid choices or the type of conversion.
• Q2.
Write a program that inputs marks of three subjects. If the average of marks is more
than 80, it displays two messages "You
are above standard!" and "Admission granted!".
• Q3.
A year is a leap year if it is divisible by four, except that any year divisible by 100 is a
leap year only if it is also divisible by
400. Write a program that inputs a year such as 1996, 1800 and 2010 etc. It will
display ''Leap year" if it is a leap year otherwise displays “Not a leap year”.

Problem Analysis:
In these problems we are required to write a program that can do the conversion of the
different quantities .And can calculate the Average of the different numbers. And also check
the year that it would leap year or it is not. In these programs we have to define the
different variables and write it in such a way that it could receive the value from the user on
the output screen And do the rest of the calculation according the program . in these
programs we have to introduce different formulas . And these formulas will do the
calculation adnd display the desired output.
ALGORITHUM:1:
1. Star
2. Show Men
Display the following options to the user:
1: Convert length (cm to inches)
2: Convert volume (liters to gallons)
3: Convert distance (km to miles)
4: Convert weight (kg to pounds)
5: Quit the program.
3. Get User Choice
Ask the user to select a number between 1 and 5.
4. Check User Input
If the input is invalid (not 1-5), show an error message and go back to Step 2.
5. Perform Actio
If the choice is:
1: Ask for a value in cm, convert it to inches, and display the result.
2: Ask for a value in liters, convert it to gallons, and display the result.
3: Ask for a value in km, convert it to miles, and display the result.
4: Ask for a value in kg, convert it to pounds, and display the result.
5: Print "Goodbye!" and stop the program.
6. Repeat or End
After a conversion (choices 1-4), return to Step 2.
If the user chooses 5, end the program.
7. End

ALGORITHUM:2:
1. Start the program.
2. Input the marks of three subjects:
Ask the user to enter marks for Subject 1, Subject 2, and Subject 3.
3. Calculate the average:
Add the three marks and divide the sum by 3
4. Display the average
Print the calculated average marks.
5. Check the condition:
If the average is greater than 80:
Print "You are above standard!"
Print "Admission granted!"
Otherwise
Print "Better luck next time!"
6. End the program.
ALGORITHUM:3;
1. Start.
2. Input the year (ask the user to enter a year).
3. Check the conditions:
If the year is divisible by 4 AND not divisible by 100, OR if the year is divisible by 400:
Output: "Leap year".
Otherwise:
Output: "Not a leap year".
4. End.
START
FLOWCHART:1:

Display Menu

Get user choice

FALSE TRUE
Is choice
valid

ERROR
CASE 1:Length
CASE 2:Volume
CASE 3:Distance
CASE 4:Weight

DISPLAY RESULT
CRASH PROGRAM

END
FLOWCHART:2: START

Sub1 , Sub2 ,Sub3

Average=(sub1+sub2+su
b3)/3

AVERAGE

FALSE TRUE
Is average >
80

Better luck for time Your above the standard


Admission Granted

jh

END
START
FLOWCHART:3:

YEAR

FALSE TRUES
(Year %4==0 &&
Year %100
!=0)||(Year
%400==0)

Not a leap year Leap year

END
CODE#1:
#include <iostream>
using namespace std;

void convert_length() {
float cm;
cout << "Enter value in cm: ";
cin >> cm;
float inches = cm * 0.394;
cout << cm << " cm is equal to " << inches << " inches" << endl;
}
void convert_volume() {
float liter;
cout << "Enter value in liters: ";
cin >> liter;
float gallons = liter * 0.264;
cout << liter << " liters is equal to " << gallons << " gallons" << endl;
}
void convert_distance() {
float km;
cout << "Enter value in km: ";
cin >> km;
float miles = km * 0.622;
cout << km << " km is equal to " << miles << " miles" << endl;
}
void convert_weight() {
float kg;
cout << "Enter value in kg: ";
cin >> kg;
float pounds = kg * 2.2;
cout << kg << " kg is equal to " << pounds << " pounds" << endl;
}
int main() {
int choice;
while (true) {
cout << "\nConversion Options:" << endl;
cout << "1. Length (cm to inches)" << endl;
cout << "2. Volume (liters to gallons)" << endl;
cout << "3. Distance (km to miles)" << endl;
cout << "4. Weight (kg to pounds)" << endl;
cout << "5. Quit" << endl;
cout << "Enter your choice (1-5): ";
cin >> choice;

switch (choice) {
case 1:
convert_length();
break;
case 2:
convert_volume();
break;
case 3:
convert_distance();
break;
case 4:
convert_weight();
break;
case 5:
cout << "Goodbye!" << endl;
return 0;

default:
cout << "Invalid choice. Please choose a valid option." << endl;
}
}
return 0;
}

CODE#2:
#include <iostream>
using namespace std;

int main() {
int sub1, sub2, sub3;
float average;
cout << "Enter marks of Subject 1: ";
cin >> sub1;
cout << "Enter marks of Subject 2: ";
cin >> sub2;
cout << "Enter marks of Subject 3: ";
cin >> sub3;
average = (sub1 + sub2 + sub3) / 3.0;
cout << "Average marks: " << average << endl;
if (average > 80) {
cout << "You are above standard!" << endl;
cout << "Admission granted!" << endl;
}
else {
cout << "Better luck next time!" << endl;
}
return 0;
}

CODE#3:

#include <iostream>
using namespace std;

int main() {
int year;
cout << "Enter a year: ";
cin >> year;
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
cout << "Leap year" << endl;
}
else {
cout << "Not a leap year" << endl;
}

return 0;
}
OUTPUT#1:

OUTPUT#2:
OUTPUT#3:
IS

Discussion and Conclusion:


These code are written in c++. In these programs we use different terminologies and ideas
.These programs involve in conversion of quantities , calculation of average of the numbers
and checking the years whether it is leap or not..So the programs are run successfully and
display its desired output

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