WACHEMO UNIVERSITY
DURAME CAMPUS
Department of computer science
project assignment of C++
program
NAME ID
NAOL DUGO 4822
Muluken fenta 4772
Tagese Girma 4915
Zubayda tadese 5107
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Define a structure for Marks of all subjects
struct Marks {
float cpp;
float introToComputer;
float emergingTech;
float physics;
float english;
float fundamentalsOfDatabase;
};
// Define a structure for Student data
struct Student {
string name;
string regNo;
char section; // A or B
Marks marks; // Nested structure for marks
};
void getSection(char& section) {
// Function to ensure only valid sections (A or B) are entered
while (true) {
cout << "Enter section (A or B): ";
cin >> section;
if (section == 'A' || section == 'B') {
break;
} else {
cout << "Error: Invalid section. Please enter A or B." << endl;
void inputStudentData(Student &s) {
// Function to input data for a student
cout << "Enter student name: ";
cin.ignore();
getline(cin, s.name);
cout << "Enter registration number: ";
cin >> s.regNo;
getSection(s.section); // Get section with validation
cout << "Enter marks in C++: ";
cin >> s.marks.cpp;
cout << "Enter marks in Intro to Computer: ";
cin >> s.marks.introToComputer;
cout << "Enter marks in Emerging Technology: ";
cin >> s.marks.emergingTech;
cout << "Enter marks in Physics: ";
cin >> s.marks.physics;
cout << "Enter marks in English: ";
cin >> s.marks.english;
cout << "Enter marks in Fundamentals of Database: ";
cin >> s.marks.fundamentalsOfDatabase;
}
float calculateAverage(Marks m) {
// Function to calculate the average marks
return (m.cpp + m.introToComputer + m.emergingTech + m.physics + m.english +
m.fundamentalsOfDatabase) / 6.0;
void displayStudentData(Student s) {
// Function to display student data in tabular format
cout << fixed << setprecision(2); // Set output precision for marks
cout << "| " << left << setw(20) << s.name
<< "| " << left << setw(15) << s.regNo
<< "| " << left << setw(8) << s.section
<< "| " << setw(5) << s.marks.cpp
<< "| " << setw(5) << s.marks.introToComputer
<< "| " << setw(5) << s.marks.emergingTech
<< "| " << setw(5) << s.marks.physics
<< "| " << setw(5) << s.marks.english
<< "| " << setw(5) << s.marks.fundamentalsOfDatabase
<< "| " << setw(5) << calculateAverage(s.marks) << " |" << endl;
void displaySectionAverage(float totalMarks, int count) {
if (count > 0) {
cout << "Section average: " << totalMarks / count << endl;
} else {
cout << "No students in this section." << endl;
}
int main() {
int n;
cout << "Enter total number of students: ";
cin >> n;
Student students[n]; // Array of student out structures
int sectionACount = 0, sectionBCount = 0;
float sectionATotalMarks = 0, sectionBTotalMarks = 0;
// Input student data
for (int i = 0; i < n; i++) {
cout << "\nEnter data for student " << i + 1 << ":\n";
inputStudentData(students[i]);
if (students[i].section == 'A') {
sectionACount++;
sectionATotalMarks += calculateAverage(students[i].marks);
} else if (students[i].section == 'B') {
sectionBCount++;
sectionBTotalMarks += calculateAverage(students[i].marks);
// Display header for tabular data
cout << "\nDisplaying student data:\n";
cout << "| " << left << setw(20) << "Name"
<< "| " << left << setw(15) << "Registration No"
<< "| " << left << setw(8) << "Section"
<< "| C++ | Intro to Comp | Emerging Tech | Physics | English | Database | Avg |" << endl;
cout << "-------------------------------------------------------------------------------------------" << endl;
// Display data for each student
for (int i = 0; i < n; i++) {
displayStudentData(students[i]);
// Display section-wise average
cout << "\nSection A students average marks:\n";
displaySectionAverage(sectionATotalMarks, sectionACount);
cout << "\nSection B students average marks:\n";
displaySectionAverage(sectionBTotalMarks, sectionBCount);
return 0;