CP Assignment 4: Answer No.1: Code
CP Assignment 4: Answer No.1: Code
Answer No.1:
Code:
#include <iostream>
#include <string>
using namespace std;
struct profile
{
int roll;
string name;
int age;
string address;
int marks;
};
profile arr[15];
int main()
{
system("color A");
int i;
int j;
cout << "Enter student " << i + 1 << "'s name: ";
cin >> arr[i].name;
cout << "Enter student " << i + 1 << "'s age: ";
cin >> arr[i].age;
cout << "Enter student " << i + 1 << "'s address: ";
cin >> arr[i].address;
cout << "Enter student " << i + 1 << "'s marks: ";
cin >> arr[i].marks;
cout << endl;
}
cout << "Student " << j << "'s roll number: " << arr[j].age;
cout << "Student " << j << "'s roll number: " << arr[j].address;
cout << "Student " << j << "'s roll number: " << arr[j].marks;
cout << endl;
}
system("pause");
return 0;
}
Output:
Answer No.2:
Code:
#include <iostream>
#include <string>
using namespace std;
struct date
{
int day;
int month;
int year;
};
int main()
{
system("color A");
date a;
date b;
else
{
cout << "Both dates are different.";
}
system("pause");
return 0;
}
Output:
Answer No.3
Code:
Consider the following C++ code. What is preventing it from compiling?
struct Employee {
int id;
float wage;
}
Output:
ERROR!!!
Solution:
A terminator ( ; ) should be put after the closing bracket
( ; ) because of the rules of the C++ code.
Correction:
Consider the following C++ code. What is preventing it from compiling?
struct Employee {
int id;
float wage;
};