C Classroom File
C Classroom File
Solution:
Code:
#include <iostream>
using namespace std;
int main() {
return 0;
}
Practical 4] Write a program that determines a student’s grade. And determine the grade
based on the following rules:
- If the average score >= 90 → grade A+
- If the average score >= 80 → grade A
- If the average score >= 70 → grade B+
- If the average score >= 60 → grade B
- If the average score >= 50 → grade C
- If the average score >= 40 → grade D
MARKS GRADES
100 - 90 A+
90 – 80 A
80 – 70 B+
70 – 60 B
60 – 50 C
50 – 40 D
Solution:
#include <iostream>
Using namespace std;
int main(){
int marks;
cout<<”Enter your Marks: ”;
cin>>marks;
if (marks >= 90){
cout<<”Your grade is A+”;
}
else if (marks >= 80){
cout<<”Your grade is A”;
}
else if (marks >= 70){
cout<<”Your grade is B+”;
}
else if (marks >= 60){
cout<<”Your grade is B”;
}
else if (marks >= 50){
cout<<”Your grade is C”;
}
else if (marks >= 40){
cout<<”Your grade is B”;
}
else{
cout<<”Enter valid marks”;
}
Return 0;
}
Practical 5] Define a class called as circle which has radius as its data member. The class
should have following member functions
a. Function to set the value of radius.
b. Function to get the value of radius.
c. Function to calculate and return the area of circle.
d. Function to calculate and return circumference.
Solution:
#include <iostream>
#include <cmath>
class Circle {
private:
double radius;
public:
Circle(double rad): radius(rad) {}
double calculateArea() {
return PI * pow(radius, 2);
}
double calculateCircumference() {
return 2 * PI * radius;
}
};
int main() {
double radius;
std::cout << "Input the radius of the circle: ";
std::cin >> radius;
Circle circle(radius);
return 0;
}
Practical 6] Develop a one-digit counter to determine the following function. The class
should have a following function
a. Function to set the value of the counter.
b. Function to display value of the counter.
c. Function to increment the counter.
d. Function to decrement the counter.
Solution:
#include <iostream>
using namespace std;
main(){
int number = 21;
int counter ;
counter = number++;
cout <<”1. Value of Counter is : “ <<counter << endl;
cout <<”2. Value of Counter in Increment Form: ” << number << endl;
number = ++number;
cout <<”3. Value of Counter in Decrement Form: ” << counter << endl;
return 0;
}