0% found this document useful (0 votes)
7 views13 pages

c008 Bds

The document contains multiple C++ programming tasks that involve inputting and processing data for various scenarios. Tasks include calculating total and average grades for students, sales for salesmen, energy consumption for machines, managing bank account information, searching for account details, calculating factorials, and swapping two numbers. Each task is presented with its respective code and expected output.

Uploaded by

Nishit Chheda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

c008 Bds

The document contains multiple C++ programming tasks that involve inputting and processing data for various scenarios. Tasks include calculating total and average grades for students, sales for salesmen, energy consumption for machines, managing bank account information, searching for account details, calculating factorials, and swapping two numbers. Each task is presented with its respective code and expected output.

Uploaded by

Nishit Chheda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

task 1:

#include <iostream>

using namespace std;

int main() {

int grades[6][4];

int total, average,i,j;

cout << "Enter grades for 6 students and 4 subjects:\n";

for ( i = 0; i < 6; ++i) {

for ( j = 0; j < 4; ++j) {

cin >> grades[i][j];

cout << "\nTotal grades for each student:\n";

for ( i = 0; i < 6; ++i) {

total = 0;

for ( j = 0; j < 4; ++j) {

total += grades[i][j];

cout << "Student " << i + 1 << ": " << total << endl;

cout << "\nAverage grade for each subject:\n";

for ( j = 0; j < 4; ++j) {

total = 0;
for ( i = 0; i < 6; ++i) {

total += grades[i][j];

average = total / 6.0;

cout << "Subject " << j + 1 << ": " << average << endl;

return 0;

Output 1:
Task 2:
#include <iostream>

using namespace std;


int main() {

int sales[5][3];

int i, j, total;

cout << "Enter sales for 5 salesmen and 3 products:\n";

for (i = 0; i < 5; i++) {

for (j = 0; j < 3; j++) {

cout << "Salesman " << i + 1 << ", Product " << j + 1 << ": ";

cin >> sales[i][j];

cout << "\nTotal sales by each salesman:\n";

for (i = 0; i < 5; i++) {

total = 0;

for (j = 0; j < 3; j++) {

total += sales[i][j];

cout << "Salesman " << i + 1 << ": " << total << endl;

cout << "\nTotal sales of each product:\n";

for (j = 0; j < 3; j++) {

total = 0;

for (i = 0; i < 5; i++) {

total += sales[i][j];

cout << "Product " << j + 1 << ": " << total << endl;

return 0;
}

Output 2:

Task 3:
#include<iostream>

using namespace std;

int main(){

int sum=0,sum2=0;

int a[5][4];

for(int i=0;i<5;i++){

cout<<"energy consumption of machine "<<i+1<<" in 4 shifts: "<<endl;

for(int j=0;j<4;j++){
cin>>a[i][j];

for(int i=0;i<5;i++){

for(int j=0;j<3;j++){

sum+=a[i][j];

cout<<"machine "<<i+1<<" total energy consumption: "<<sum<<endl;

sum=0;

for(int i=0;i<4;i++){

for(int j=0;j<5;j++){

sum2+=a[j][i];

cout<<"shift "<<i+1<<" total energy consumption: "<<sum2<<endl;

sum2=0;

OUTPUT 3:
Task 5:
#include<iostream>

using namespace std;

struct BankAccount{

int AccNo;

double Balance;

char name[40];

};

int main(){
struct BankAccount b;

cout<<"account number= "<<endl;

cin>>b.AccNo;

cout<<"account balance= "<<endl;

cin>>b.Balance;

cout<<"name= "<<endl;

cin.getline(b.name,40);

cin.getline(b.name,40);

cout<<"Account Number= "<<b.AccNo<<endl<<"Balance= "<<b.Balance<<endl<<"Name=


"<<b.name<<endl;

OUTPUT 5:

Task 6:
#include<iostream>

using namespace std;

struct BankAccount{

int AccNo[50];

double Balance[50];

char name[50][50];

};

int main(){

struct BankAccount b;

int n,s,f=0;
cout<<"enter number of people= "<<endl;

cin>>n;

for(int i=0;i<n;i++){

cout<<"account number "<<i+1<<"= "<<endl;

cin>>b.AccNo[i];

cout<<"account balance "<<i+1<<"= "<<endl;

cin>>b.Balance[i];

cout<<"name "<<i+1<<"= "<<endl;

cin.getline(b.name[i],40);

cin.getline(b.name[i],40);

start:

cout<<"Search: "<<endl;

cout<<"enter 1 to search Account number \n 2 to search Balance \n 3 to search name\n 4 to stop:


"<<endl;

cin>>s;

if(s==1){

cout<<"enter the number of person to search= "<<endl;

cin>>f;

if(b.AccNo[f-1]){

cout<<b.AccNo[f-1]<<endl;

else{

cout<<"invalid input"<<endl;

goto start;

else if(s==2){

cout<<"enter the number of person to search= "<<endl;

cin>>f;

if(b.Balance[f-1]){
cout<<b.Balance[f-1]<<endl;

else{

cout<<"invalid input"<<endl;

goto start;

else if(s==3){

cout<<"enter the number of person to search= "<<endl;

cin>>f;

if(b.name[f-1]){

cout<<b.name[f-1]<<endl;

else{

cout<<"invalid input"<<endl;

goto start;

else{

terminate();

OUTPUT 6:
Task 7:
#include <iostream>

using namespace std;

int main() {

int num, factorial = 1;

cout << "Enter a positive integer: ";

cin >> num;


if (num < 0) {

cout << "Error: Factorial is not defined for negative numbers." << endl;

} else {

for (int i = 1; i <= num; ++i) {

factorial *= i;

cout << "Factorial of " << num << " = " << factorial << endl;

return 0;

OUTPUT 7:

Task 8:
#include <iostream>

using namespace std;

int main() {

int a, b;

int temp;

cout << "Enter 1st number: ";

cin >> a;

cout << "Enter 2nd number: ";

cin >> b;
cout << "Before swapping: a = " << a << ", b = " << b << endl;

temp = a;

a = b;

b = temp;

cout << "After swapping: a = " << a << ", b = " << b << endl;

return 0;

OUTPUT 8:

You might also like