0% found this document useful (0 votes)
17 views3 pages

CP Practicemids

The document contains multiple C++ code snippets that perform various calculations and operations. These include calculating the area of a triangle, properties of a circle, digit extraction from a five-digit number, number classification, vowel/consonant identification, zakat calculation, and electricity bill computation. Each code segment demonstrates basic programming concepts such as input/output, conditional statements, and arithmetic operations.

Uploaded by

erajkhan2005
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)
17 views3 pages

CP Practicemids

The document contains multiple C++ code snippets that perform various calculations and operations. These include calculating the area of a triangle, properties of a circle, digit extraction from a five-digit number, number classification, vowel/consonant identification, zakat calculation, and electricity bill computation. Each code segment demonstrates basic programming concepts such as input/output, conditional statements, and arithmetic operations.

Uploaded by

erajkhan2005
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/ 3

1 //code1

2 #include<iostream>
3 using namespace std;
4 int main()
5 {
6 float base,altitude,area,v_var;
7 cout<<"enter the base of triangle\n";
8 cin>>base;
9 cout<<"enter the altitude of triangle\n";
10 cin>> altitude;
11 v_var = (base * altitude);
12 area = (0.5 * v_var);
13 cout<<"The area of the triangle is "<< area <<" square units";
14 return 0;
15 }
16
17 //code2
18 #include<iostream>
19 #include <cmath>
20 using namespace std;
21 int main()
22 {
23 float radius,pi=3.1419,diameter, circumference,area;
24 cout<<"enter radius of the circle";
25 cin>>radius;
26 diameter=2*radius;
27 circumference=2*pi*radius;
28 area=pi*radius*radius;
29 cout<<"diameter of given circle is "<<diameter<<"units\n";
30 cout<<"circumference of given circle is "<<circumference<<"units\n";
31 cout<<"Area of given circle is "<<area<<"units\n";
32 return 0;
33 }
34 //code3
35 #include<iostream>
36 using namespace std;
37 int main()
38 {
39 int num_1;
40 int digit_1,digit_2,digit_3,digit_4,digit_5;
41 cout<<"Enter your five digit positive integer: ";
42 cin>>num_1;
43 digit_1 =num_1/10000;
44 digit_2 =num_1/1000 %10;
45 digit_3 =num_1/100%10;
46 digit_4 =num_1/10%10;
47 digit_5 =num_1/1%10;
48 if(num_1>=0&&num_1>=10000&&num_1<=99999){
49 cout<<"First digit is: "<<digit_1<<"\n";
50 cout<<"Second digit is: "<<digit_2<<"\n";
51 cout<<"Third digit is: "<<digit_3<<"\n";
52 cout<<"Fourth digit is: "<<digit_4<<"\n";
53 cout<<"Fifth digit is: "<<digit_5<<"\n";
54 }
55 else{
56 cout<<"incorrect input";
57 }
58 return 0;
59 }
60
61 //code4
62 #include<iostream>
63 using namespace std;
64 int main() {
65 int num;
66 cout << "Enter a number: ";
67 cin >> num;
68
69 if (num <= 0) {
70 cout << "Condition 1: num is less than or equal to 0" << endl;
71 } else if (num % 2 == 0) {
72 cout << "Condition 2: num is even and greater than 0" << endl;
73 } else {
74 cout << "Condition 3: num is odd and greater than 0" << endl;
75 }
76
77 return 0;
78 }
79
80 //code5
81 #include <iostream>
82 using namespace std;
83
84 int main() {
85 char letter;
86 cout << "Enter a character: ";
87 cin >> letter;
88 if (letter == 'A' || letter == 'a' ||
89 letter == 'E' || letter == 'e' ||
90 letter == 'I' || letter == 'i' ||
91 letter == 'O' || letter == 'o' ||
92 letter == 'U' || letter == 'u') {
93 cout << "You have entered a vowel." << endl;
94 } else if ((letter >= 'A' && letter <= 'Z') || (letter >= 'a' && letter <= 'z')) {
95 cout << "You have entered a consonant." << endl;
96 } else {
97 cout << "You have entered an invalid character." << endl;
98 }
99
100 return 0;
101 }
102
103 //code6
104 #include<iostream>
105 using namespace std;
106 int main(){
107 int net_wealth;
108 cout<<"Enter your net wealth in pkr: ";
109 cin>>net_wealth;
110 cout<<"Your zakat is: "<<net_wealth*0.025<<"pkr";
111
112 }
113
114 //code7
115 #include <iostream>
116 using namespace std;
117 int main() {
118 const int FIXED_COST = 3000;
119 const double TAX_RATE = 0.13;
120 int units_consumed;
121 double cost_of_electricity = 0.0, taxes = 0.0, total_bill = 0.0;
122 cout << "Enter the electricity units consumed: ";
123 cin >> units_consumed;
124 if (units_consumed <= 200) {
125 cost_of_electricity = units_consumed * 35; // 35 PKR per unit
126 } else if (units_consumed > 200 && units_consumed <= 350) {
127 cost_of_electricity = (200 * 35) + ((units_consumed - 200) * 45); // 35 PKR for first 200, 45 PKR
for rest
128 } else if (units_consumed > 350) {
129 cost_of_electricity = (200 * 35) + (150 * 45) + ((units_consumed - 350) * 60); // 35 PKR for first
200, 45 PKR for next 150, 60 PKR for rest
130 }
131 taxes = cost_of_electricity * TAX_RATE;
132 total_bill = FIXED_COST + cost_of_electricity + taxes;
133 cout << "\nElectricity Bill Details:\n";
134 cout << "Fixed Cost: " << FIXED_COST << " PKR\n";
135 cout << "Cost of Electricity: " << cost_of_electricity << " PKR\n";
136 cout << "Taxes (13%): " << taxes << " PKR\n";
137 cout << "Total Bill: " << total_bill << " PKR\n";
138
139 return 0;
140 }

You might also like