Professional Documents
Culture Documents
Programming (Lab)
Assignment Week 3
BS-1 AI
IBA Sukkur
Arrow:
/* Exercise 01: Arrow using setw
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(10)<<"*"<<endl;
cout<<setw(11)<<"**"<<endl;
cout<<setw(12)<<"*********"<<endl;
cout<<setw(11)<<"**"<<endl;
cout<<setw(10)<<"*"<<endl;
system("pause");
return 0;
}
Output:
Pyramid:
/* Exercise 01: Pyramid using setw
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(10)<<"^"<<endl;
cout<<setw(9)<<"^"<<setw(2)<<"^"<<endl;
cout<<setw(8)<<"^"<<setw(2)<<"^"<<setw(2)< "^"<<endl;
cout<<setw(7)<<"^"<<setw(2)<<"^"<<setw(2)<<"^"<<setw(2)<<"^"<<endl;
system("pause");
return 0;
}
Output:
Hourglass:
/* Exercise 01: Hourglass using setw
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(10)<<"%%%%%"<<endl;
cout<<setw(9)<<"%%%"<<endl;
cout<<setw(8)<<"%"<<endl;
cout<<setw(9)<<"%%%"<<endl;
cout<<setw(10)<<"%%%%%"<<endl;
system("pause");
return 0;
}
Output:
Diamond:
/* Exercise 01: Diamond using setw
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(13)<<"*"<<endl;
cout<<setw(14)<<"***"<<endl;
cout<<setw(15)<<"*****"<<endl;
cout<<setw(16)<<"*******"<<endl;
cout<<setw(17)<<"*********"<<endl;
cout<<setw(18)<<"***********"<<endl;
cout<<setw(19)<<"*************"<<endl;
cout<<setw(20)<<"***************"<<endl;
cout<<setw(19)<<"*************"<<endl;
cout<<setw(18)<<"***********"<<endl;
cout<<setw(17)<<"*********"<<endl;
cout<<setw(16)<<"*******"<<endl;
cout<<setw(15)<<"*****"<<endl;
cout<<setw(14)<<"***"<<endl;
cout<<setw(13)<<"*"<<endl;
system("pause");
return 0;
}
Output:
/* Exercise 1: Triangle and rectangle using setw and endl
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<setw(12)<<"*"<<endl;
cout<<setw(11)<<"*"<<setw(2)<<"*"<<endl;
cout<<setw(10)<<"*"<<setw(4)<<"*"<<endl;
cout<<setw(9)<<"*"<<setw(6)<<"*"<<endl;
cout<<setw(8)<<"*"<<setw(8)<<"*"<<endl;
cout<<setw(7)<<"*"<<setw(10)<<"*"<<endl;
cout<<setw(6)<<"*"<<setw(12)<<"*"<<endl;
cout<<setw(19)<<"* * * * * * * *"<<endl<<endl;
cout<<setw(22)<<"* * * * * * * * * *"<<endl;
cout<<setw(4)<<"*"<<setw(18)<<"*"<<endl;
cout<<setw(4)<<"*"<<setw(18)<<"*"<<endl;
cout<<setw(4)<<"*"<<setw(18)<<"*"<<endl;
cout<<setw(4)<<"*"<<setw(18)<<"*"<<endl;
cout<<setw(4)<<"*"<<setw(18)<<"*"<<endl;
cout<<setw(22)<<"* * * * * * * * * *"<<endl;
system("pause");
return 0;
}
Output:
system("pause");
return 0;
}
Output:
system("pause");
return 0;
}
Output:
system("pause");
return 0;
}
Output:
/* Exercise 3b: Print a statement using setw and endl and backslash
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week 3
Date: 31st August, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Programming language makes use of different operators that
are:"<<endl;
cout<<setw(51)<<"Logical operator \\Relational Operator\\ "<<endl;
return 0;
}
Output:
cout<<setw(num1)<<num1<<endl;
cout<<setw(num2)<<num2<<endl;
return 0;
}
Output:
int main() {
// Marks Table
cout << setw(40) << "The Marks of Students" << endl;
cout << left << setw(20) << "Student" << right << setw(10) <<
"Marks" << endl;
cout << left << setw(20) << std1 << right << setw(10) << marks1 <<
endl;
cout << left << setw(20) << std2 << right << setw(10) << marks2 <<
endl;
cout << left << setw(20) << std3 << right << setw(10) << marks3 <<
endl;
cout << left << setw(20) << "Sum " << right << setw(10) << sum <<
endl;
cout << left << setw(20) <<"Average " << right << setw(13) << fixed
<< setprecision(2) << average << endl;
system("pause");
return 0;
}
Output:
/* Exercise 5: Price of Beverages.
Fundamentals of Programming
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week3
Date: 1st September, 2023 */
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// Define the prices of the beverages
double apple_juice_price = 199.99;
double orange_juice_price = 180.88;
double banana_shake_price = 170.77;
system("pause");
return 0;
}
Ouput:
string stdname;
int rollnumber;
double maths, physics, chemistry;
system("pause");
return 0;
Output:
/* Exercise 7 : Write a short program that declares and initializes
double variables one, two, three, four, and five to the
values 1.000, 1.414, 1.732, 2.000, and 2.236, respectively.
Fundamentals of Programming
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week3
Date: 1st September, 2023 */
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
cout<<fixed<<setprecision(3);
cout<<"N"<<setw(19)<<"Square Root\n\n";
cout<<"1"<<setw(9)<<(int)one<<endl;
cout<<"2"<<setw(13)<<two<<endl;
cout<<"3"<<setw(13)<<three<<endl;
cout<<"4"<<setw(9)<<(int)four<<endl;
cout<<"5"<<setw(13)<<five<<endl;
system("pause");
return 0;
}
Output:
/* Exercise 8 : Game of Mad Lib
Fundamentals of Programming
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week3
Date: 1st September, 2023 */
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
string name_of_instructor, name, food, adjective, color, animal;
int num;
cout << "\nDear Instructor " << name_of_instructor << "," << endl
<< endl;
cout << "I am sorry that I am unable to turn in my homework at this
time. First, I ate a rotten " << food << ", which made\nme turn " <<
color << " and extremely ill. I came down with a fever of " << num << ".
Next, my " << adjective << "\npet " << animal << " must have smelled
the remains of the " << food << " on my homework, because he ate it. I
am \ncurrently rewriting my homework and hope you will accept it late"
<< endl << endl;
cout << "Sincerely," << endl << endl;
cout << name << endl << endl;
system("pause");
return 0;
}
Output:
/* Exercise 9 : Score Board
Fundamentals of Programming
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week3
Date: 1st September, 2023 */
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
string player1, player2;
double score1, score2;
system("pause");
return 0;
}
Output:
/* Exercise 10 : Contact Information Formatter
Fundamentals of Programming
This code is written by Meer Muhammad Ansari
BS-1(AI)
Week3
Date: 1st September, 2023 */
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main(){
system("pause");
return 0;
}
Output:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
string name, color;
int age;
cout << "Enter Your Name: ";
getline(cin, name);
cin.ignore();
system("pause");
return 0;
}
Output: