In C++ you can use the standard library sort algorithm to sort any data sequence provided the elements support the appropriate comparison operator (std::less<T> for any given type T is used by default). For example: std::vector<int> v {5, 9, 7, 1, 3}; std::sort (v.begin(), v.end()); // v = {1, 3, 5, 7, 9} std::sort (v.begin(), v.end(), std::greater<int>); // v = {9, 7, 5, 3, 1}
#include<iostream> #include<vector> #include<string> #include<algorithm> // forward declarations void sort(std::vector<int>&); void sort(std::vector<std::string>&); int main() { std::vector<int> int_array = { 7, 3, 8, 6, 2, 9, 1, 4, 0, 5}; std::vector<std::string> str_array = { "John", "Bill", "Alan", "Craig"}; sort (int_array); sort (str_array); } void sort(std::vector<int>& arr) { std::sort (arr.begin(), arr.end()); } void sort(std::vector<std::string>& arr) { std::sort (arr.begin(), arr.end()); }
#include<iostream> #include<iomanip> #include<vector> #include<string> #include<random> #include<time.h> struct student_t { unsigned m_student_id; std::string m_student_name; student_t(const unsigned student_id, const std::string& student_name): m_student_id(student_id), m_student_name(student_name) {} }; struct students_t : std::vector<student_t> { students_t() : std::vector<student_t> () { push_back( student_t( 1, "Albert Black")); push_back( student_t( 2, "Charlie Dawson")); push_back( student_t( 3, "Eric Farrel")); push_back( student_t( 4, "Gary Houston")); push_back( student_t( 5, "Iain Jackson")); push_back( student_t( 6, "Kevin Lawson")); push_back( student_t( 7, "Michael Nicholson")); push_back( student_t( 8, "Oscar Peterson")); push_back( student_t( 9, "Robert Stevenson")); push_back( student_t( 10, "Tony Urquart")); } }; struct subject_t { unsigned m_subject_id; std::string m_subject_name; subject_t(const unsigned subject_id, const std::string& subject_name): m_subject_id(subject_id), m_subject_name(subject_name) {} }; struct subjects_t : std::vector<subject_t> { subjects_t() : std::vector<subject_t> () { push_back( subject_t( 1, "English")); push_back( subject_t( 2, "Mathematics")); push_back( subject_t( 3, "Physics")); push_back( subject_t( 4, "Biology")); push_back( subject_t( 5, "Chemistry")); push_back( subject_t( 6, "History")); push_back( subject_t( 7, "Geography")); } unsigned max_length() { // Returns length of longest name. unsigned max=0; for (std::vector<subject_t>::const_iterator isubject=begin(); isubject!=end(); ++isubject) { const subject_t& subject = *isubject; if (max < subject.m_subject_name.size()) max = subject.m_subject_name.size(); } return max; } }; struct mark_t { student_t& m_student; subject_t& m_subject; unsigned m_mark; mark_t(student_t& student, subject_t& subject, const unsigned mark): m_student(student), m_subject(subject), m_mark(mark) {} mark_t& operator= (const mark_t& rvalue) { this->m_student = rvalue.m_student; this->m_subject = rvalue.m_subject; this->m_mark = rvalue.m_mark; return *this; } }; struct marks_t : std::vector<mark_t> { students_t& m_students; subjects_t& m_subjects; marks_t (students_t& students, subjects_t& subjects) : std::vector<mark_t>(), m_students(students), m_subjects(subjects) { // pseudo-random number generator std::default_random_engine generator; generator.seed ((unsigned) time (NULL)); std::uniform_int_distribution<unsigned> distribution (0, 100); for (std::vector<student_t>::const_iterator istudent=students.begin(); istudent!=students.end(); ++istudent) { student_t& student = const_cast<student_t&> (*istudent); for (std::vector<subject_t>::const_iterator isubject=subjects.begin(); isubject!=subjects.end(); ++isubject) { subject_t& subject = const_cast<subject_t&> (*isubject); push_back( mark_t(student, subject, distribution(generator))); } } } std::ostream& print (std::ostream& os) { unsigned last_student_id = 0; for (std::vector<mark_t>::const_iterator imark=begin(); imark!=end(); ++imark) { const student_t& student = imark->m_student; if (last_student_id != student.m_student_id) { if (last_student_id) os << '\n'; last_student_id = student.m_student_id; os << '#' << student.m_student_id << '\t' << student.m_student_name << ":\n" << std::endl; } const subject_t& subject = imark->m_subject; os << '\t' << std::setw (m_subjects.max_length()) << subject.m_subject_name << '\t' << std::setw(3) << imark->m_mark << std::endl; } os << std::endl; return os; } }; int main() { students_t students; subjects_t subjects; marks_t marks (students, subjects); marks.print (std::cout); }
7^3 = 7 x 7 x 7
#include<iostream> void num_to_years_weeks_days( unsigned num, unsigned& years, unsigned& weeks, unsigned& days) { years = num / 365; num -= years * 365; weeks = num / 7; num -= weeks * 7; days = num; } int main() { unsigned years, weeks, days; unsigned num = 1000; num_to_years_weeks_days(num, years, weeks, days); std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl; num = 12345; std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl; }
The cost of installing a home wind power generator depends on the kilowatt it produces. A 1 kilowatt wind power generator usually costs $3000-$7000. A 7 kilowatt wind power generator costs $20,000-$40,000. The more kilowatt it produces, the more costly it is.
Yes, a 5500 watt generator should be able to run a 1 horsepower motor. A typical 1 horsepower motor requires around 750-1000 watts to operate, so the generator's output should be sufficient. Just make sure to check the starting wattage of the motor to ensure the generator can handle any initial surge in power.
maharashtra scholarship result of 7 std 2012_2013
#include<iostream> #include<iomanip> #include<map> #include<random> #include<time.h> std::default_random_engine generator; std::uniform_int_distribution<unsigned> distribution (1, 10); typedef std::map<unsigned, unsigned> freq_map; int main() { std::cout << "Program to generate 1,000,000 random numbers in the range 1 to 10\n"; std::cout << "and to print the frequency table for all numbers generated.\n\n"; generator.seed ((unsigned) time (NULL)); freq_map fmap; freq_map::iterator iter; for (unsigned count=0; count<1000000; ++count) { unsigned number = distribution (generator); iter = fmap.find (number); if (iter == fmap.end()) { fmap.insert (freq_map::value_type (number, 1)); } else { ++(iter->second); } } for (iter = fmap.begin(); iter != fmap.end(); ++iter) { std::cout << "The number" << std::setw(3) << iter->first; std::cout << " occurred" << std::setw(7) << iter->second << " times\n"; } std::cout << std::endl; }
At 240 volts, and 7 amp current, you will have a load of 1680 watts (volts x amps = watts). A 2000 watt generator will sufice, however a 3500 watt generator, if within your budget, will power a few other necessities if required.
#include<iostream> #include<sstream> int input_num (std::string prompt) { int num = 0; while (1) { std::cout<<prompt<<": "; std::string input=""; getline (std::cin, input); std::stringstream ss (input); if (ss>>num) break; std::cout<<"Invalid input.\n"; } return (num); } int main() { while (1) { int num = input_num ("Enter a number (0 to exit)"); if (!num) break; if (num%7) std::cout << "The number is not divisible by 7.\n" << std::endl; else std::cout << "The number is divisible by 7.\n" << std::endl; } }
#include<iostream> int main() { for(int i=0; i<=12; ++i ) std::cout<<"7 x "<<i<<" = "<<7*i<<std::endl; return(0); }
A 1-ton AC can melt a ton of ice in 24 hours. The power needed is theoretically 3517 Watts so allowing for power factor and efficiency you would need a 7 kVA generator.
Explore the Generac 25kW Generator—a reliable backup power solution for homes & businesses. With automatic operation, robust performance, and 24/7 power security, it’s ideal for outages. Learn specs, pricing, and benefits. Get yours today!
NOTICE
#include<iostream> #include<sstream> #include<vector> #include<algorithm> std::ostream& operator<< (std::ostream& os, std::vector<double> v) { os << "{"; for (auto num : v) os << num << ", "; return os << "\b\b} "; } int main () { std::vector<double> v {}; for (size_t in=0; in<7; ++in) { while (true) { std::cout << "Enter a number: "; std::stringstream ss; std::cin >> ss; double d; if (ss >> d) { v.push_back (v); break; } std::cout << "Try again...\n"; } std::cout << "Before sorting: " << v << std::endl; std::sort (v.begin(), v.end()); std::cout << "After sorting: " << v << std::endl; }
Generator Gawl - 1998 is rated/received certificates of: Spain:7